Ardour  9.0-pre0-582-g084a23a80d
SerializedRCUManager< T > Class Template Reference

#include <rcu.h>

Inheritance diagram for SerializedRCUManager< T >:
[legend]

Public Member Functions

 SerializedRCUManager (T *new_managed_object)
 
void init (std::shared_ptr< T > object_to_be_managed)
 
std::shared_ptr< T > write_copy ()
 
void abort ()
 
bool update (std::shared_ptr< T > new_value)
 
void no_update ()
 
void flush ()
 
- Public Member Functions inherited from RCUManager< T >
 RCUManager (T *object_to_be_managed)
 
virtual ~RCUManager ()
 
std::shared_ptr< T const > reader () const
 

Private Attributes

std::mutex _lock
 
RCUManager< T >::PtrToSharedPtr _current_write_old
 
std::list< std::shared_ptr< T > > _dead_wood
 

Additional Inherited Members

- Protected Types inherited from RCUManager< T >
typedef std::shared_ptr< T > * PtrToSharedPtr
 
- Protected Member Functions inherited from RCUManager< T >
bool active_read () const
 
- Protected Attributes inherited from RCUManager< T >
std::atomic< PtrToSharedPtrmanaged_object
 

Detailed Description

template<class T>
class SerializedRCUManager< T >

Serialized RCUManager implements the RCUManager interface. It is based on the following key assumption: among its users we have readers that are bound by RT time constraints, and writers who are not. Therefore, we do not care how slow the write_copy()/update() operations are, or what synchronization primitives they use.

Because of this design assumption, this class will serialize all writers. That is, objects calling write_copy()/update() will be serialized by a mutex. Only a single writer may be in the middle of write_copy()/update(); all other writers will block until the first has finished. The order of execution of multiple writers if more than one is blocked in this way is undefined.

The class maintains a lock-protected "dead wood" list of old value of *managed_object (i.e. shared_ptr<T>). The list is cleaned up every time we call write_copy(). If the list is the last instance of a shared_ptr<T> that references the object (determined by shared_ptr::unique()) then we erase it from the list, thus deleting the object it points to. This is lazy destruction - the SerializedRCUManager assumes that there will sufficient calls to write_copy() to ensure that we do not inadvertently leave objects around for excessive periods of time.

For extremely well defined circumstances (i.e. it is known that there are no other writer objects in existence), SerializedRCUManager also provides a flush() method that will unconditionally clear out the "dead wood" list. It must be used with significant caution, although the use of shared_ptr<T> means that no actual objects will be deleted incorrectly if this is misused.

Definition at line 141 of file rcu.h.

Constructor & Destructor Documentation

◆ SerializedRCUManager()

template<class T >
SerializedRCUManager< T >::SerializedRCUManager ( T *  new_managed_object)
inline

Definition at line 144 of file rcu.h.

Member Function Documentation

◆ abort()

template<class T >
void SerializedRCUManager< T >::abort ( )
inline

Definition at line 191 of file rcu.h.

◆ flush()

template<class T >
void SerializedRCUManager< T >::flush ( void  )
inline

Definition at line 268 of file rcu.h.

◆ init()

template<class T >
void SerializedRCUManager< T >::init ( std::shared_ptr< T >  object_to_be_managed)
inline

Definition at line 150 of file rcu.h.

◆ no_update()

template<class T >
void SerializedRCUManager< T >::no_update ( )
inline

Definition at line 261 of file rcu.h.

◆ update()

template<class T >
bool SerializedRCUManager< T >::update ( std::shared_ptr< T >  new_value)
inlinevirtual

Implements RCUManager< T >.

Definition at line 195 of file rcu.h.

◆ write_copy()

template<class T >
std::shared_ptr<T> SerializedRCUManager< T >::write_copy ( )
inlinevirtual

Implements RCUManager< T >.

Definition at line 155 of file rcu.h.

Member Data Documentation

◆ _current_write_old

template<class T >
RCUManager<T>::PtrToSharedPtr SerializedRCUManager< T >::_current_write_old
private

Definition at line 276 of file rcu.h.

◆ _dead_wood

template<class T >
std::list<std::shared_ptr<T> > SerializedRCUManager< T >::_dead_wood
private

Definition at line 277 of file rcu.h.

◆ _lock

template<class T >
std::mutex SerializedRCUManager< T >::_lock
private

Definition at line 275 of file rcu.h.


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