3 #ifndef CDSLIB_URCU_SIGNAL_BUFFERED_H
4 #define CDSLIB_URCU_SIGNAL_BUFFERED_H
6 #include <cds/urcu/details/sig_buffered.h>
7 #ifdef CDS_URCU_SIGNAL_HANDLING_ENABLED
9 namespace cds { namespace urcu {
11 /// User-space signal-handled RCU with deferred buffered reclamation
12 /** @anchor cds_urcu_signal_buffered_gc
14 This is a wrapper around signal_buffered class used for metaprogramming.
17 - \p Buffer - lock-free queue or lock-free bounded queue.
18 Default is cds::container::VyukovMPMCCycleQueue< retired_ptr >
19 - \p Lock - mutex type, default is \p std::mutex
20 - \p Backoff - back-off schema, default is cds::backoff::Default
23 #ifdef CDS_DOXGEN_INVOKED
24 class Buffer = cds::container::VyukovMPMCCycleQueue< retired_ptr >
25 ,class Lock = std::mutex
26 ,class Backoff = cds::backoff::Default
33 class gc< signal_buffered< Buffer, Lock, Backoff > >: public details::gc_common
36 typedef signal_buffered< Buffer, Lock, Backoff > rcu_implementation ; ///< Wrapped URCU implementation
38 typedef typename rcu_implementation::rcu_tag rcu_tag ; ///< URCU tag
39 typedef typename rcu_implementation::thread_gc thread_gc ; ///< Thread-side RCU part
40 typedef typename rcu_implementation::scoped_lock scoped_lock ; ///< Access lock class
42 using details::gc_common::atomic_marked_ptr;
45 /// Creates URCU \p %signal_buffered singleton.
47 The \p nBufferCapacity parameter defines RCU threshold.
49 The \p nSignal parameter defines a signal number stated for RCU, default is \p SIGUSR1
51 gc( size_t nBufferCapacity = 256, int nSignal = SIGUSR1 )
53 rcu_implementation::Construct( nBufferCapacity, nSignal );
56 /// Destroys URCU \p %general_instant singleton
59 rcu_implementation::Destruct( true );
63 /// Waits to finish a grace period and clears the buffer
65 After grace period finished the function frees all retired pointer
68 static void synchronize()
70 rcu_implementation::instance()->synchronize();
73 /// Places retired pointer <\p p, \p pFunc> to internal buffer
75 If the buffer is full, \ref synchronize function is invoked.
78 static void retire_ptr( T * p, void (* pFunc)(T *) )
80 retired_ptr rp( reinterpret_cast<void *>( p ), reinterpret_cast<free_retired_ptr_func>( pFunc ) );
84 /// Places retired pointer \p p with \p Disposer to internal buffer
86 If the buffer is full, \ref synchronize function is invoked.
88 template <typename Disposer, typename T>
89 static void retire_ptr( T * p )
91 retire_ptr( p, cds::details::static_functor<Disposer, T>::call );
94 /// Places retired pointer \p p to internal buffer
96 If the buffer is full, \ref synchronize function is invoked.
98 static void retire_ptr( retired_ptr& p )
100 rcu_implementation::instance()->retire_ptr(p);
103 /// Frees chain [ \p itFirst, \p itLast) in one synchronization cycle
104 template <typename ForwardIterator>
105 static void batch_retire( ForwardIterator itFirst, ForwardIterator itLast )
107 rcu_implementation::instance()->batch_retire( itFirst, itLast );
110 /// Acquires access lock (so called RCU reader-side lock)
112 For safety reasons, it is better to use \ref scoped_lock class for locking/unlocking
114 static void access_lock()
116 thread_gc::access_lock();
119 /// Releases access lock (so called RCU reader-side lock)
121 For safety reasons, it is better to use \ref scoped_lock class for locking/unlocking
123 static void access_unlock()
125 thread_gc::access_unlock();
128 /// Returns the threshold of internal buffer
129 static size_t capacity()
131 return rcu_implementation::instance()->capacity();
134 /// Returns the signal number stated for RCU
135 static int signal_no()
137 return rcu_implementation::instance()->signal_no();
140 /// Checks if the thread is inside read-side critical section (i.e. the lock is acquired)
142 Usually, this function is used internally to be convinced
143 that subsequent remove action is not lead to a deadlock.
145 static bool is_locked()
147 return thread_gc::is_locked();
150 /// Forces retired object removal
152 This function calls \ref synchronize
154 static void force_dispose()
160 }} // namespace cds::urcu
162 #endif // #ifdef CDS_URCU_SIGNAL_HANDLING_ENABLED
163 #endif // #ifndef CDSLIB_URCU_SIGNAL_BUFFERED_H