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 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 defines a proper typedef for 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. Usually, for intrusive containers \p Cast may be \p void.
54 #ifdef CDS_DOXYGEN_INVOKED
57 typename Cast=details::conventional_exempt_member_cast<NodeType, ValueType>
62 //TODO: use move semantics and explicit operator bool!
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
77 // No copy-constructible
78 exempt_ptr( exempt_ptr const& );
79 exempt_ptr& operator=( exempt_ptr const& );
83 /// Constructs empty pointer
84 exempt_ptr() CDS_NOEXCEPT
88 /// Releases the pointer
94 /// Checks if the pointer is \p NULL
95 bool empty() const CDS_NOEXCEPT
97 return m_pNode == nullptr;
100 /// Dereference operator
101 value_type * operator->() const CDS_NOEXCEPT
103 return !empty() ? node_to_value_cast()(m_pNode) : nullptr;
106 /// Returns a reference to the value
107 value_type& operator *() CDS_NOEXCEPT
110 return *node_to_value_cast()( m_pNode );
114 /// Assignment operator, the object should be empty. For internal use only
115 exempt_ptr& operator =( node_type * pNode )
117 // release() cannot be called in this point since RCU should be locked
119 assert( rcu::is_locked() );
125 /// Disposes the pointer. Should be called only outside of RCU critical section
128 assert( !rcu::is_locked() );
130 rcu::template retire_ptr<disposer>( m_pNode );
137 // Intrusive container specialization
143 class exempt_ptr< RCU, NodeType, NodeType, Disposer, void >
145 //TODO: use move semantics and explicit operator bool!
147 typedef RCU rcu ; ///< RCU type - one of <tt>cds::urcu::gc< ... ></tt>
148 typedef NodeType node_type ; ///< Node type
149 typedef NodeType value_type ; ///< Node type
150 typedef Disposer disposer ; ///< Disposer calling when release
151 typedef void node_to_value_cast; ///< No casting is needed
157 // No copy-constructible
158 exempt_ptr( exempt_ptr const& );
159 exempt_ptr& operator=( exempt_ptr const& );
162 /// Constructs empty pointer
163 exempt_ptr() CDS_NOEXCEPT
167 /// Releases the pointer
173 /// Checks if the pointer is \p NULL
174 bool empty() const CDS_NOEXCEPT
176 return m_pNode == nullptr;
179 /// Dereference operator.
180 value_type * operator->() const CDS_NOEXCEPT
182 return !empty() ? m_pNode : nullptr;
185 /// Returns a reference to the value
186 value_type& operator *() CDS_NOEXCEPT
192 /// Assignment operator, the object should be empty. For internal use only
193 exempt_ptr& operator =( node_type * pNode )
195 // release() cannot be called in this point since RCU should be locked
197 assert( rcu::is_locked() );
202 /// Disposes the pointer. Should be called only outside of RCU critical section
205 assert( !rcu::is_locked() );
207 rcu::template retire_ptr<disposer>( m_pNode );
214 }} // namespace cds::urcu
216 #endif //#ifndef __CDS_URCU_EXEMPT_PTR_H