3 #ifndef _CDS_URCU_GENERAL_BUFFERED_H
4 #define _CDS_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<
25 ,cds::opt::buffer< cds::opt::v::dynamic_buffer< retired_ptr > >
27 ,class Lock = cds_std::mutex
28 ,class Backoff = cds::backoff::Default
35 class gc< general_buffered< Buffer, Lock, Backoff > >: public details::gc_common
38 typedef general_buffered< Buffer, Lock, Backoff > rcu_implementation ; ///< Wrapped URCU implementation
40 typedef typename rcu_implementation::rcu_tag rcu_tag ; ///< URCU tag
41 typedef typename rcu_implementation::thread_gc thread_gc ; ///< Thread-side RCU part
42 typedef typename rcu_implementation::scoped_lock scoped_lock ; ///< Access lock class
44 using details::gc_common::atomic_marked_ptr;
47 /// Creates URCU \p %general_buffered singleton.
48 gc( size_t nBufferCapacity = 256 )
50 rcu_implementation::Construct( nBufferCapacity );
53 /// Destroys URCU \p %general_instant singleton
56 rcu_implementation::Destruct( true );
60 /// Waits to finish a grace period and clears the buffer
62 After grace period finished the function frees all retired pointer
65 static void synchronize()
67 rcu_implementation::instance()->synchronize();
70 /// Places retired pointer <\p p, \p pFunc> to internal buffer
72 If the buffer is full, \ref synchronize function is invoked.
75 static void retire_ptr( T * p, void (* pFunc)(T *) )
77 retired_ptr rp( reinterpret_cast<void *>( p ), reinterpret_cast<free_retired_ptr_func>( pFunc ) );
81 /// Places retired pointer \p p with \p Disposer to internal buffer
83 If the buffer is full, \ref synchronize function is invoked.
85 template <typename Disposer, typename T>
86 static void retire_ptr( T * p )
88 retire_ptr( p, cds::details::static_functor<Disposer, T>::call );
91 /// Places retired pointer \p p to internal buffer
93 If the buffer is full, \ref synchronize function is invoked.
95 static void retire_ptr( retired_ptr& p )
97 rcu_implementation::instance()->retire_ptr(p);
100 /// Frees chain [ \p itFirst, \p itLast) in one synchronization cycle
101 template <typename ForwardIterator>
102 static void batch_retire( ForwardIterator itFirst, ForwardIterator itLast )
104 rcu_implementation::instance()->batch_retire( itFirst, itLast );
107 /// Acquires access lock (so called RCU reader-side lock)
109 For safety reasons, it is better to use \ref scoped_lock class for locking/unlocking
111 static void access_lock()
113 thread_gc::access_lock();
116 /// Releases access lock (so called RCU reader-side lock)
118 For safety reasons, it is better to use \ref scoped_lock class for locking/unlocking
120 static void access_unlock()
122 thread_gc::access_unlock();
125 /// Returns the threshold of internal buffer
126 static size_t capacity()
128 return rcu_implementation::instance()->capacity();
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 /// Forces retired object removal
143 This function calls \ref synchronize
145 static void force_dispose()
151 }} // namespace cds::urcu
153 #endif // #ifndef _CDS_URCU_GENERAL_BUFFERED_H