TracktionEngine
Classes | Public Member Functions | List of all members
tracktion::graph::LockFreeObject< ObjectType > Class Template Reference

Manages access to an object in a way that means it is lock-free to access from a real-time thread. More...

Classes

class  ScopedRealTimeAccess
 Helper class to automatically retain/release real time access to an object. More...
 

Public Member Functions

 LockFreeObject ()
 Constructs an initially empty object. More...
 
void clear ()
 Clears the object and any pending object by assigining them defaultly constructed objects. More...
 
void pushNonRealTime (ObjectType &&newObj)
 Pushes a new object to be picked up on the real time thread. More...
 
ObjectType * retainRealTime ()
 Retains the object for use in a real time thread. More...
 
void releaseRealTime ()
 Releases the use of the object from a previous call to retainRealTime. More...
 
ScopedRealTimeAccess getScopedAccess ()
 Creates a ScopedRealTimeAccess for this LockFreeObject. More...
 

Detailed Description

template<typename ObjectType>
class tracktion::graph::LockFreeObject< ObjectType >

Manages access to an object in a way that means it is lock-free to access from a real-time thread.

This initially starts empty so call pushNonRealTime to queue an object. You can then get at this object using retainRealTime. It's thread safe to call pushNonRealTime as many times as you like, retainRealTime will just return the old object whilst those calls are in progress. Calls to pushNonRealTime may have to wait for the real time access to complete, signified by a call to releaseRealTime.

Additionally, you may want to clear the objects e.g. releasing some resource they have stored. This can be done with the clear call. Whilst this is happening, retainRealTime will still be lock-free but will return nullptr signifying no object can be used.

See also
ScopedRealTimeAccess

Constructor & Destructor Documentation

◆ LockFreeObject()

template<typename ObjectType >
tracktion::graph::LockFreeObject< ObjectType >::LockFreeObject ( )

Constructs an initially empty object.

Use the pushNonRealTime function to queue one for real-time access.

Member Function Documentation

◆ clear()

template<typename ObjectType >
void tracktion::graph::LockFreeObject< ObjectType >::clear ( )

Clears the object and any pending object by assigining them defaultly constructed objects.

◆ pushNonRealTime()

template<typename ObjectType >
void tracktion::graph::LockFreeObject< ObjectType >::pushNonRealTime ( ObjectType &&  newObj)

Pushes a new object to be picked up on the real time thread.

◆ retainRealTime()

template<typename ObjectType >
ObjectType* tracktion::graph::LockFreeObject< ObjectType >::retainRealTime ( )

Retains the object for use in a real time thread.

If a previous push call has finished, this will update and use the newly pushed object. If a clear call is in progress this will return nullptr.

This must be matched with a corresponding call to releaseRealTime(). To Ensure this, use the ScopedRealTimeAccess helper class.

References tracktion::graph::RealTimeSpinLock::try_lock().

◆ releaseRealTime()

template<typename ObjectType >
void tracktion::graph::LockFreeObject< ObjectType >::releaseRealTime ( )

Releases the use of the object from a previous call to retainRealTime.

References tracktion::graph::RealTimeSpinLock::unlock().

Referenced by tracktion::graph::LockFreeObject< ObjectType >::ScopedRealTimeAccess::~ScopedRealTimeAccess().

◆ getScopedAccess()

template<typename ObjectType >
ScopedRealTimeAccess tracktion::graph::LockFreeObject< ObjectType >::getScopedAccess ( )

Creates a ScopedRealTimeAccess for this LockFreeObject.


The documentation for this class was generated from the following file: