3 #ifndef __CDS_URCU_EXEMPT_PTR_H
4 #define __CDS_URCU_EXEMPT_PTR_H
6 #include <cds/details/defs.h>
8 namespace cds { namespace urcu {
12 template <typename Node, typename Value>
13 struct conventional_exempt_member_cast
15 Value * operator()( Node * p ) const
21 template <typename Node, typename Value>
22 struct conventional_exempt_pair_cast
24 Value * operator()( Node * p ) const
29 } // namespace details
32 /// Exempt pointer for RCU
34 This special pointer class is intended for returning extracted node from RCU-based container.
35 The destructor (and \p release() member function) invokes <tt>RCU::retire_ptr< Disposer >()</tt> function to dispose the node.
36 For non-intrusive containers from \p cds::container namespace \p Disposer is usually an invocation
37 of node deallocator. For intrusive containers the disposer can be empty or it can trigger an event "node can be reused safely".
38 In any case, the exempt pointer concept keeps RCU semantics.
40 You don't need use this helper class directly. Any RCU-based container typedefs a simplified version of this template.
43 - \p RCU - one of \ref cds_urcu_gc "RCU type"
44 - \p NodeType - container's node type
45 - \p ValueType - value type stored in container's node. For intrusive containers it is the same as \p NodeType
46 - \p Disposer - a disposer functor
47 - \p Cast - a functor for casting from \p NodeType to \p ValueType. For intrusive containers
48 the casting is usually disabled, i.e. \p Cast is \p void.
55 #ifdef CDS_DOXYGEN_INVOKED
58 typename Cast=details::conventional_exempt_member_cast<NodeType, ValueType>
64 typedef RCU rcu ; ///< RCU type - one of <tt>cds::urcu::gc< ... ></tt>
65 typedef NodeType node_type ; ///< Node type
66 typedef ValueType value_type ; ///< Value type
67 typedef Disposer disposer ; ///< Disposer calling when release
68 typedef Cast node_to_value_cast ; ///< Functor converting \p node_type to \p value_type
76 /// Constructs empty pointer
77 exempt_ptr() CDS_NOEXCEPT
82 /// Creates exempt pointer for \p pNode. Only for internal use.
83 explicit exempt_ptr( node_type * pNode ) CDS_NOEXCEPT
86 explicit exempt_ptr( std::nullptr_t ) CDS_NOEXCEPT
92 exempt_ptr( exempt_ptr&& p ) CDS_NOEXCEPT
93 : m_pNode( p.m_pNode )
98 /// The exempt pointer is not copy-constructible
99 exempt_ptr( exempt_ptr const& ) = delete;
101 /// Releases the pointer
107 /// Checks if the pointer is \p nullptr
108 bool empty() const CDS_NOEXCEPT
110 return m_pNode == nullptr;
113 /// \p bool operator returns <tt>!empty()</tt>
114 explicit operator bool() const CDS_NOEXCEPT
119 /// Dereference operator
120 value_type * operator->() const CDS_NOEXCEPT
122 return !empty() ? node_to_value_cast()(m_pNode) : nullptr;
125 /// Returns a reference to the value
126 value_type& operator *() CDS_NOEXCEPT
129 return *node_to_value_cast()( m_pNode );
132 /// Move assignment. Can be called only outside of RCU critical section
133 exempt_ptr& operator =( exempt_ptr&& p ) CDS_NOEXCEPT
141 /// The exempt pointer is not copy-assignable
142 exempt_ptr& operator=(exempt_ptr const&) = delete;
144 /// Disposes the pointer. Should be called only outside of RCU critical section
147 assert( !rcu::is_locked() );
149 rcu::template retire_ptr<disposer>( m_pNode );
156 // Intrusive container specialization
162 class exempt_ptr< RCU, NodeType, NodeType, Disposer, void >
165 typedef RCU rcu ; ///< RCU type - one of <tt>cds::urcu::gc< ... ></tt>
166 typedef NodeType node_type ; ///< Node type
167 typedef NodeType value_type ; ///< Node type
168 typedef Disposer disposer ; ///< Disposer calling when release
169 typedef void node_to_value_cast; ///< No casting is needed
175 /// Constructs empty pointer
176 exempt_ptr() CDS_NOEXCEPT
180 /// Creates exempt pointer for \p pNode. Only for internal use.
181 explicit exempt_ptr( node_type * pNode ) CDS_NOEXCEPT
184 explicit exempt_ptr( std::nullptr_t ) CDS_NOEXCEPT
189 exempt_ptr( exempt_ptr&& p ) CDS_NOEXCEPT
190 : m_pNode( p.m_pNode )
196 /// The exempt pointer is not copy-constructible
197 exempt_ptr( exempt_ptr const& ) = delete;
199 /// Releases the pointer
205 /// Checks if the pointer is \p nullptr
206 bool empty() const CDS_NOEXCEPT
208 return m_pNode == nullptr;
211 /// \p bool operator returns <tt>!empty()</tt>
212 explicit operator bool() const CDS_NOEXCEPT
217 /// Dereference operator.
218 value_type * operator->() const CDS_NOEXCEPT
220 return !empty() ? m_pNode : nullptr;
223 /// Returns a reference to the value
224 value_type& operator *() CDS_NOEXCEPT
230 /// Move assignment. Can be called only outside of RCU critical section
231 exempt_ptr& operator =(exempt_ptr&& p) CDS_NOEXCEPT
239 /// The exempt pointer is not copy-assignable
240 exempt_ptr& operator=(exempt_ptr const&) = delete;
242 /// Disposes the pointer. Should be called only outside of RCU critical section
246 assert( !rcu::is_locked() );
247 rcu::template retire_ptr<disposer>( m_pNode );
254 }} // namespace cds::urcu
256 #endif //#ifndef __CDS_URCU_EXEMPT_PTR_H