2 This file is a part of libcds - Concurrent Data Structures library
4 (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2017
6 Source code repo: http://github.com/khizmax/libcds/
7 Download: http://sourceforge.net/projects/libcds/files/
9 Redistribution and use in source and binary forms, with or without
10 modification, are permitted provided that the following conditions are met:
12 * Redistributions of source code must retain the above copyright notice, this
13 list of conditions and the following disclaimer.
15 * Redistributions in binary form must reproduce the above copyright notice,
16 this list of conditions and the following disclaimer in the documentation
17 and/or other materials provided with the distribution.
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #ifndef CDSLIB_URCU_GENERAL_INSTANT_H
32 #define CDSLIB_URCU_GENERAL_INSTANT_H
34 #include <cds/urcu/details/gpi.h>
36 namespace cds { namespace urcu {
38 /// User-space general-purpose RCU with immediate reclamation
39 /** @anchor cds_urcu_general_instant_gc
41 This is a wrapper around \p general_instant class.
44 - \p Lock - mutex type, default is \p std::mutex
45 - \p Backoff - back-off schema, default is \p cds::backoff::Default
48 #ifdef CDS_DOXGEN_INVOKED
49 class Lock = std::mutex
50 ,class Backoff = cds::backoff::Default
56 class gc< general_instant< Lock, Backoff > >: public details::gc_common
59 typedef general_instant< Lock, Backoff > rcu_implementation ; ///< Wrapped URCU implementation
61 typedef typename rcu_implementation::rcu_tag rcu_tag ; ///< URCU tag
62 typedef typename rcu_implementation::thread_gc thread_gc ; ///< Thread-side RCU part
63 typedef typename rcu_implementation::scoped_lock scoped_lock ; ///< Access lock class
65 using details::gc_common::atomic_marked_ptr;
68 /// Creates URCU \p %general_instant singleton
71 rcu_implementation::Construct();
74 /// Destroys URCU \p %general_instant singleton
77 rcu_implementation::Destruct( true );
81 /// Waits to finish a grace period
82 static void synchronize()
84 rcu_implementation::instance()->synchronize();
87 /// Frees the pointer \p p invoking \p pFunc after end of grace period
89 The function calls \ref synchronize to wait for end of grace period
90 and then evaluates disposing expression <tt>pFunc( p )</tt>
93 static void retire_ptr( T* p, free_retired_ptr_func pFunc )
95 retired_ptr rp( p, pFunc );
99 /// Frees the pointer \p using \p Disposer after end of grace period
101 The function calls \ref synchronize to wait for end of grace period
102 and then evaluates disposing expression <tt>Disposer()( p )</tt>
104 template <typename Disposer, typename T>
105 static void retire_ptr( T* p )
107 retire_ptr( p, cds::details::static_functor<Disposer, T>::call );
110 /// Frees the pointer \p after the end of grace period
112 The function calls \ref synchronize to wait for end of grace period
113 and then evaluates disposing expression <tt>p.m_funcFree( p.m_p )</tt>
115 static void retire_ptr( retired_ptr& p )
117 rcu_implementation::instance()->retire_ptr(p);
120 /// Frees chain [ \p itFirst, \p itLast) in one synchronization cycle
121 template <typename ForwardIterator>
122 static void batch_retire( ForwardIterator itFirst, ForwardIterator itLast )
124 rcu_implementation::instance()->batch_retire( itFirst, itLast );
127 /// Retires the pointer chain until \p Func returns \p nullptr retired pointer
128 template <typename Func>
129 static void batch_retire( Func e )
131 rcu_implementation::instance()->batch_retire( e );
134 /// Acquires access lock (so called RCU reader-side lock)
136 For safety reasons, it is better to use \ref scoped_lock class for locking/unlocking
138 static void access_lock()
140 thread_gc::access_lock();
143 /// Releases access lock (so called RCU reader-side lock)
145 For safety reasons, it is better to use \ref scoped_lock class for locking/unlocking
147 static void access_unlock()
149 thread_gc::access_unlock();
152 /// Checks if the thread is inside read-side critical section (i.e. the lock is acquired)
154 Usually, this function is used internally to be convinced
155 that subsequent remove action is not lead to a deadlock.
157 static bool is_locked()
159 return thread_gc::is_locked();
162 /// Forced GC cycle call.
164 This method does nothing and is introduced only for uniformity with other
167 static void force_dispose()
173 class gc< general_instant_stripped >: public gc< general_instant<>>
177 }} // namespace cds::urcu
179 #endif // #ifndef CDSLIB_URCU_GENERAL_INSTANT_H