ardour
Public Member Functions | Private Attributes | List of all members
SerializedRCUManager< T > Class Template Reference

#include <rcu.h>

Inheritance diagram for SerializedRCUManager< T >:
RCUManager< T >

Public Member Functions

 SerializedRCUManager (T *new_rcu_value)
 
boost::shared_ptr< T > write_copy ()
 
bool update (boost::shared_ptr< T > new_value)
 
void flush ()
 
- Public Member Functions inherited from RCUManager< T >
 RCUManager (T *new_rcu_value)
 
virtual ~RCUManager ()
 
boost::shared_ptr< T > reader () const
 

Private Attributes

Glib::Threads::Mutex m_lock
 
boost::shared_ptr< T > * current_write_old
 
std::list< boost::shared_ptr< T > > m_dead_wood
 

Additional Inherited Members

- Protected Attributes inherited from RCUManager< T >
union {
   boost::shared_ptr< T > *   m_rcu_value
 
   volatile gpointer   gptr
 
x
 

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 m_rcu_value (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 114 of file rcu.h.

Constructor & Destructor Documentation

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

Definition at line 118 of file rcu.h.

Member Function Documentation

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

Definition at line 191 of file rcu.h.

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

Implements RCUManager< T >.

Definition at line 155 of file rcu.h.

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

Implements RCUManager< T >.

Definition at line 123 of file rcu.h.

Member Data Documentation

template<class T>
boost::shared_ptr<T>* SerializedRCUManager< T >::current_write_old
private

Definition at line 198 of file rcu.h.

template<class T>
std::list<boost::shared_ptr<T> > SerializedRCUManager< T >::m_dead_wood
private

Definition at line 199 of file rcu.h.

template<class T>
Glib::Threads::Mutex SerializedRCUManager< T >::m_lock
private

Definition at line 197 of file rcu.h.


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