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.
41 You don't need use this helper class directly. Any RCU-based container typedefs a simplified version of this template.
44 - \p RCU - one of \ref cds_urcu_gc "RCU type"
45 - \p NodeType - container's node type
46 - \p ValueType - value type stored in container's node. For intrusive containers it is the same as \p NodeType
47 - \p Disposer - a disposer functor
48 - \p Cast - a functor for casting from \p NodeType to \p ValueType. For intrusive containers
49 the casting is usually disabled, i.e. \p Cast is \p void.
56 #ifdef CDS_DOXYGEN_INVOKED
59 typename Cast=details::conventional_exempt_member_cast<NodeType, ValueType>
66 ValueType * operator()( NodeType * p ) const
73 typedef RCU rcu ; ///< RCU type - one of <tt>cds::urcu::gc< ... ></tt>
74 typedef NodeType node_type ; ///< Node type
75 typedef ValueType value_type ; ///< Value type
76 typedef Disposer disposer ; ///< Disposer calling when release
77 /// Functor converting \p node_type to \p value_type
78 typedef typename std::conditional< std::is_same< Cast, void >::value, trivial_cast, Cast>::type node_to_value_cast;
86 /// Constructs empty pointer
87 exempt_ptr() CDS_NOEXCEPT
92 /// Creates exempt pointer for \p pNode. Only for internal use.
93 explicit exempt_ptr( node_type * pNode ) CDS_NOEXCEPT
96 explicit exempt_ptr( std::nullptr_t ) CDS_NOEXCEPT
102 exempt_ptr( exempt_ptr&& p ) CDS_NOEXCEPT
103 : m_pNode( p.m_pNode )
108 /// The exempt pointer is not copy-constructible
109 exempt_ptr( exempt_ptr const& ) = delete;
111 /// Releases the pointer, see \p release()
117 /// Checks if the pointer is \p nullptr
118 bool empty() const CDS_NOEXCEPT
120 return m_pNode == nullptr;
123 /// \p bool operator returns <tt>!empty()</tt>
124 explicit operator bool() const CDS_NOEXCEPT
129 /// Dereference operator
130 value_type * operator->() const CDS_NOEXCEPT
132 return !empty() ? node_to_value_cast()(m_pNode) : nullptr;
135 /// Returns a reference to the value
136 value_type& operator *() CDS_NOEXCEPT
139 return *node_to_value_cast()( m_pNode );
142 /// Move assignment. Can be called only outside of RCU critical section
143 exempt_ptr& operator =( exempt_ptr&& p ) CDS_NOEXCEPT
151 /// The exempt pointer is not copy-assignable
152 exempt_ptr& operator=(exempt_ptr const&) = delete;
154 /// Disposes the pointer. Should be called only outside of RCU critical section
158 assert( !rcu::is_locked() );
159 rcu::template retire_ptr<disposer>( m_pNode );
164 }} // namespace cds::urcu
166 #endif //#ifndef CDSLIB_URCU_EXEMPT_PTR_H