mn_atomic_primary_types.hpp
Go to the documentation of this file.
1 // *** ADDED BY HEADER FIXUP ***
2 #include <cstdlib>
3 // *** END ***
4 /*
5 *This file is part of the Mini Thread Library (https://github.com/RoseLeBlood/MiniThread ).
6 *Copyright (c) 2021 Amber-Sophia Schroeck
7 *
8 *The Mini Thread Library is free software; you can redistribute it and/or modify
9 *it under the terms of the GNU Lesser General Public License as published by
10 *the Free Software Foundation, version 3, or (at your option) any later version.
11 
12 *The Mini Thread Library is distributed in the hope that it will be useful, but
13 *WITHOUT ANY WARRANTY; without even the implied warranty of
14 *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 *General Public License for more details.
16 *
17 *You should have received a copy of the GNU Lesser General Public
18 *License along with the Mini Thread Library; if not, see
19 *<https://www.gnu.org/licenses/>;.
20 */
21 #ifndef _MINLIB_5ac13f75_2f13_4bb7_acae_7b8f27f78e20_H_
22 #define _MINLIB_5ac13f75_2f13_4bb7_acae_7b8f27f78e20_H_
23 
24 #if defined(__GNUC__) || defined(__clang__) || defined(__xlc__)
25  #include "mn_atomic_gcc.hpp"
26  #define BASE_ATOMIC_TYPE mn::basic_atomic_gcc
27  #define BASE_ATOMIC_SMART_POINTER mn::basic_smart_pointer_atomic_gcc
28 
29  #undef ATOMIC_VAR_INIT
30  #define ATOMIC_VAR_INIT(value) { .__tValue = (value) }
31  #define atomic_init(obj, value) ((void)((obj)->__tValue = (value)))
32  #define ATOMIC_FLAG_INIT { 0 }
33 #else
34 #error Unsupported compiler / system.
35 #endif
36 
37 
38 namespace mn {
42  template <typename T>
43  struct _atomic : BASE_ATOMIC_TYPE<T> {
44  using base_type = BASE_ATOMIC_TYPE<T>;
46  using value_type = typename base_type::value_type;
47  using difference_type = typename base_type::value_type;
48  };
49 
50 
54  template<>
55  struct _atomic<bool> : BASE_ATOMIC_TYPE<bool> {
56  static constexpr bool is_always_lock_free = ATOMIC_BOOL_LOCK_FREE == 2;
57 
58  using base_type = BASE_ATOMIC_TYPE<bool> ;
60  using value_type = typename base_type::value_type;
61  using difference_type = typename base_type::difference_type;;
62 
63  _atomic(const self_type&) = delete;
64  _atomic& operator=(const self_type&) = delete;
65  _atomic& operator=(const self_type&) volatile = delete;
66 
67  constexpr _atomic(value_type value) : base_type(value) { }
68 
69  using base_type::operator value_type;
70  using base_type::operator=;
71  };
72 
76  template<>
77  struct _atomic<char> : BASE_ATOMIC_TYPE<char> {
78  static constexpr bool is_always_lock_free = ATOMIC_CHAR_LOCK_FREE == 2;
79 
80  using base_type = BASE_ATOMIC_TYPE<char> ;
82  using value_type = typename base_type::value_type;
83  using difference_type = typename base_type::difference_type;;
84 
85  _atomic(const self_type&) = delete;
86  _atomic& operator=(const self_type&) = delete;
87  _atomic& operator=(const self_type&) volatile = delete;
88 
89  constexpr _atomic(value_type value) : base_type(value) { }
90 
91  using base_type::operator value_type;
92  using base_type::operator=;
93  };
94 
98  template<>
99  struct _atomic<signed char> : BASE_ATOMIC_TYPE<signed char> {
100  static constexpr bool is_always_lock_free = ATOMIC_CHAR_LOCK_FREE == 2;
101 
102  using base_type = BASE_ATOMIC_TYPE<signed char> ;
104  using value_type = typename base_type::value_type;
105  using difference_type = typename base_type::difference_type;;
106 
107  _atomic(const self_type&) = delete;
108  _atomic& operator=(const self_type&) = delete;
109  _atomic& operator=(const self_type&) volatile = delete;
110 
111  constexpr _atomic(value_type value) : base_type(value) { }
112 
113  using base_type::operator value_type;
114  using base_type::operator=;
115  };
116 
120  template<>
121  struct _atomic<short> : BASE_ATOMIC_TYPE<short> {
122  static constexpr bool is_always_lock_free = ATOMIC_SHORT_LOCK_FREE == 2;
123 
124  using base_type = BASE_ATOMIC_TYPE<short> ;
126  using value_type = typename base_type::value_type;
127  using difference_type = typename base_type::difference_type;;
128 
129  _atomic(const self_type&) = delete;
130  _atomic& operator=(const self_type&) = delete;
131  _atomic& operator=(const self_type&) volatile = delete;
132 
133  constexpr _atomic(value_type value) : base_type(value) { }
134 
135  using base_type::operator value_type;
136  using base_type::operator=;
137  };
138 
142  template<>
143  struct _atomic<int> : BASE_ATOMIC_TYPE<int> {
144  static constexpr bool is_always_lock_free = ATOMIC_INT_LOCK_FREE == 2;
145 
146  using base_type = BASE_ATOMIC_TYPE<int> ;
148  using value_type = typename base_type::value_type;
149  using difference_type = typename base_type::difference_type;;
150 
151  _atomic(const self_type&) = delete;
152  _atomic& operator=(const self_type&) = delete;
153  _atomic& operator=(const self_type&) volatile = delete;
154 
155  constexpr _atomic(value_type value) : base_type(value) { }
156 
157  using base_type::operator value_type;
158  using base_type::operator=;
159  };
160 
164  template<>
165  struct _atomic<long> : BASE_ATOMIC_TYPE<long> {
166  static constexpr bool is_always_lock_free = ATOMIC_LONG_LOCK_FREE == 2;
167 
168  using base_type = BASE_ATOMIC_TYPE<long> ;
170  using value_type = typename base_type::value_type;
171  using difference_type = typename base_type::difference_type;;
172 
173  _atomic(const self_type&) = delete;
174  _atomic& operator=(const self_type&) = delete;
175  _atomic& operator=(const self_type&) volatile = delete;
176 
177  constexpr _atomic(value_type value) : base_type(value) { }
178 
179  using base_type::operator value_type;
180  using base_type::operator=;
181  };
182 
186  template<>
187  struct _atomic<long long> : BASE_ATOMIC_TYPE<long long> {
188  static constexpr bool is_always_lock_free = ATOMIC_LONG_LOCK_FREE == 2;
189 
190  using base_type = BASE_ATOMIC_TYPE<long long> ;
192  using value_type = typename base_type::value_type;
193  using difference_type = typename base_type::difference_type;;
194 
195  _atomic(const self_type&) = delete;
196  _atomic& operator=(const self_type&) = delete;
197  _atomic& operator=(const self_type&) volatile = delete;
198 
199  constexpr _atomic(value_type value) : base_type(value) { }
200 
201  using base_type::operator value_type;
202  using base_type::operator=;
203  };
204 
205  //----------------
209  template<>
210  struct _atomic<unsigned char> : BASE_ATOMIC_TYPE<unsigned char> {
211  static constexpr bool is_always_lock_free = ATOMIC_CHAR_LOCK_FREE == 2;
212 
213  using base_type = BASE_ATOMIC_TYPE<unsigned char> ;
215  using value_type = typename base_type::value_type;
216  using difference_type = typename base_type::difference_type;;
217 
218  _atomic(const self_type&) = delete;
219  _atomic& operator=(const self_type&) = delete;
220  _atomic& operator=(const self_type&) volatile = delete;
221 
222  constexpr _atomic(value_type value) : base_type(value) { }
223 
224  using base_type::operator value_type;
225  using base_type::operator=;
226  };
227 
231  template<>
232  struct _atomic<unsigned short> : BASE_ATOMIC_TYPE<unsigned short> {
233  static constexpr bool is_always_lock_free = ATOMIC_SHORT_LOCK_FREE == 2;
234 
235  using base_type = BASE_ATOMIC_TYPE<unsigned short> ;
237  using value_type = typename base_type::value_type;
238  using difference_type = typename base_type::difference_type;;
239 
240  _atomic(const self_type&) = delete;
241  _atomic& operator=(const self_type&) = delete;
242  _atomic& operator=(const self_type&) volatile = delete;
243 
244  constexpr _atomic(value_type value) : base_type(value) { }
245 
246  using base_type::operator value_type;
247  using base_type::operator=;
248  };
249 
253  template<>
254  struct _atomic<unsigned int> : BASE_ATOMIC_TYPE<unsigned int> {
255  static constexpr bool is_always_lock_free = ATOMIC_INT_LOCK_FREE == 2;
256 
257  using base_type = BASE_ATOMIC_TYPE<unsigned int> ;
259  using value_type = typename base_type::value_type;
260  using difference_type = typename base_type::difference_type;;
261 
262  _atomic(const self_type&) = delete;
263  _atomic& operator=(const self_type&) = delete;
264  _atomic& operator=(const self_type&) volatile = delete;
265 
266  constexpr _atomic(value_type value) : base_type(value) { }
267 
268  using base_type::operator value_type;
269  using base_type::operator=;
270  };
271 
275  template<>
276  struct _atomic<unsigned long> : BASE_ATOMIC_TYPE<unsigned long> {
277  static constexpr bool is_always_lock_free = ATOMIC_LONG_LOCK_FREE == 2;
278 
279  using base_type = BASE_ATOMIC_TYPE<unsigned long> ;
281  using value_type = typename base_type::value_type;
282  using difference_type = typename base_type::difference_type;;
283 
284  _atomic(const self_type&) = delete;
285  _atomic& operator=(const self_type&) = delete;
286  _atomic& operator=(const self_type&) volatile = delete;
287 
288  constexpr _atomic(value_type value) : base_type(value) { }
289 
290  using base_type::operator value_type;
291  using base_type::operator=;
292  };
293 
297  template<>
298  struct _atomic<char16_t> : BASE_ATOMIC_TYPE<char16_t> {
299  static constexpr bool is_always_lock_free = ATOMIC_CHAR16_T_LOCK_FREE == 2;
300 
301  using base_type = BASE_ATOMIC_TYPE<char16_t> ;
303  using value_type = typename base_type::value_type;
304  using difference_type = typename base_type::difference_type;;
305 
306  _atomic(const self_type&) = delete;
307  _atomic& operator=(const self_type&) = delete;
308  _atomic& operator=(const self_type&) volatile = delete;
309 
310  constexpr _atomic(value_type value) : base_type(value) { }
311 
312  using base_type::operator value_type;
313  using base_type::operator=;
314  };
315 
319  template<>
320  struct _atomic<char32_t> : BASE_ATOMIC_TYPE<char32_t> {
321  static constexpr bool is_always_lock_free = ATOMIC_CHAR32_T_LOCK_FREE == 2;
322 
323  using base_type = BASE_ATOMIC_TYPE<char32_t> ;
325  using value_type = typename base_type::value_type;
326  using difference_type = typename base_type::difference_type;;
327 
328  _atomic(const self_type&) = delete;
329  _atomic& operator=(const self_type&) = delete;
330  _atomic& operator=(const self_type&) volatile = delete;
331 
332  constexpr _atomic(value_type value) : base_type(value) { }
333 
334  using base_type::operator value_type;
335  using base_type::operator=;
336  };
337 
341  template<>
342  struct _atomic<wchar_t> : BASE_ATOMIC_TYPE<wchar_t> {
343  static constexpr bool is_always_lock_free = ATOMIC_WCHAR_T_LOCK_FREE == 2;
344 
345  using base_type = BASE_ATOMIC_TYPE<wchar_t> ;
347  using value_type = typename base_type::value_type;
348  using difference_type = typename base_type::difference_type;
349 
350  _atomic(const self_type&) = delete;
351  _atomic& operator=(const self_type&) = delete;
352  _atomic& operator=(const self_type&) volatile = delete;
353 
354  constexpr _atomic(value_type value) : base_type(value) { }
355 
356  using base_type::operator value_type;
357  using base_type::operator=;
358  };
359 
363  template<typename T>
364  struct _atomic_ptr : BASE_ATOMIC_TYPE<T*> {
365  static constexpr bool is_always_lock_free = ATOMIC_POINTER_LOCK_FREE == 2;
366 
367  using pointer = T*;
368  using base_type = BASE_ATOMIC_TYPE<pointer> ;
371 
372  _atomic_ptr() = default;
373  ~_atomic_ptr() = default;
374 
375  constexpr _atomic_ptr(pointer value) : base_type(value) { }
376 
377  _atomic_ptr(const self_type&) = delete;
378  _atomic_ptr& operator=(const self_type&) = delete;
379  _atomic_ptr& operator=(const self_type&) volatile = delete;
380 
381  using base_type::operator pointer;
382  using base_type::operator=;
383 
384  };
385 }
386 
387 #endif
struct mn::memory::detail::ptr_difference T
Definition: mn_atomic_singleton.hpp:38
Definition: mn_allocator_typetraits.hpp:25
long ptrdiff_t
Definition: mn_def.hpp:49
Special version for bool.
Definition: mn_atomic_primary_types.hpp:55
typename base_type::value_type value_type
Definition: mn_atomic_primary_types.hpp:60
BASE_ATOMIC_TYPE< bool > base_type
Definition: mn_atomic_primary_types.hpp:58
constexpr _atomic(value_type value)
Definition: mn_atomic_primary_types.hpp:67
_atomic(const self_type &)=delete
_atomic & operator=(const self_type &) volatile=delete
_atomic & operator=(const self_type &)=delete
typename base_type::difference_type difference_type
Definition: mn_atomic_primary_types.hpp:61
Special version for char16_t.
Definition: mn_atomic_primary_types.hpp:298
_atomic & operator=(const self_type &) volatile=delete
_atomic(const self_type &)=delete
constexpr _atomic(value_type value)
Definition: mn_atomic_primary_types.hpp:310
typename base_type::value_type value_type
Definition: mn_atomic_primary_types.hpp:303
typename base_type::difference_type difference_type
Definition: mn_atomic_primary_types.hpp:304
BASE_ATOMIC_TYPE< char16_t > base_type
Definition: mn_atomic_primary_types.hpp:301
_atomic & operator=(const self_type &)=delete
Special version for char32_t.
Definition: mn_atomic_primary_types.hpp:320
_atomic(const self_type &)=delete
constexpr _atomic(value_type value)
Definition: mn_atomic_primary_types.hpp:332
typename base_type::value_type value_type
Definition: mn_atomic_primary_types.hpp:325
typename base_type::difference_type difference_type
Definition: mn_atomic_primary_types.hpp:326
_atomic & operator=(const self_type &)=delete
_atomic & operator=(const self_type &) volatile=delete
BASE_ATOMIC_TYPE< char32_t > base_type
Definition: mn_atomic_primary_types.hpp:323
Special version for char.
Definition: mn_atomic_primary_types.hpp:77
BASE_ATOMIC_TYPE< char > base_type
Definition: mn_atomic_primary_types.hpp:80
_atomic(const self_type &)=delete
_atomic & operator=(const self_type &)=delete
constexpr _atomic(value_type value)
Definition: mn_atomic_primary_types.hpp:89
typename base_type::difference_type difference_type
Definition: mn_atomic_primary_types.hpp:83
_atomic & operator=(const self_type &) volatile=delete
typename base_type::value_type value_type
Definition: mn_atomic_primary_types.hpp:82
Special version for int.
Definition: mn_atomic_primary_types.hpp:143
_atomic & operator=(const self_type &) volatile=delete
_atomic(const self_type &)=delete
typename base_type::value_type value_type
Definition: mn_atomic_primary_types.hpp:148
_atomic & operator=(const self_type &)=delete
BASE_ATOMIC_TYPE< int > base_type
Definition: mn_atomic_primary_types.hpp:146
constexpr _atomic(value_type value)
Definition: mn_atomic_primary_types.hpp:155
typename base_type::difference_type difference_type
Definition: mn_atomic_primary_types.hpp:149
Special version for long.
Definition: mn_atomic_primary_types.hpp:165
_atomic(const self_type &)=delete
_atomic & operator=(const self_type &)=delete
BASE_ATOMIC_TYPE< long > base_type
Definition: mn_atomic_primary_types.hpp:168
constexpr _atomic(value_type value)
Definition: mn_atomic_primary_types.hpp:177
typename base_type::value_type value_type
Definition: mn_atomic_primary_types.hpp:170
typename base_type::difference_type difference_type
Definition: mn_atomic_primary_types.hpp:171
_atomic & operator=(const self_type &) volatile=delete
Special version for long long.
Definition: mn_atomic_primary_types.hpp:187
typename base_type::difference_type difference_type
Definition: mn_atomic_primary_types.hpp:193
BASE_ATOMIC_TYPE< long long > base_type
Definition: mn_atomic_primary_types.hpp:190
typename base_type::value_type value_type
Definition: mn_atomic_primary_types.hpp:192
_atomic & operator=(const self_type &) volatile=delete
_atomic & operator=(const self_type &)=delete
_atomic(const self_type &)=delete
constexpr _atomic(value_type value)
Definition: mn_atomic_primary_types.hpp:199
Special version for short.
Definition: mn_atomic_primary_types.hpp:121
BASE_ATOMIC_TYPE< short > base_type
Definition: mn_atomic_primary_types.hpp:124
typename base_type::difference_type difference_type
Definition: mn_atomic_primary_types.hpp:127
_atomic & operator=(const self_type &) volatile=delete
_atomic & operator=(const self_type &)=delete
typename base_type::value_type value_type
Definition: mn_atomic_primary_types.hpp:126
_atomic(const self_type &)=delete
constexpr _atomic(value_type value)
Definition: mn_atomic_primary_types.hpp:133
Special version for signed char.
Definition: mn_atomic_primary_types.hpp:99
typename base_type::value_type value_type
Definition: mn_atomic_primary_types.hpp:104
typename base_type::difference_type difference_type
Definition: mn_atomic_primary_types.hpp:105
_atomic & operator=(const self_type &) volatile=delete
BASE_ATOMIC_TYPE< signed char > base_type
Definition: mn_atomic_primary_types.hpp:102
_atomic(const self_type &)=delete
_atomic & operator=(const self_type &)=delete
constexpr _atomic(value_type value)
Definition: mn_atomic_primary_types.hpp:111
Special version for unsigned char.
Definition: mn_atomic_primary_types.hpp:210
typename base_type::value_type value_type
Definition: mn_atomic_primary_types.hpp:215
typename base_type::difference_type difference_type
Definition: mn_atomic_primary_types.hpp:216
_atomic & operator=(const self_type &) volatile=delete
constexpr _atomic(value_type value)
Definition: mn_atomic_primary_types.hpp:222
BASE_ATOMIC_TYPE< unsigned char > base_type
Definition: mn_atomic_primary_types.hpp:213
_atomic & operator=(const self_type &)=delete
_atomic(const self_type &)=delete
Special version for int.
Definition: mn_atomic_primary_types.hpp:254
_atomic & operator=(const self_type &)=delete
constexpr _atomic(value_type value)
Definition: mn_atomic_primary_types.hpp:266
typename base_type::difference_type difference_type
Definition: mn_atomic_primary_types.hpp:260
BASE_ATOMIC_TYPE< unsigned int > base_type
Definition: mn_atomic_primary_types.hpp:257
_atomic & operator=(const self_type &) volatile=delete
_atomic(const self_type &)=delete
typename base_type::value_type value_type
Definition: mn_atomic_primary_types.hpp:259
Special version for long.
Definition: mn_atomic_primary_types.hpp:276
typename base_type::value_type value_type
Definition: mn_atomic_primary_types.hpp:281
_atomic & operator=(const self_type &) volatile=delete
BASE_ATOMIC_TYPE< unsigned long > base_type
Definition: mn_atomic_primary_types.hpp:279
constexpr _atomic(value_type value)
Definition: mn_atomic_primary_types.hpp:288
_atomic & operator=(const self_type &)=delete
_atomic(const self_type &)=delete
typename base_type::difference_type difference_type
Definition: mn_atomic_primary_types.hpp:282
Special version for short.
Definition: mn_atomic_primary_types.hpp:232
_atomic & operator=(const self_type &) volatile=delete
_atomic & operator=(const self_type &)=delete
BASE_ATOMIC_TYPE< unsigned short > base_type
Definition: mn_atomic_primary_types.hpp:235
typename base_type::value_type value_type
Definition: mn_atomic_primary_types.hpp:237
_atomic(const self_type &)=delete
typename base_type::difference_type difference_type
Definition: mn_atomic_primary_types.hpp:238
constexpr _atomic(value_type value)
Definition: mn_atomic_primary_types.hpp:244
Special version for wchar_t.
Definition: mn_atomic_primary_types.hpp:342
constexpr _atomic(value_type value)
Definition: mn_atomic_primary_types.hpp:354
_atomic(const self_type &)=delete
BASE_ATOMIC_TYPE< wchar_t > base_type
Definition: mn_atomic_primary_types.hpp:345
_atomic & operator=(const self_type &) volatile=delete
typename base_type::value_type value_type
Definition: mn_atomic_primary_types.hpp:347
_atomic & operator=(const self_type &)=delete
typename base_type::difference_type difference_type
Definition: mn_atomic_primary_types.hpp:348
Special version for pointer.
Definition: mn_atomic_primary_types.hpp:364
_atomic_ptr & operator=(const self_type &)=delete
static constexpr bool is_always_lock_free
Definition: mn_atomic_primary_types.hpp:365
_atomic_ptr & operator=(const self_type &) volatile=delete
~_atomic_ptr()=default
_atomic_ptr(const self_type &)=delete
constexpr _atomic_ptr(pointer value)
Definition: mn_atomic_primary_types.hpp:375
T * pointer
Definition: mn_atomic_primary_types.hpp:367
BASE_ATOMIC_TYPE< pointer > base_type
Definition: mn_atomic_primary_types.hpp:368
mn::ptrdiff_t difference_type
Definition: mn_atomic_primary_types.hpp:370
_atomic_ptr()=default
Only for declar special version for types.
Definition: mn_atomic_primary_types.hpp:43
typename base_type::value_type value_type
Definition: mn_atomic_primary_types.hpp:46
typename base_type::value_type difference_type
Definition: mn_atomic_primary_types.hpp:47
BASE_ATOMIC_TYPE< T > base_type
Definition: mn_atomic_primary_types.hpp:44