{
typedef details::guard base_class;
friend class ThreadGC;
-
- ThreadGC& m_gc ; ///< ThreadGC object of current thread
public:
/// Allocates a guard from \p gc GC. \p gc must be ThreadGC object of current thread
- Guard( ThreadGC& gc );
+ Guard(); // inline in dhp_impl.h
/// Returns guard allocated back to pool of free guards
- ~Guard(); // inline after GarbageCollector
-
- /// Returns DHP GC object
- ThreadGC& getGC() CDS_NOEXCEPT
- {
- return m_gc;
- }
+ ~Guard(); // inline in dhp_impl.h
/// Guards pointer \p p
template <typename T>
class GuardArray
{
details::guard m_arr[Count] ; ///< array of guard
- ThreadGC& m_gc ; ///< ThreadGC object of current thread
const static size_t c_nCapacity = Count ; ///< Array capacity (equal to \p Count template parameter)
public:
public:
/// Allocates array of guards from \p gc which must be the ThreadGC object of current thread
- GuardArray( ThreadGC& gc ); // inline below
-
- /// The object is not default-constructible
- GuardArray() = delete;
+ GuardArray(); // inline in dhp_impl.h
/// The object is not copy-constructible
GuardArray( GuardArray const& ) = delete;
+ /// The object is not move-constructible
+ GuardArray( GuardArray&& ) = delete;
+
/// Returns guards allocated back to pool
- ~GuardArray(); // inline below
+ ~GuardArray(); // inline in dh_impl.h
/// Returns the capacity of array
CDS_CONSTEXPR size_t capacity() const CDS_NOEXCEPT
return c_nCapacity;
}
- /// Returns DHP ThreadGC object
- ThreadGC& getGC() CDS_NOEXCEPT
- {
- return m_gc;
- }
-
/// Returns reference to the guard of index \p nIndex (0 <= \p nIndex < \p Count)
details::guard& operator []( size_t nIndex ) CDS_NOEXCEPT
{
m_gc.scan();
}
};
-
- //////////////////////////////////////////////////////////
- // Inlines
-
- inline Guard::Guard(ThreadGC& gc)
- : m_gc( gc )
- {
- getGC().allocGuard( *this );
- }
- inline Guard::~Guard()
- {
- getGC().freeGuard( *this );
- }
-
- template <size_t Count>
- inline GuardArray<Count>::GuardArray( ThreadGC& gc )
- : m_gc( gc )
- {
- getGC().allocGuard( *this );
- }
- template <size_t Count>
- inline GuardArray<Count>::~GuardArray()
- {
- getGC().freeGuard( *this );
- }
-
} // namespace dhp
}} // namespace cds::gc
//@endcond
class guard
{
details::hp_guard& m_hp ; ///< Hazard pointer guarded
- ThreadGC& m_gc ; ///< Thread GC
public:
typedef details::hp_guard::hazard_ptr hazard_ptr ; ///< Hazard pointer type
public:
- /// Allocates HP guard from \p gc
- guard( ThreadGC& gc )
- : m_hp( gc.allocGuard() )
- , m_gc( gc )
- {}
+ /// Allocates HP guard
+ guard(); // inline in hp_impl.h
/// Allocates HP guard from \p gc and protects the pointer \p p of type \p T
template <typename T>
- guard( ThreadGC& gc, T * p )
- : m_hp( gc.allocGuard() )
- , m_gc( gc )
- {
- m_hp = p;
- }
+ explicit guard( T * p ); // inline in hp_impl.h
/// Frees HP guard. The pointer guarded may be deleted after this.
- ~guard()
- {
- m_gc.freeGuard( m_hp );
- }
-
- /// Returns thread GC
- ThreadGC& getGC() const
- {
- return m_gc;
- }
+ ~guard(); // inline in hp_impl.h
/// Protects the pointer \p p against reclamation (guards the pointer).
template <typename T>
template <size_t Count>
class array : public details::hp_array<Count>
{
- ThreadGC& m_mgr ; ///< Thread GC
-
public:
/// Rebind array for other size \p COUNT2
template <size_t Count2>
};
public:
- /// Allocates array of HP guard from \p mgr
- array( ThreadGC& mgr )
- : m_mgr( mgr )
- {
- mgr.allocGuard( *this );
- }
+ /// Allocates array of HP guard
+ array(); // inline in hp_impl.h
/// Frees array of HP guard
- ~array()
- {
- m_mgr.freeGuard( *this );
- }
-
- /// Returns thread GC
- ThreadGC& getGC() const { return m_mgr; }
+ ~array(); //inline in hp_impl.h
};
} // namespace hp
public:
// Default ctor
- Guard(); // inline in dhp_impl.h
+ Guard()
+ {}
//@cond
Guard( Guard const& ) = delete;
public:
// Default ctor
- GuardArray(); // inline in dhp_impl.h
+ GuardArray()
+ {}
//@cond
GuardArray( GuardArray const& ) = delete;
//@cond
namespace cds { namespace gc {
+ namespace dhp {
+
+ inline Guard::Guard()
+ {
+ cds::threading::getGC<DHP>().allocGuard( *this );
+ }
+
+ inline Guard::~Guard()
+ {
+ cds::threading::getGC<DHP>().freeGuard( *this );
+ }
+
+ template <size_t Count>
+ inline GuardArray<Count>::GuardArray()
+ {
+ cds::threading::getGC<DHP>().allocGuard( *this );
+ }
+
+ template <size_t Count>
+ inline GuardArray<Count>::~GuardArray()
+ {
+ cds::threading::getGC<DHP>().freeGuard( *this );
+ }
+ } // namespace dhp
+
+
inline DHP::thread_gc::thread_gc(
bool bPersistent
)
cds::threading::getGC<DHP>().freeGuard(g);
}
- inline DHP::Guard::Guard()
- : Guard::base_class( cds::threading::getGC<DHP>() )
- {}
-
- template <size_t Count>
- inline DHP::GuardArray<Count>::GuardArray()
- : GuardArray::base_class( cds::threading::getGC<DHP>() )
- {}
-
inline void DHP::scan()
{
cds::threading::getGC<DHP>().scan();
public:
/// Default ctor
- Guard(); // inline in hp_impl.h
+ Guard()
+ {}
//@cond
Guard( Guard const& ) = delete;
public:
/// Default ctor
- GuardArray(); // inline in hp_impl.h
+ GuardArray()
+ {}
//@cond
GuardArray( GuardArray const& ) = delete;
//@cond
namespace cds { namespace gc {
+ namespace hp {
+ inline guard::guard()
+ : m_hp( cds::threading::getGC<HP>().allocGuard() )
+ {}
+
+ template <typename T>
+ inline guard::guard( T * p )
+ : m_hp( cds::threading::getGC<HP>().allocGuard() )
+ {
+ m_hp = p;
+ }
+
+ inline guard::~guard()
+ {
+ cds::threading::getGC<HP>().freeGuard( m_hp );
+ }
+
+ template <size_t Count>
+ inline array<Count>::array()
+ {
+ cds::threading::getGC<HP>().allocGuard( *this );
+ }
+
+ template <size_t Count>
+ inline array<Count>::~array()
+ {
+ cds::threading::getGC<HP>().freeGuard( *this );
+ }
+
+
+
+ } // namespace hp
+
inline HP::thread_gc::thread_gc(
bool bPersistent
)
cds::threading::getGC<HP>().freeGuard( g );
}
- inline HP::Guard::Guard()
- : Guard::base_class( cds::threading::getGC<HP>() )
- {}
-
- template <size_t COUNT>
- inline HP::GuardArray<COUNT>::GuardArray()
- : GuardArray::base_class( cds::threading::getGC<HP>() )
- {}
-
template <typename T>
inline void HP::retire( T * p, void (* pFunc)(T *) )
{