MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ update()

template<typename T>
template<typename Edit>
requires std::invocable<Edit&, T&> && std::default_initializable<T> && std::copy_constructible<T>
bool MayaFlux::Memory::SnapshotCell< T >::update ( Edit edit)
inline

Edits a copy of the current snapshot and publishes it.

Starts from a default constructed T when the cell is empty. If another writer publishes first, the copy is discarded and edit runs again on the newer snapshot, so it may run more than once and must depend only on the value it is given.

Template Parameters
EditCallable (T&) returning void, or bool.
Parameters
editMutates the copy. A bool return of false abandons the edit and publishes nothing.
Returns
true if a new snapshot was published, false if edit declined.

Definition at line 173 of file SnapshotCell.hpp.

174 {
177 "SnapshotCell::update edit must return void or bool");
178
179 for (;;) {
180 Guard pin = read();
181 const T* current = pin.get();
182
184
185 if constexpr (std::is_void_v<Result>) {
187 } else if (!std::invoke(edit, *draft)) {
188 return false;
189 }
190
191 const T* expected = current;
192 if (m_head.compare_exchange_strong(expected, draft.get())) {
193 draft.release();
194 pin = Guard {};
196 return true;
197 }
198 }
199 }
Keeps one snapshot alive and unchanged while it exists.
Guard read() const noexcept
Pins the current snapshot.
std::atomic< const T * > m_head
Lock-free cell holding one immutable snapshot of a value, read without blocking.

References MayaFlux::Memory::SnapshotCell< T >::Guard::get(), m_head, read(), and retire().

Referenced by MayaFlux::Platform::SystemConfig::get_dep_includes().

Here is the call graph for this function:
Here is the caller graph for this function: