3 #ifndef CDSLIB_URCU_EXEMPT_PTR_H
4 #define CDSLIB_URCU_EXEMPT_PTR_H
7 #include <cds/details/defs.h>
9 namespace cds { namespace urcu {
13 template <typename Node, typename Value>
14 struct conventional_exempt_member_cast
16 Value * operator()( Node * p ) const
22 template <typename Node, typename Value>
23 struct conventional_exempt_pair_cast
25 Value * operator()( Node * p ) const
30 } // namespace details
33 /// Exempt pointer for RCU
35 This special pointer class is intended for returning extracted node from RCU-based container.
36 The destructor (and \p release() member function) invokes <tt>RCU::retire_ptr< Disposer >()</tt> function to dispose the node.
37 For non-intrusive containers from \p cds::container namespace \p Disposer is usually an invocation
38 of node deallocator. For intrusive containers the disposer can be empty or it can trigger an event "node can be reused safely".
39 In any case, the exempt pointer concept keeps RCU semantics.
40 The destructor or \p release() should be called outside the RCU lock of current thread.
42 You don't need use this helper class directly. Any RCU-based container typedefs a simplified version of this template.
45 - \p RCU - one of \ref cds_urcu_gc "RCU type"
46 - \p NodeType - container's node type
47 - \p ValueType - value type stored in container's node. For intrusive containers it is the same as \p NodeType
48 - \p Disposer - a disposer functor
49 - \p Cast - a functor for casting from \p NodeType to \p ValueType. For intrusive containers
50 the casting is usually disabled, i.e. \p Cast is \p void.
57 #ifdef CDS_DOXYGEN_INVOKED
60 typename Cast=details::conventional_exempt_member_cast<NodeType, ValueType>
67 ValueType * operator()( NodeType * p ) const
74 typedef RCU rcu ; ///< RCU type - one of <tt>cds::urcu::gc< ... ></tt>
75 typedef NodeType node_type ; ///< Node type
76 typedef ValueType value_type ; ///< Value type
77 typedef Disposer disposer ; ///< Disposer calling when release
78 /// Functor converting \p node_type to \p value_type
79 typedef typename std::conditional< std::is_same< Cast, void >::value, trivial_cast, Cast>::type node_to_value_cast;
87 /// Constructs empty pointer
88 exempt_ptr() CDS_NOEXCEPT
93 /// Creates exempt pointer for \p pNode. Only for internal use.
94 explicit exempt_ptr( node_type * pNode ) CDS_NOEXCEPT
97 explicit exempt_ptr( std::nullptr_t ) CDS_NOEXCEPT
103 exempt_ptr( exempt_ptr&& p ) CDS_NOEXCEPT
104 : m_pNode( p.m_pNode )
109 /// The exempt pointer is not copy-constructible
110 exempt_ptr( exempt_ptr const& ) = delete;
112 /// Releases the pointer, see \p release()
118 /// Checks if the pointer is \p nullptr
119 bool empty() const CDS_NOEXCEPT
121 return m_pNode == nullptr;
124 /// \p bool operator returns <tt>!empty()</tt>
125 explicit operator bool() const CDS_NOEXCEPT
130 /// Dereference operator
131 value_type * operator->() const CDS_NOEXCEPT
133 return !empty() ? node_to_value_cast()(m_pNode) : nullptr;
136 /// Returns a reference to the value
137 value_type& operator *() CDS_NOEXCEPT
140 return *node_to_value_cast()( m_pNode );
143 /// Move assignment. Can be called only outside of RCU critical section
144 exempt_ptr& operator =( exempt_ptr&& p ) CDS_NOEXCEPT
152 /// The exempt pointer is not copy-assignable
153 exempt_ptr& operator=(exempt_ptr const&) = delete;
155 /// Disposes the pointer. Should be called only outside of RCU critical section
159 assert( !rcu::is_locked() );
160 rcu::template retire_ptr<disposer>( m_pNode );
165 }} // namespace cds::urcu
167 #endif //#ifndef CDSLIB_URCU_EXEMPT_PTR_H