reimplement guarded_ptr from scratch
[libcds.git] / cds / gc / impl / hp_impl.h
1 //$$CDS-header$$
2
3 #ifndef __CDS_GC_IMPL_HP_IMPL_H
4 #define __CDS_GC_IMPL_HP_IMPL_H
5
6 #include <cds/threading/model.h>
7 #include <cds/details/static_functor.h>
8
9 //@cond
10 namespace cds { namespace gc {
11
12     inline HP::thread_gc::thread_gc(
13         bool    bPersistent
14         )
15         : m_bPersistent( bPersistent )
16     {
17         if ( !threading::Manager::isThreadAttached() )
18             threading::Manager::attachThread();
19     }
20
21     inline HP::thread_gc::~thread_gc()
22     {
23         if ( !m_bPersistent )
24             cds::threading::Manager::detachThread();
25     }
26
27     inline /*static*/ cds::gc::hp::details::hp_guard& HP::thread_gc::alloc_guard()
28     {
29         return cds::threading::getGC<HP>().allocGuard();
30     }
31
32     inline /*static*/ void HP::thread_gc::free_guard( cds::gc::hp::details::hp_guard& g )
33     {
34         cds::threading::getGC<HP>().freeGuard( g );
35     }
36
37     inline HP::Guard::Guard()
38         : Guard::base_class( cds::threading::getGC<HP>() )
39     {}
40
41     template <size_t COUNT>
42     inline HP::GuardArray<COUNT>::GuardArray()
43         : GuardArray::base_class( cds::threading::getGC<HP>() )
44     {}
45
46     template <typename T>
47     inline void HP::retire( T * p, void (* pFunc)(T *) )
48     {
49         cds::threading::getGC<HP>().retirePtr( p, pFunc );
50     }
51
52     template <class Disposer, typename T>
53     inline void HP::retire( T * p )
54     {
55         cds::threading::getGC<HP>().retirePtr( p, cds::details::static_functor<Disposer, T>::call );
56     }
57
58     inline void HP::scan()
59     {
60         cds::threading::getGC<HP>().scan();
61     }
62
63 }} // namespace cds::gc
64 //@endcond
65
66 #endif // #ifndef __CDS_GC_IMPL_HP_IMPL_H