3 #ifndef _CDS_URCU_GENERAL_THREADED_H
4 #define _CDS_URCU_GENERAL_THREADED_H
6 #include <cds/urcu/details/gpt.h>
8 namespace cds { namespace urcu {
10 /// User-space general-purpose RCU with special thread for deferred reclamation
11 /** @anchor cds_urcu_general_threaded_gc
13 This is a wrapper around general_threaded class used for metaprogramming.
16 - \p Buffer - lock-free queue or lock-free bounded queue.
17 Default is cds::container::VyukovMPMCCycleQueue< retired_ptr >
18 - \p Lock - mutex type, default is \p std::mutex
19 - \p DisposerThread - reclamation thread class, default is \p cds::urcu::dispose_thread
20 See \ref cds::urcu::dispose_thread for class interface.
21 - \p Backoff - back-off schema, default is cds::backoff::Default
25 #ifdef CDS_DOXGEN_INVOKED
26 class Buffer = cds::container::VyukovMPMCCycleQueue<
28 ,cds::opt::buffer< cds::opt::v::dynamic_buffer< epoch_retired_ptr > >
30 ,class Lock = cds_std::mutex
31 ,class DisposerThread = dispose_thread<Buffer>
32 ,class Backoff = cds::backoff::Default
40 class gc< general_threaded< Buffer, Lock, DisposerThread, Backoff > >: public details::gc_common
43 typedef general_threaded< Buffer, Lock, DisposerThread, Backoff > rcu_implementation ; ///< Wrapped URCU implementation
45 typedef typename rcu_implementation::rcu_tag rcu_tag ; ///< URCU tag
46 typedef typename rcu_implementation::thread_gc thread_gc ; ///< Thread-side RCU part
47 typedef typename rcu_implementation::scoped_lock scoped_lock ; ///< Access lock class
49 using details::gc_common::atomic_marked_ptr;
52 /// Creates URCU \p %general_threaded singleton.
53 gc( size_t nBufferCapacity = 256 )
55 rcu_implementation::Construct( nBufferCapacity );
58 /// Destroys URCU \p %general_threaded singleton
61 rcu_implementation::Destruct( true );
65 /// Waits to finish a grace period and calls disposing thread
67 After grace period finished the function gives new task to disposing thread.
68 Unlike \ref force_dispose the \p %synchronize function does not wait for
69 task ending. Only a "task ready" message is sent to disposing thread.
71 static void synchronize()
73 rcu_implementation::instance()->synchronize();
76 /// Retires pointer \p p by the disposer \p pFunc
78 If the buffer is full, \ref synchronize function is invoked.
81 static void retire_ptr( T * p, void (* pFunc)(T *) )
83 retired_ptr rp( reinterpret_cast<void *>( p ), reinterpret_cast<free_retired_ptr_func>( pFunc ) );
87 /// Retires pointer \p p using \p Disposer
89 If the buffer is full, \ref synchronize function is invoked.
91 template <typename Disposer, typename T>
92 static void retire_ptr( T * p )
94 retire_ptr( p, cds::details::static_functor<Disposer, T>::call );
97 /// Retires pointer \p p of type \ref cds_urcu_retired_ptr "retired_ptr"
99 If the buffer is full, \ref synchronize function is invoked.
101 static void retire_ptr( retired_ptr& p )
103 rcu_implementation::instance()->retire_ptr(p);
106 /// Frees chain [ \p itFirst, \p itLast) in one synchronization cycle
107 template <typename ForwardIterator>
108 static void batch_retire( ForwardIterator itFirst, ForwardIterator itLast )
110 rcu_implementation::instance()->batch_retire( itFirst, itLast );
113 /// Acquires access lock (so called RCU reader-side lock)
115 For safety reasons, it is better to use \ref scoped_lock class for locking/unlocking
117 static void access_lock()
119 thread_gc::access_lock();
122 /// Releases access lock (so called RCU reader-side lock)
124 For safety reasons, it is better to use \ref scoped_lock class for locking/unlocking
126 static void access_unlock()
128 thread_gc::access_unlock();
131 /// Checks if the thread is inside read-side critical section (i.e. the lock is acquired)
133 Usually, this function is used internally to be convinced
134 that subsequent remove action is not lead to a deadlock.
136 static bool is_locked()
138 return thread_gc::is_locked();
141 /// Returns the threshold of internal buffer
142 static size_t capacity()
144 return rcu_implementation::instance()->capacity();
147 /// Forces retired object removal (synchronous version of \ref synchronize)
149 The function calls \ref synchronize and waits until reclamation thread
150 frees retired objects.
152 static void force_dispose()
154 rcu_implementation::instance()->force_dispose();
158 }} // namespace cds::urcu
160 #endif // #ifndef _CDS_URCU_GENERAL_THREADED_H