libpromeki 1.0.0-alpha
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
memfdregion.h
Go to the documentation of this file.
1
8#pragma once
9
10
11#include <promeki/config.h>
12#if PROMEKI_ENABLE_CORE
13#include <cstddef>
14#include <cstdint>
15#include <promeki/namespace.h>
16#include <promeki/string.h>
17#include <promeki/error.h>
18
19PROMEKI_NAMESPACE_BEGIN
20
90class MemfdRegion {
91 public:
98 static bool isSupported();
99
101 MemfdRegion();
102
120 explicit MemfdRegion(size_t bytes, const String &debugName = String("anonymous"));
121
123 ~MemfdRegion();
124
125 MemfdRegion(const MemfdRegion &) = delete;
126 MemfdRegion &operator=(const MemfdRegion &) = delete;
127
129 MemfdRegion(MemfdRegion &&other) noexcept;
130
132 MemfdRegion &operator=(MemfdRegion &&other) noexcept;
133
141 bool isValid() const;
142
144 bool isSealed() const;
145
147 size_t size() const { return _size; }
148
156 int fd() const { return _fd; }
157
167 void *producerView();
168
196 Error seal(void **outFirstClone = nullptr);
197
214 void *cloneView(Error *err = nullptr);
215
230 void *readOnlyView(Error *err = nullptr);
231
245 Error releaseView(void *p);
246
256 Error adviseProducer(int madviseFlag);
257
265 Error adviseView(void *p, int madviseFlag);
266
267 private:
268 int _fd; // -1 when not held
269 size_t _size; // rounded-up
270 void *_producer; // cached MAP_SHARED|PROT_WRITE; null pre-mmap or post-seal
271 bool _sealed;
272 bool _dead; // permanent failure latched after a failed seal()
273
274 void closeAndReset() noexcept;
275};
276
277PROMEKI_NAMESPACE_END
278
279#endif // PROMEKI_ENABLE_CORE