reimplement guarded_ptr from scratch
[libcds.git] / cds / gc / impl / dhp_impl.h
1 //$$CDS-header$$
2
3 #ifndef __CDS_GC_IMPL_DHP_IMPL_H
4 #define __CDS_GC_IMPL_DHP_IMPL_H
5
6 #include <cds/threading/model.h>
7
8 //@cond
9 namespace cds { namespace gc {
10
11     inline DHP::thread_gc::thread_gc(
12         bool    bPersistent
13         )
14         : m_bPersistent( bPersistent )
15     {
16         if ( !cds::threading::Manager::isThreadAttached() )
17             cds::threading::Manager::attachThread();
18     }
19
20     inline DHP::thread_gc::~thread_gc()
21     {
22         if ( !m_bPersistent )
23             cds::threading::Manager::detachThread();
24     }
25
26     inline /*static*/ void DHP::thread_gc::alloc_guard( cds::gc::dhp::details::guard& g )
27     {
28         return cds::threading::getGC<DHP>().allocGuard(g);
29     }
30     inline /*static*/ void DHP::thread_gc::free_guard( cds::gc::dhp::details::guard& g )
31     {
32         cds::threading::getGC<DHP>().freeGuard(g);
33     }
34
35     inline DHP::Guard::Guard()
36         : Guard::base_class( cds::threading::getGC<DHP>() )
37     {}
38
39     template <size_t Count>
40     inline DHP::GuardArray<Count>::GuardArray()
41         : GuardArray::base_class( cds::threading::getGC<DHP>() )
42     {}
43
44     inline void DHP::scan()
45     {
46         cds::threading::getGC<DHP>().scan();
47     }
48
49 }} // namespace cds::gc
50 //@endcond
51
52 #endif // #ifndef __CDS_GC_IMPL_DHP_IMPL_H