3 #ifndef CDSLIB_GC_DETAILS_RETIRED_PTR_H
4 #define CDSLIB_GC_DETAILS_RETIRED_PTR_H
6 #include <cds/details/defs.h>
7 #include <cds/details/static_functor.h>
10 namespace cds { namespace gc {
11 /// Common implementation details for any GC
14 /// Pointer to function to free (destruct and deallocate) retired pointer of specific type
15 typedef void (* free_retired_ptr_func )( void * );
19 Pointer to an object that is ready to delete.
23 typedef void * pointer;
26 pointer m_p; ///< retired pointer
29 free_retired_ptr_func m_funcFree; ///< pointer to the destructor function
31 /// Comparison of two retired pointers
32 static bool less( const retired_ptr& p1, const retired_ptr& p2 ) CDS_NOEXCEPT
34 return p1.m_p < p2.m_p;
37 /// Default ctor initializes pointer to \p nullptr
38 retired_ptr() CDS_NOEXCEPT
40 , m_funcFree( nullptr )
44 retired_ptr( pointer p, free_retired_ptr_func func ) CDS_NOEXCEPT
51 retired_ptr( T * p, void (* pFreeFunc)(T *)) CDS_NOEXCEPT
52 : m_p( reinterpret_cast<pointer>(p))
53 , m_funcFree( reinterpret_cast< free_retired_ptr_func >( pFreeFunc ))
56 /// Assignment operator
57 retired_ptr& operator =( retired_ptr const& s) CDS_NOEXCEPT
60 m_funcFree = s.m_funcFree;
64 /// Invokes destructor function for the pointer
71 CDS_STRICT_DO( m_p = nullptr );
72 CDS_STRICT_DO( m_funcFree = nullptr );
76 static inline bool operator <( const retired_ptr& p1, const retired_ptr& p2 ) CDS_NOEXCEPT
78 return retired_ptr::less( p1, p2 );
81 static inline bool operator ==( const retired_ptr& p1, const retired_ptr& p2 ) CDS_NOEXCEPT
83 return p1.m_p == p2.m_p;
86 static inline bool operator !=( const retired_ptr& p1, const retired_ptr& p2 ) CDS_NOEXCEPT
90 } // namespace details
92 template <typename Func, typename T>
93 static inline cds::gc::details::retired_ptr make_retired_ptr( T * p )
95 return cds::gc::details::retired_ptr( p, cds::details::static_functor<Func, T>::call );
98 }} // namespace cds::gc
101 #endif // #ifndef CDSLIB_GC_DETAILS_RETIRED_PTR_H