xref: /freebsd/contrib/llvm-project/libcxx/include/__atomic/support.h (revision 700637cbb5e582861067a11aaca4d053546871d2)
1*700637cbSDimitry Andric //===----------------------------------------------------------------------===//
2*700637cbSDimitry Andric //
3*700637cbSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*700637cbSDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
5*700637cbSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*700637cbSDimitry Andric //
7*700637cbSDimitry Andric //===----------------------------------------------------------------------===//
8*700637cbSDimitry Andric 
9*700637cbSDimitry Andric #ifndef _LIBCPP___ATOMIC_SUPPORT_H
10*700637cbSDimitry Andric #define _LIBCPP___ATOMIC_SUPPORT_H
11*700637cbSDimitry Andric 
12*700637cbSDimitry Andric #include <__config>
13*700637cbSDimitry Andric 
14*700637cbSDimitry Andric #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
15*700637cbSDimitry Andric #  pragma GCC system_header
16*700637cbSDimitry Andric #endif
17*700637cbSDimitry Andric 
18*700637cbSDimitry Andric //
19*700637cbSDimitry Andric // This file implements base support for atomics on the platform.
20*700637cbSDimitry Andric //
21*700637cbSDimitry Andric // The following operations and types must be implemented (where _Atmc
22*700637cbSDimitry Andric // is __cxx_atomic_base_impl for readability):
23*700637cbSDimitry Andric //
24*700637cbSDimitry Andric // clang-format off
25*700637cbSDimitry Andric //
26*700637cbSDimitry Andric // template <class _Tp>
27*700637cbSDimitry Andric // struct __cxx_atomic_base_impl;
28*700637cbSDimitry Andric //
29*700637cbSDimitry Andric // #define __cxx_atomic_is_lock_free(__size)
30*700637cbSDimitry Andric //
31*700637cbSDimitry Andric // void __cxx_atomic_thread_fence(memory_order __order) noexcept;
32*700637cbSDimitry Andric // void __cxx_atomic_signal_fence(memory_order __order) noexcept;
33*700637cbSDimitry Andric //
34*700637cbSDimitry Andric // template <class _Tp>
35*700637cbSDimitry Andric // void __cxx_atomic_init(_Atmc<_Tp> volatile* __a, _Tp __val) noexcept;
36*700637cbSDimitry Andric // template <class _Tp>
37*700637cbSDimitry Andric // void __cxx_atomic_init(_Atmc<_Tp>* __a, _Tp __val) noexcept;
38*700637cbSDimitry Andric //
39*700637cbSDimitry Andric // template <class _Tp>
40*700637cbSDimitry Andric // void __cxx_atomic_store(_Atmc<_Tp> volatile* __a, _Tp __val, memory_order __order) noexcept;
41*700637cbSDimitry Andric // template <class _Tp>
42*700637cbSDimitry Andric // void __cxx_atomic_store(_Atmc<_Tp>* __a, _Tp __val, memory_order __order) noexcept;
43*700637cbSDimitry Andric //
44*700637cbSDimitry Andric // template <class _Tp>
45*700637cbSDimitry Andric // _Tp __cxx_atomic_load(_Atmc<_Tp> const volatile* __a, memory_order __order) noexcept;
46*700637cbSDimitry Andric // template <class _Tp>
47*700637cbSDimitry Andric // _Tp __cxx_atomic_load(_Atmc<_Tp> const* __a, memory_order __order) noexcept;
48*700637cbSDimitry Andric //
49*700637cbSDimitry Andric // template <class _Tp>
50*700637cbSDimitry Andric // void __cxx_atomic_load_inplace(_Atmc<_Tp> const volatile* __a, _Tp* __dst, memory_order __order) noexcept;
51*700637cbSDimitry Andric // template <class _Tp>
52*700637cbSDimitry Andric // void __cxx_atomic_load_inplace(_Atmc<_Tp> const* __a, _Tp* __dst, memory_order __order) noexcept;
53*700637cbSDimitry Andric //
54*700637cbSDimitry Andric // template <class _Tp>
55*700637cbSDimitry Andric // _Tp __cxx_atomic_exchange(_Atmc<_Tp> volatile* __a, _Tp __value, memory_order __order) noexcept;
56*700637cbSDimitry Andric // template <class _Tp>
57*700637cbSDimitry Andric // _Tp __cxx_atomic_exchange(_Atmc<_Tp>* __a, _Tp __value, memory_order __order) noexcept;
58*700637cbSDimitry Andric //
59*700637cbSDimitry Andric // template <class _Tp>
60*700637cbSDimitry Andric // bool __cxx_atomic_compare_exchange_strong(_Atmc<_Tp> volatile* __a, _Tp* __expected, _Tp __value, memory_order __success, memory_order __failure) noexcept;
61*700637cbSDimitry Andric // template <class _Tp>
62*700637cbSDimitry Andric // bool __cxx_atomic_compare_exchange_strong(_Atmc<_Tp>* __a, _Tp* __expected, _Tp __value, memory_order __success, memory_order __failure) noexcept;
63*700637cbSDimitry Andric //
64*700637cbSDimitry Andric // template <class _Tp>
65*700637cbSDimitry Andric // bool __cxx_atomic_compare_exchange_weak(_Atmc<_Tp> volatile* __a, _Tp* __expected, _Tp __value, memory_order __success, memory_order __failure) noexcept;
66*700637cbSDimitry Andric // template <class _Tp>
67*700637cbSDimitry Andric // bool __cxx_atomic_compare_exchange_weak(_Atmc<_Tp>* __a, _Tp* __expected, _Tp __value, memory_order __success, memory_order __failure) noexcept;
68*700637cbSDimitry Andric //
69*700637cbSDimitry Andric // template <class _Tp>
70*700637cbSDimitry Andric // _Tp __cxx_atomic_fetch_add(_Atmc<_Tp> volatile* __a, _Tp __delta, memory_order __order) noexcept;
71*700637cbSDimitry Andric // template <class _Tp>
72*700637cbSDimitry Andric // _Tp __cxx_atomic_fetch_add(_Atmc<_Tp>* __a, _Tp __delta, memory_order __order) noexcept;
73*700637cbSDimitry Andric //
74*700637cbSDimitry Andric // template <class _Tp>
75*700637cbSDimitry Andric // _Tp* __cxx_atomic_fetch_add(_Atmc<_Tp*> volatile* __a, ptrdiff_t __delta, memory_order __order) noexcept;
76*700637cbSDimitry Andric // template <class _Tp>
77*700637cbSDimitry Andric // _Tp* __cxx_atomic_fetch_add(_Atmc<_Tp*>* __a, ptrdiff_t __delta, memory_order __order) noexcept;
78*700637cbSDimitry Andric //
79*700637cbSDimitry Andric // template <class _Tp>
80*700637cbSDimitry Andric // _Tp __cxx_atomic_fetch_sub(_Atmc<_Tp> volatile* __a, _Tp __delta, memory_order __order) noexcept;
81*700637cbSDimitry Andric // template <class _Tp>
82*700637cbSDimitry Andric // _Tp __cxx_atomic_fetch_sub(_Atmc<_Tp>* __a, _Tp __delta, memory_order __order) noexcept;
83*700637cbSDimitry Andric // template <class _Tp>
84*700637cbSDimitry Andric // _Tp* __cxx_atomic_fetch_sub(_Atmc<_Tp*> volatile* __a, ptrdiff_t __delta, memory_order __order) noexcept;
85*700637cbSDimitry Andric // template <class _Tp>
86*700637cbSDimitry Andric // _Tp* __cxx_atomic_fetch_sub(_Atmc<_Tp*>* __a, ptrdiff_t __delta, memory_order __order) noexcept;
87*700637cbSDimitry Andric //
88*700637cbSDimitry Andric // template <class _Tp>
89*700637cbSDimitry Andric // _Tp __cxx_atomic_fetch_and(_Atmc<_Tp> volatile* __a, _Tp __pattern, memory_order __order) noexcept;
90*700637cbSDimitry Andric // template <class _Tp>
91*700637cbSDimitry Andric // _Tp __cxx_atomic_fetch_and(_Atmc<_Tp>* __a, _Tp __pattern, memory_order __order) noexcept;
92*700637cbSDimitry Andric //
93*700637cbSDimitry Andric // template <class _Tp>
94*700637cbSDimitry Andric // _Tp __cxx_atomic_fetch_or(_Atmc<_Tp> volatile* __a, _Tp __pattern, memory_order __order) noexcept;
95*700637cbSDimitry Andric // template <class _Tp>
96*700637cbSDimitry Andric // _Tp __cxx_atomic_fetch_or(_Atmc<_Tp>* __a, _Tp __pattern, memory_order __order) noexcept;
97*700637cbSDimitry Andric // template <class _Tp>
98*700637cbSDimitry Andric // _Tp __cxx_atomic_fetch_xor(_Atmc<_Tp> volatile* __a, _Tp __pattern, memory_order __order) noexcept;
99*700637cbSDimitry Andric // template <class _Tp>
100*700637cbSDimitry Andric // _Tp __cxx_atomic_fetch_xor(_Atmc<_Tp>* __a, _Tp __pattern, memory_order __order) noexcept;
101*700637cbSDimitry Andric //
102*700637cbSDimitry Andric // clang-format on
103*700637cbSDimitry Andric //
104*700637cbSDimitry Andric 
105*700637cbSDimitry Andric #if _LIBCPP_HAS_GCC_ATOMIC_IMP
106*700637cbSDimitry Andric #  include <__atomic/support/gcc.h>
107*700637cbSDimitry Andric #elif _LIBCPP_HAS_C_ATOMIC_IMP
108*700637cbSDimitry Andric #  include <__atomic/support/c11.h>
109*700637cbSDimitry Andric #endif
110*700637cbSDimitry Andric 
111*700637cbSDimitry Andric _LIBCPP_BEGIN_NAMESPACE_STD
112*700637cbSDimitry Andric 
113*700637cbSDimitry Andric template <typename _Tp, typename _Base = __cxx_atomic_base_impl<_Tp> >
114*700637cbSDimitry Andric struct __cxx_atomic_impl : public _Base {
115*700637cbSDimitry Andric   _LIBCPP_HIDE_FROM_ABI __cxx_atomic_impl() _NOEXCEPT = default;
__cxx_atomic_impl__cxx_atomic_impl116*700637cbSDimitry Andric   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR explicit __cxx_atomic_impl(_Tp __value) _NOEXCEPT : _Base(__value) {}
117*700637cbSDimitry Andric };
118*700637cbSDimitry Andric 
119*700637cbSDimitry Andric _LIBCPP_END_NAMESPACE_STD
120*700637cbSDimitry Andric 
121*700637cbSDimitry Andric #endif // _LIBCPP___ATOMIC_SUPPORT_H
122