Added copyright and license
[libcds.git] / cds / threading / model.h
1 /*
2     This file is a part of libcds - Concurrent Data Structures library
3
4     (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2016
5
6     Source code repo: http://github.com/khizmax/libcds/
7     Download: http://sourceforge.net/projects/libcds/files/
8     
9     Redistribution and use in source and binary forms, with or without
10     modification, are permitted provided that the following conditions are met:
11
12     * Redistributions of source code must retain the above copyright notice, this
13       list of conditions and the following disclaimer.
14
15     * Redistributions in binary form must reproduce the above copyright notice,
16       this list of conditions and the following disclaimer in the documentation
17       and/or other materials provided with the distribution.
18
19     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20     AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21     IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22     DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23     FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24     DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25     SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26     CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27     OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28     OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.     
29 */
30
31 #ifndef CDSLIB_THREADING_MODEL_H
32 #define CDSLIB_THREADING_MODEL_H
33
34 #include <cds/threading/details/_common.h>
35 #include <cds/user_setup/threading.h>
36 #include <cds/threading/details/auto_detect.h>
37
38 namespace cds { namespace threading {
39
40     /// Returns thread specific data of \p GC garbage collector
41     template <class GC> typename GC::thread_gc_impl&  getGC();
42
43     /// Returns RCU thread specific data (thread GC) for current thread
44     /**
45         Template argument \p RCUtag is one of \ref cds_urcu_tags "RCU tags"
46     */
47     template <typename RCUtag> cds::urcu::details::thread_data<RCUtag> * getRCU();
48
49     /// Get cds::gc::HP thread GC implementation for current thread
50     /**
51         The object returned may be uninitialized if you did not call attachThread in the beginning of thread execution
52         or if you did not use cds::gc::HP.
53         To initialize cds::gc::HP GC you must constuct cds::gc::HP object in the beginning of your application,
54         see \ref cds_how_to_use "How to use libcds"
55     */
56     template <>
57     inline cds::gc::HP::thread_gc_impl&   getGC<cds::gc::HP>()
58     {
59         return Manager::getHZPGC();
60     }
61
62     /// Get cds::gc::DHP thread GC implementation for current thread
63     /**
64         The object returned may be uninitialized if you did not call attachThread in the beginning of thread execution
65         or if you did not use cds::gc::DHP.
66         To initialize cds::gc::DHP GC you must constuct cds::gc::DHP object in the beginning of your application,
67         see \ref cds_how_to_use "How to use libcds"
68     */
69     template <>
70     inline cds::gc::DHP::thread_gc_impl&   getGC<cds::gc::DHP>()
71     {
72         return Manager::getDHPGC();
73     }
74
75     //@cond
76     template<>
77     inline cds::urcu::details::thread_data<cds::urcu::general_instant_tag> * getRCU<cds::urcu::general_instant_tag>()
78     {
79         return Manager::thread_data()->m_pGPIRCU;
80     }
81     template<>
82     inline cds::urcu::details::thread_data<cds::urcu::general_buffered_tag> * getRCU<cds::urcu::general_buffered_tag>()
83     {
84         return Manager::thread_data()->m_pGPBRCU;
85     }
86     template<>
87     inline cds::urcu::details::thread_data<cds::urcu::general_threaded_tag> * getRCU<cds::urcu::general_threaded_tag>()
88     {
89         return Manager::thread_data()->m_pGPTRCU;
90     }
91 #ifdef CDS_URCU_SIGNAL_HANDLING_ENABLED
92     template<>
93     inline cds::urcu::details::thread_data<cds::urcu::signal_buffered_tag> * getRCU<cds::urcu::signal_buffered_tag>()
94     {
95         ThreadData * p = Manager::thread_data();
96         return p ? p->m_pSHBRCU : nullptr;
97     }
98     template<>
99     inline cds::urcu::details::thread_data<cds::urcu::signal_threaded_tag> * getRCU<cds::urcu::signal_threaded_tag>()
100     {
101         ThreadData * p = Manager::thread_data();
102         return p ? p->m_pSHTRCU : nullptr;
103     }
104 #endif
105
106     static inline cds::algo::elimination::record& elimination_record()
107     {
108         return Manager::thread_data()->m_EliminationRec;
109     }
110     //@endcond
111
112 }} // namespace cds::threading
113
114 #endif // #ifndef CDSLIB_THREADING_MODEL_H