13namespace tracktion {
inline namespace graph
36template<
typename ObjectType>
56 pendingObjectStorage = {};
59 pendingObject =
nullptr;
68 pendingObjectStorage = std::move (newObj);
69 pendingObject = &pendingObjectStorage;
83 needToUnlockClearObjectsMutex =
true;
87 needToUnlockClearObjectsMutex =
false;
94 needToUnlockPushingObjectMutex =
true;
97 if (
auto newObject = pendingObject.
exchange (
nullptr))
102 needToUnlockPushingObjectMutex =
false;
106 return &objectStorage;
112 if (needToUnlockClearObjectsMutex)
113 clearObjectsMutex.
unlock();
115 if (needToUnlockPushingObjectMutex)
116 pushingObjectMutex.
unlock();
128 : lockFreeObject (lfo)
155 ObjectType objectStorage, pendingObjectStorage;
158 bool needToUnlockPushingObjectMutex =
false, needToUnlockClearObjectsMutex =
true;
Helper class to automatically retain/release real time access to an object.
~ScopedRealTimeAccess()
Releases real time access to the object.
ScopedRealTimeAccess(LockFreeObject &lfo)
Retains real time access to an object.
ObjectType * get() const
Returns a pointer to the object if access was obtained.
Manages access to an object in a way that means it is lock-free to access from a real-time thread.
void clear()
Clears the object and any pending object by assigining them defaultly constructed objects.
LockFreeObject()
Constructs an initially empty object.
ScopedRealTimeAccess getScopedAccess()
Creates a ScopedRealTimeAccess for this LockFreeObject.
void pushNonRealTime(ObjectType &&newObj)
Pushes a new object to be picked up on the real time thread.
ObjectType * retainRealTime()
Retains the object for use in a real time thread.
void releaseRealTime()
Releases the use of the object from a previous call to retainRealTime.
A basic spin lock that uses an atomic_flag to store the locked state so should never result in a syst...
void unlock() noexcept
Releases the lock, this should only be called after a successful call to try_lock or lock.
bool try_lock() noexcept
Attempts to take the lock once, returning true if successful.