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
33namespace folly {
34
35///
36/// Hazard pointer record.
37/// Defined in HazptrRec.h
38///
39
40/** hazptr_rec */
41template <template <typename> class Atom = std::atomic>
42class hazptr_rec;
43
44///
45/// Classes related to objects protected by hazard pointers.
46/// Defined in HazptrObj.h
47///
48
49/** hazptr_obj */
50template <template <typename> class Atom = std::atomic>
51class hazptr_obj;
52
53/** hazptr_obj_list */
54template <template <typename> class Atom = std::atomic>
55class hazptr_obj_list;
56
57/** hazptr_obj_batch */
58template <template <typename> class Atom = std::atomic>
59class hazptr_obj_batch;
60
61/** hazptr_obj_retired_list */
62template <template <typename> class Atom = std::atomic>
63class hazptr_obj_retired_list;
64
65/** hazptr_deleter */
66template <typename T, typename D>
67class hazptr_deleter;
68
69/** hazptr_obj_base */
70template <
71 typename T,
72 template <typename> class Atom = std::atomic,
73 typename D = std::default_delete<T>>
74class 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 */
82template <typename T, template <typename> class Atom = std::atomic>
83class hazptr_root;
84
85/** hazptr_obj_linked */
86template <template <typename> class Atom = std::atomic>
87class hazptr_obj_linked;
88
89/** hazptr_obj_base_linked */
90template <
91 typename T,
92 template <typename> class Atom = std::atomic,
93 typename Deleter = std::default_delete<T>>
94class 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 */
102template <template <typename> class Atom = std::atomic>
103class hazptr_tc_entry;
104
105/** hazptr_tc */
106template <template <typename> class Atom = std::atomic>
107class hazptr_tc;
108
109/** hazptr_tc_tls */
110template <template <typename> class Atom = std::atomic>
111hazptr_tc<Atom>& hazptr_tc_tls();
112
113/** hazptr_priv */
114template <template <typename> class Atom = std::atomic>
115class hazptr_priv;
116
117/** hazptr_priv_tls */
118template <template <typename> class Atom = std::atomic>
119hazptr_priv<Atom>& hazptr_priv_tls();
120
121///
122/// Hazard pointer domain
123/// Defined in HazptrDomain.h
124///
125
126/** hazptr_domain */
127template <template <typename> class Atom = std::atomic>
128class hazptr_domain;
129
130/** default_hazptr_domain */
131template <template <typename> class Atom = std::atomic>
132hazptr_domain<Atom>& default_hazptr_domain();
133
134/** hazptr_domain_push_list */
135template <template <typename> class Atom = std::atomic>
136void 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 */
141template <template <typename> class Atom = std::atomic>
142void 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 */
148template <
149 template <typename> class Atom = std::atomic,
150 typename T,
151 typename D = std::default_delete<T>>
152void hazptr_retire(T* obj, D reclaim = {});
153
154/** hazptr_cleanup */
155template <template <typename> class Atom = std::atomic>
156void hazptr_cleanup(
157 hazptr_domain<Atom>& domain = default_hazptr_domain<Atom>()) noexcept;
158
159/** hazptr_cleanup_batch_tag */
160template <template <typename> class Atom = std::atomic>
161void 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 */
166extern 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 */
174template <template <typename> class Atom = std::atomic>
175class hazptr_holder;
176
177/** Free function swap of hazptr_holder-s */
178template <template <typename> class Atom = std::atomic>
179void swap(hazptr_holder<Atom>&, hazptr_holder<Atom>&) noexcept;
180
181/** hazptr_array */
182template <uint8_t M = 1, template <typename> class Atom = std::atomic>
183class hazptr_array;
184
185/** hazptr_local */
186template <uint8_t M = 1, template <typename> class Atom = std::atomic>
187class hazptr_local;
188
189} // namespace folly
190