Replace NULL with nullptr
[libcds.git] / cds / threading / model.h
1 //$$CDS-header$$
2
3 #ifndef __CDS_THREADING_MODEL_H
4 #define __CDS_THREADING_MODEL_H
5
6 #include <cds/threading/details/_common.h>
7 #include <cds/user_setup/threading.h>
8 #include <cds/threading/details/auto_detect.h>
9
10 namespace cds { namespace threading {
11
12     /// Returns thread specific data of \p GC garbage collector
13     template <class GC> typename GC::thread_gc_impl&  getGC();
14
15     /// Returns RCU thread specific data (thread GC) for current thread
16     /**
17         Template argument \p RCUtag is one of \ref cds_urcu_tags "RCU tags"
18     */
19     template <typename RCUtag> cds::urcu::details::thread_data<RCUtag> * getRCU();
20
21     /// Get cds::gc::HP thread GC implementation for current thread
22     /**
23         The object returned may be uninitialized if you did not call attachThread in the beginning of thread execution
24         or if you did not use cds::gc::HP.
25         To initialize cds::gc::HP GC you must constuct cds::gc::HP object in the beginning of your application,
26         see \ref cds_how_to_use "How to use libcds"
27     */
28     template <>
29     inline cds::gc::HP::thread_gc_impl&   getGC<cds::gc::HP>()
30     {
31         return Manager::getHZPGC();
32     }
33
34     /// Get cds::gc::HRC thread GC implementation for current thread
35     /**
36         The object returned may be uninitialized if you did not call attachThread in the beginning of thread execution
37         or if you did not use cds::gc::HRC.
38         To initialize cds::gc::HRC GC you must constuct cds::gc::HRC object in the beginning of your application,
39         see \ref cds_how_to_use "How to use libcds"
40     */
41     template <>
42     inline cds::gc::HRC::thread_gc_impl&   getGC<cds::gc::HRC>()
43     {
44         return Manager::getHRCGC();
45     }
46
47     /// Get cds::gc::PTB thread GC implementation for current thread
48     /**
49         The object returned may be uninitialized if you did not call attachThread in the beginning of thread execution
50         or if you did not use cds::gc::PTB.
51         To initialize cds::gc::PTB GC you must constuct cds::gc::PTB object in the beginning of your application,
52         see \ref cds_how_to_use "How to use libcds"
53     */
54     template <>
55     inline cds::gc::PTB::thread_gc_impl&   getGC<cds::gc::PTB>()
56     {
57         return Manager::getPTBGC();
58     }
59
60     //@cond
61     template<>
62     inline cds::urcu::details::thread_data<cds::urcu::general_instant_tag> * getRCU<cds::urcu::general_instant_tag>()
63     {
64         return Manager::thread_data()->m_pGPIRCU;
65     }
66     template<>
67     inline cds::urcu::details::thread_data<cds::urcu::general_buffered_tag> * getRCU<cds::urcu::general_buffered_tag>()
68     {
69         return Manager::thread_data()->m_pGPBRCU;
70     }
71     template<>
72     inline cds::urcu::details::thread_data<cds::urcu::general_threaded_tag> * getRCU<cds::urcu::general_threaded_tag>()
73     {
74         return Manager::thread_data()->m_pGPTRCU;
75     }
76 #ifdef CDS_URCU_SIGNAL_HANDLING_ENABLED
77     template<>
78     inline cds::urcu::details::thread_data<cds::urcu::signal_buffered_tag> * getRCU<cds::urcu::signal_buffered_tag>()
79     {
80         ThreadData * p = Manager::thread_data();
81         return p ? p->m_pSHBRCU : nullptr;
82     }
83     template<>
84     inline cds::urcu::details::thread_data<cds::urcu::signal_threaded_tag> * getRCU<cds::urcu::signal_threaded_tag>()
85     {
86         ThreadData * p = Manager::thread_data();
87         return p ? p->m_pSHTRCU : nullptr;
88     }
89 #endif
90
91     static inline cds::algo::elimination::record& elimination_record()
92     {
93         return Manager::thread_data()->m_EliminationRec;
94     }
95     //@endcond
96
97 }} // namespace cds::threading
98
99 #endif // #ifndef __CDS_THREADING_MODEL_H