4 #include "boost/shared_ptr.hpp"
5 #include "glibmm/thread.h"
14 RCUManager (T* new_rcu_value)
15 : m_rcu_value(new_rcu_value)
20 virtual ~RCUManager() { }
22 boost::shared_ptr<T> reader () const { return m_rcu_value; }
25 virtual boost::shared_ptr<T> write_copy () = 0;
28 virtual void update (boost::shared_ptr<T> new_value) = 0;
32 boost::shared_ptr<T> m_rcu_value;
39 class SerializedRCUManager : public RCUManager<T>
43 SerializedRCUManager(T* new_rcu_value)
44 : RCUManager<T>(new_rcu_value)
49 virtual boost::shared_ptr<T> write_copy ()
53 // I hope this is doing what I think it is doing :)
54 boost::shared_ptr<T> new_copy(new T(*RCUManager<T>::m_rcu_value));
56 // XXX todo remove old copies with only 1 reference from the list.
61 virtual void update (boost::shared_ptr<T> new_value)
63 // So a current reader doesn't hold the only reference to
64 // the existing value when we assign it a new value which
65 // should ensure that deletion of old values doesn't
66 // occur in a reader thread.
67 boost::shared_ptr<T> old_copy = RCUManager<T>::m_rcu_value;
69 // we hold the lock at this point effectively blocking
71 RCUManager<T>::m_rcu_value = new_value;
74 // XXX add the old value to the list of old copies.
82 std::list<boost::shared_ptr<T> > m_old_values;
90 RCUWriter(RCUManager<T>& manager)
93 m_copy = m_manager.write_copy();
98 // we can check here that the refcount of m_copy is 1
100 if(m_copy.use_count() == 1) {
101 m_manager.update(m_copy);
109 // or operator boost::shared_ptr<T> ();
110 boost::shared_ptr<T> get_copy() { return m_copy; }
114 RCUManager<T>& m_manager;
116 // preferably this holds a pointer to T
117 boost::shared_ptr<T> m_copy;
120 #endif /* __pbd_rcu_h__ */