1 | /* |
2 | * Copyright 2018-present Facebook, Inc. |
3 | * |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | * you may not use this file except in compliance with the License. |
6 | * You may obtain a copy of the License at |
7 | * |
8 | * http://www.apache.org/licenses/LICENSE-2.0 |
9 | * |
10 | * Unless required by applicable law or agreed to in writing, software |
11 | * distributed under the License is distributed on an "AS IS" BASIS, |
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. |
15 | */ |
16 | #pragma once |
17 | |
18 | #include <atomic> |
19 | #include <memory> |
20 | |
21 | /// |
22 | /// Forward declatations and implicit documentation of all hazptr |
23 | /// top-level classes, functions, macros, default values, and globals. |
24 | /// |
25 | |
26 | /** FOLYY_HAZPTR_THR_LOCAL */ |
27 | #if FOLLY_MOBILE |
28 | #define FOLLY_HAZPTR_THR_LOCAL false |
29 | #else |
30 | #define FOLLY_HAZPTR_THR_LOCAL true |
31 | #endif |
32 | |
33 | namespace folly { |
34 | |
35 | /// |
36 | /// Hazard pointer record. |
37 | /// Defined in HazptrRec.h |
38 | /// |
39 | |
40 | /** hazptr_rec */ |
41 | template <template <typename> class Atom = std::atomic> |
42 | class hazptr_rec; |
43 | |
44 | /// |
45 | /// Classes related to objects protected by hazard pointers. |
46 | /// Defined in HazptrObj.h |
47 | /// |
48 | |
49 | /** hazptr_obj */ |
50 | template <template <typename> class Atom = std::atomic> |
51 | class hazptr_obj; |
52 | |
53 | /** hazptr_obj_list */ |
54 | template <template <typename> class Atom = std::atomic> |
55 | class hazptr_obj_list; |
56 | |
57 | /** hazptr_obj_batch */ |
58 | template <template <typename> class Atom = std::atomic> |
59 | class hazptr_obj_batch; |
60 | |
61 | /** hazptr_obj_retired_list */ |
62 | template <template <typename> class Atom = std::atomic> |
63 | class hazptr_obj_retired_list; |
64 | |
65 | /** hazptr_deleter */ |
66 | template <typename T, typename D> |
67 | class hazptr_deleter; |
68 | |
69 | /** hazptr_obj_base */ |
70 | template < |
71 | typename T, |
72 | template <typename> class Atom = std::atomic, |
73 | typename D = std::default_delete<T>> |
74 | class hazptr_obj_base; |
75 | |
76 | /// |
77 | /// Classes related to link counted objects and automatic retirement. |
78 | /// Defined in HazptrLinked.h |
79 | /// |
80 | |
81 | /** hazptr_root */ |
82 | template <typename T, template <typename> class Atom = std::atomic> |
83 | class hazptr_root; |
84 | |
85 | /** hazptr_obj_linked */ |
86 | template <template <typename> class Atom = std::atomic> |
87 | class hazptr_obj_linked; |
88 | |
89 | /** hazptr_obj_base_linked */ |
90 | template < |
91 | typename T, |
92 | template <typename> class Atom = std::atomic, |
93 | typename Deleter = std::default_delete<T>> |
94 | class hazptr_obj_base_linked; |
95 | |
96 | /// |
97 | /// Classes and functions related to thread local structures. |
98 | /// Defined in HazptrThrLocal.h |
99 | /// |
100 | |
101 | /** hazptr_tc_entry */ |
102 | template <template <typename> class Atom = std::atomic> |
103 | class hazptr_tc_entry; |
104 | |
105 | /** hazptr_tc */ |
106 | template <template <typename> class Atom = std::atomic> |
107 | class hazptr_tc; |
108 | |
109 | /** hazptr_tc_tls */ |
110 | template <template <typename> class Atom = std::atomic> |
111 | hazptr_tc<Atom>& hazptr_tc_tls(); |
112 | |
113 | /** hazptr_priv */ |
114 | template <template <typename> class Atom = std::atomic> |
115 | class hazptr_priv; |
116 | |
117 | /** hazptr_priv_tls */ |
118 | template <template <typename> class Atom = std::atomic> |
119 | hazptr_priv<Atom>& hazptr_priv_tls(); |
120 | |
121 | /// |
122 | /// Hazard pointer domain |
123 | /// Defined in HazptrDomain.h |
124 | /// |
125 | |
126 | /** hazptr_domain */ |
127 | template <template <typename> class Atom = std::atomic> |
128 | class hazptr_domain; |
129 | |
130 | /** default_hazptr_domain */ |
131 | template <template <typename> class Atom = std::atomic> |
132 | hazptr_domain<Atom>& default_hazptr_domain(); |
133 | |
134 | /** hazptr_domain_push_list */ |
135 | template <template <typename> class Atom = std::atomic> |
136 | void hazptr_domain_push_list( |
137 | hazptr_obj_list<Atom>& l, |
138 | hazptr_domain<Atom>& domain = default_hazptr_domain<Atom>()) noexcept; |
139 | |
140 | /** hazptr_domain_push_retired */ |
141 | template <template <typename> class Atom = std::atomic> |
142 | void hazptr_domain_push_retired( |
143 | hazptr_obj_list<Atom>& l, |
144 | bool check = true, |
145 | hazptr_domain<Atom>& domain = default_hazptr_domain<Atom>()) noexcept; |
146 | |
147 | /** hazptr_retire */ |
148 | template < |
149 | template <typename> class Atom = std::atomic, |
150 | typename T, |
151 | typename D = std::default_delete<T>> |
152 | void hazptr_retire(T* obj, D reclaim = {}); |
153 | |
154 | /** hazptr_cleanup */ |
155 | template <template <typename> class Atom = std::atomic> |
156 | void hazptr_cleanup( |
157 | hazptr_domain<Atom>& domain = default_hazptr_domain<Atom>()) noexcept; |
158 | |
159 | /** hazptr_cleanup_batch_tag */ |
160 | template <template <typename> class Atom = std::atomic> |
161 | void hazptr_cleanup_batch_tag( |
162 | const hazptr_obj_batch<Atom>* batch, |
163 | hazptr_domain<Atom>& domain = default_hazptr_domain<Atom>()) noexcept; |
164 | |
165 | /** Global default domain defined in Hazptr.cpp */ |
166 | extern hazptr_domain<std::atomic> default_domain; |
167 | |
168 | /// |
169 | /// Classes related to hazard pointer holders. |
170 | /// Defined in HazptrHolder.h |
171 | /// |
172 | |
173 | /** hazptr_holder */ |
174 | template <template <typename> class Atom = std::atomic> |
175 | class hazptr_holder; |
176 | |
177 | /** Free function swap of hazptr_holder-s */ |
178 | template <template <typename> class Atom = std::atomic> |
179 | void swap(hazptr_holder<Atom>&, hazptr_holder<Atom>&) noexcept; |
180 | |
181 | /** hazptr_array */ |
182 | template <uint8_t M = 1, template <typename> class Atom = std::atomic> |
183 | class hazptr_array; |
184 | |
185 | /** hazptr_local */ |
186 | template <uint8_t M = 1, template <typename> class Atom = std::atomic> |
187 | class hazptr_local; |
188 | |
189 | } // namespace folly |
190 | |