3 #ifndef CDSLIB_URCU_GENERAL_INSTANT_H
4 #define CDSLIB_URCU_GENERAL_INSTANT_H
6 #include <cds/urcu/details/gpi.h>
8 namespace cds { namespace urcu {
10 /// User-space general-purpose RCU with immediate reclamation
11 /** @anchor cds_urcu_general_instant_gc
13 This is a wrapper around \p general_instant class.
16 - \p Lock - mutex type, default is \p std::mutex
17 - \p Backoff - back-off schema, default is \p cds::backoff::Default
20 #ifdef CDS_DOXGEN_INVOKED
21 class Lock = std::mutex
22 ,class Backoff = cds::backoff::Default
28 class gc< general_instant< Lock, Backoff > >: public details::gc_common
31 typedef general_instant< Lock, Backoff > rcu_implementation ; ///< Wrapped URCU implementation
33 typedef typename rcu_implementation::rcu_tag rcu_tag ; ///< URCU tag
34 typedef typename rcu_implementation::thread_gc thread_gc ; ///< Thread-side RCU part
35 typedef typename rcu_implementation::scoped_lock scoped_lock ; ///< Access lock class
37 using details::gc_common::atomic_marked_ptr;
40 /// Creates URCU \p %general_instant singleton
43 rcu_implementation::Construct();
46 /// Destroys URCU \p %general_instant singleton
49 rcu_implementation::Destruct( true );
53 /// Waits to finish a grace period
54 static void synchronize()
56 rcu_implementation::instance()->synchronize();
59 /// Frees the pointer \p p invoking \p pFunc after end of grace period
61 The function calls \ref synchronize to wait for end of grace period
62 and then evaluates disposing expression <tt>pFunc( p )</tt>
65 static void retire_ptr( T * p, void (* pFunc)(T *) )
67 retired_ptr rp( reinterpret_cast<void *>( p ), reinterpret_cast<free_retired_ptr_func>( pFunc ) );
71 /// Frees the pointer \p using \p Disposer after end of grace period
73 The function calls \ref synchronize to wait for end of grace period
74 and then evaluates disposing expression <tt>Disposer()( p )</tt>
76 template <typename Disposer, typename T>
77 static void retire_ptr( T * p )
79 retire_ptr( p, cds::details::static_functor<Disposer, T>::call );
82 /// Frees the pointer \p after the end of grace period
84 The function calls \ref synchronize to wait for end of grace period
85 and then evaluates disposing expression <tt>p.m_funcFree( p.m_p )</tt>
87 static void retire_ptr( retired_ptr& p )
89 rcu_implementation::instance()->retire_ptr(p);
92 /// Frees chain [ \p itFirst, \p itLast) in one synchronization cycle
93 template <typename ForwardIterator>
94 static void batch_retire( ForwardIterator itFirst, ForwardIterator itLast )
96 rcu_implementation::instance()->batch_retire( itFirst, itLast );
99 /// Retires the pointer chain until \p Func returns \p nullptr retired pointer
100 template <typename Func>
101 static void batch_retire( Func e )
103 rcu_implementation::instance()->batch_retire( e );
106 /// Acquires access lock (so called RCU reader-side lock)
108 For safety reasons, it is better to use \ref scoped_lock class for locking/unlocking
110 static void access_lock()
112 thread_gc::access_lock();
115 /// Releases access lock (so called RCU reader-side lock)
117 For safety reasons, it is better to use \ref scoped_lock class for locking/unlocking
119 static void access_unlock()
121 thread_gc::access_unlock();
124 /// Checks if the thread is inside read-side critical section (i.e. the lock is acquired)
126 Usually, this function is used internally to be convinced
127 that subsequent remove action is not lead to a deadlock.
129 static bool is_locked()
131 return thread_gc::is_locked();
134 /// Forced GC cycle call.
136 This method does nothing and is introduced only for uniformity with other
139 static void force_dispose()
143 }} // namespace cds::urcu
145 #endif // #ifndef CDSLIB_URCU_GENERAL_INSTANT_H