issue#11: cds: changed __CDS_ guard prefix to CDSLIB_ for all .h files
[libcds.git] / cds / gc / impl / hp_impl.h
1 //$$CDS-header$$
2
3 #ifndef CDSLIB_GC_IMPL_HP_IMPL_H
4 #define CDSLIB_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     namespace hp {
13         inline guard::guard()
14             : m_hp( cds::threading::getGC<HP>().allocGuard() )
15         {}
16
17         template <typename T>
18         inline guard::guard( T * p )
19             : m_hp( cds::threading::getGC<HP>().allocGuard() )
20         {
21             m_hp = p;
22         }
23
24         inline guard::~guard()
25         {
26             cds::threading::getGC<HP>().freeGuard( m_hp );
27         }
28
29         template <size_t Count>
30         inline array<Count>::array()
31         {
32             cds::threading::getGC<HP>().allocGuard( *this );
33         }
34
35         template <size_t Count>
36         inline array<Count>::~array()
37         {
38             cds::threading::getGC<HP>().freeGuard( *this );
39         }
40
41
42
43     } // namespace hp
44
45     inline HP::thread_gc::thread_gc(
46         bool    bPersistent
47         )
48         : m_bPersistent( bPersistent )
49     {
50         if ( !threading::Manager::isThreadAttached() )
51             threading::Manager::attachThread();
52     }
53
54     inline HP::thread_gc::~thread_gc()
55     {
56         if ( !m_bPersistent )
57             cds::threading::Manager::detachThread();
58     }
59
60     inline /*static*/ cds::gc::hp::details::hp_guard& HP::thread_gc::alloc_guard()
61     {
62         return cds::threading::getGC<HP>().allocGuard();
63     }
64
65     inline /*static*/ void HP::thread_gc::free_guard( cds::gc::hp::details::hp_guard& g )
66     {
67         cds::threading::getGC<HP>().freeGuard( g );
68     }
69
70     template <typename T>
71     inline void HP::retire( T * p, void (* pFunc)(T *) )
72     {
73         cds::threading::getGC<HP>().retirePtr( p, pFunc );
74     }
75
76     template <class Disposer, typename T>
77     inline void HP::retire( T * p )
78     {
79         cds::threading::getGC<HP>().retirePtr( p, cds::details::static_functor<Disposer, T>::call );
80     }
81
82     inline void HP::scan()
83     {
84         cds::threading::getGC<HP>().scan();
85     }
86
87 }} // namespace cds::gc
88 //@endcond
89
90 #endif // #ifndef CDSLIB_GC_IMPL_HP_IMPL_H