3 #ifndef CDSLIB_URCU_GENERAL_BUFFERED_H
4 #define CDSLIB_URCU_GENERAL_BUFFERED_H
6 #include <cds/urcu/details/gpb.h>
8 namespace cds { namespace urcu {
10 /// User-space general-purpose RCU with deferred buffered reclamation
11 /** @anchor cds_urcu_general_buffered_gc
13 This is a wrapper around general_buffered 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 Backoff - back-off schema, default is cds::backoff::Default
22 #ifdef CDS_DOXGEN_INVOKED
23 class Buffer = cds::container::VyukovMPMCCycleQueue< retired_ptr >
24 ,class Lock = std::mutex
25 ,class Backoff = cds::backoff::Default
32 class gc< general_buffered< Buffer, Lock, Backoff > >: public details::gc_common
35 typedef general_buffered< Buffer, Lock, Backoff > rcu_implementation ; ///< Wrapped URCU implementation
37 typedef typename rcu_implementation::rcu_tag rcu_tag ; ///< URCU tag
38 typedef typename rcu_implementation::thread_gc thread_gc ; ///< Thread-side RCU part
39 typedef typename rcu_implementation::scoped_lock scoped_lock ; ///< Access lock class
41 using details::gc_common::atomic_marked_ptr;
44 /// Creates URCU \p %general_buffered singleton.
45 gc( size_t nBufferCapacity = 256 )
47 rcu_implementation::Construct( nBufferCapacity );
50 /// Destroys URCU \p %general_instant singleton
53 rcu_implementation::Destruct( true );
57 /// Waits to finish a grace period and clears the buffer
59 After grace period finished the function frees all retired pointer
62 static void synchronize()
64 rcu_implementation::instance()->synchronize();
67 /// Places retired pointer <\p p, \p pFunc> to internal buffer
69 If the buffer is full, \ref synchronize function is invoked.
72 static void retire_ptr( T * p, void (* pFunc)(T *) )
74 retired_ptr rp( reinterpret_cast<void *>( p ), reinterpret_cast<free_retired_ptr_func>( pFunc ) );
78 /// Places retired pointer \p p with \p Disposer to internal buffer
80 If the buffer is full, \ref synchronize function is invoked.
82 template <typename Disposer, typename T>
83 static void retire_ptr( T * p )
85 retire_ptr( p, cds::details::static_functor<Disposer, T>::call );
88 /// Places retired pointer \p p to internal buffer
90 If the buffer is full, \ref synchronize function is invoked.
92 static void retire_ptr( retired_ptr& p )
94 rcu_implementation::instance()->retire_ptr(p);
97 /// Frees chain [ \p itFirst, \p itLast) in one synchronization cycle
98 template <typename ForwardIterator>
99 static void batch_retire( ForwardIterator itFirst, ForwardIterator itLast )
101 rcu_implementation::instance()->batch_retire( itFirst, itLast );
104 /// Acquires access lock (so called RCU reader-side lock)
106 For safety reasons, it is better to use \ref scoped_lock class for locking/unlocking
108 static void access_lock()
110 thread_gc::access_lock();
113 /// Releases 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_unlock()
119 thread_gc::access_unlock();
122 /// Returns the threshold of internal buffer
123 static size_t capacity()
125 return rcu_implementation::instance()->capacity();
128 /// Checks if the thread is inside read-side critical section (i.e. the lock is acquired)
130 Usually, this function is used internally to be convinced
131 that subsequent remove action is not lead to a deadlock.
133 static bool is_locked()
135 return thread_gc::is_locked();
138 /// Forces retired object removal
140 This function calls \ref synchronize
142 static void force_dispose()
148 }} // namespace cds::urcu
150 #endif // #ifndef CDSLIB_URCU_GENERAL_BUFFERED_H