libpromeki 1.0.0-alpha
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
memfdbufferimpl.h
Go to the documentation of this file.
1
8#pragma once
9
10#include <promeki/namespace.h>
11#include <promeki/config.h>
13#include <promeki/memfdregion.h>
14#include <promeki/mutex.h>
15#include <promeki/sharedptr.h>
16
17PROMEKI_NAMESPACE_BEGIN
18
19#if PROMEKI_ENABLE_MEMFD
74class MemfdBufferImpl : public HostMappedBufferImpl {
75 public:
88 MemfdBufferImpl(const MemSpace &ms, size_t bytes, size_t align);
89
91 ~MemfdBufferImpl() override;
92
93 bool canClone() const override;
94 bool isCowBacked() const override { return true; }
95 Error seal() const override;
96 size_t residentBytes() const override;
97
108 MemfdBufferImpl *_promeki_clone() const override;
109
110 private:
118 MemfdBufferImpl(const MemfdBufferImpl &source, void *cloneView);
119
120 using RegionPtr = SharedPtr<MemfdRegion, false>;
121
122 RegionPtr _region;
123 mutable Mutex _sealMutex;
124 mutable bool _sealed = false;
125 mutable bool _dead = false;
126 // Set to true at sibling-clone construction time.
127 // ensureExclusive() implies the caller intends to
128 // write through the new clone; subsequent detaches
129 // from this clone must therefore preserve any
130 // such writes (the kernel's MAP_PRIVATE-from-file
131 // semantics would silently drop them). The post-
132 // seal source (and the producer-phase impl) stay
133 // _dirty=false so the first detach from a clean
134 // cached payload still uses the cheap kernel-CoW
135 // path — the SystemCow optimisation hinges on
136 // exactly that case.
137 bool _dirty = false;
138};
139
140#endif // PROMEKI_ENABLE_MEMFD
141PROMEKI_NAMESPACE_END