Skip to content

Commit b5f8f92

Browse files
committed
[libc++][atomic_ref] move __to_gcc_[failure_]order to its own header file
1 parent 3adf64a commit b5f8f92

File tree

5 files changed

+58
-26
lines changed

5 files changed

+58
-26
lines changed

libcxx/include/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ set(files
245245
__atomic/is_always_lock_free.h
246246
__atomic/kill_dependency.h
247247
__atomic/memory_order.h
248+
__atomic/to_gcc_order.h
248249
__availability
249250
__bit/bit_cast.h
250251
__bit/bit_ceil.h

libcxx/include/__atomic/atomic_ref.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <__atomic/check_memory_order.h>
2222
#include <__atomic/cxx_atomic_impl.h>
2323
#include <__atomic/is_always_lock_free.h>
24+
#include <__atomic/to_gcc_order.h>
2425
#include <__config>
2526
#include <__memory/addressof.h>
2627
#include <__type_traits/is_floating_point.h>

libcxx/include/__atomic/cxx_atomic_impl.h

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include <__atomic/is_always_lock_free.h>
1313
#include <__atomic/memory_order.h>
14+
#include <__atomic/to_gcc_order.h>
1415
#include <__config>
1516
#include <__memory/addressof.h>
1617
#include <__type_traits/conditional.h>
@@ -61,32 +62,6 @@ struct __cxx_atomic_base_impl {
6162
_Tp __a_value;
6263
};
6364

64-
_LIBCPP_HIDE_FROM_ABI inline _LIBCPP_CONSTEXPR int __to_gcc_order(memory_order __order) {
65-
// Avoid switch statement to make this a constexpr.
66-
return __order == memory_order_relaxed
67-
? __ATOMIC_RELAXED
68-
: (__order == memory_order_acquire
69-
? __ATOMIC_ACQUIRE
70-
: (__order == memory_order_release
71-
? __ATOMIC_RELEASE
72-
: (__order == memory_order_seq_cst
73-
? __ATOMIC_SEQ_CST
74-
: (__order == memory_order_acq_rel ? __ATOMIC_ACQ_REL : __ATOMIC_CONSUME))));
75-
}
76-
77-
_LIBCPP_HIDE_FROM_ABI inline _LIBCPP_CONSTEXPR int __to_gcc_failure_order(memory_order __order) {
78-
// Avoid switch statement to make this a constexpr.
79-
return __order == memory_order_relaxed
80-
? __ATOMIC_RELAXED
81-
: (__order == memory_order_acquire
82-
? __ATOMIC_ACQUIRE
83-
: (__order == memory_order_release
84-
? __ATOMIC_RELAXED
85-
: (__order == memory_order_seq_cst
86-
? __ATOMIC_SEQ_CST
87-
: (__order == memory_order_acq_rel ? __ATOMIC_ACQUIRE : __ATOMIC_CONSUME))));
88-
}
89-
9065
template <typename _Tp>
9166
_LIBCPP_HIDE_FROM_ABI void __cxx_atomic_init(volatile __cxx_atomic_base_impl<_Tp>* __a, _Tp __val) {
9267
__cxx_atomic_assign_volatile(__a->__a_value, __val);
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef _LIBCPP___ATOMIC_TO_GCC_ORDER_H
10+
#define _LIBCPP___ATOMIC_TO_GCC_ORDER_H
11+
12+
#include <__atomic/memory_order.h>
13+
#include <__config>
14+
15+
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16+
# pragma GCC system_header
17+
#endif
18+
19+
_LIBCPP_BEGIN_NAMESPACE_STD
20+
21+
#if defined(__ATOMIC_RELAXED) && defined(__ATOMIC_CONSUME) && defined(__ATOMIC_ACQUIRE) && \
22+
defined(__ATOMIC_RELEASE) && defined(__ATOMIC_ACQ_REL) && defined(__ATOMIC_SEQ_CST)
23+
24+
_LIBCPP_HIDE_FROM_ABI inline _LIBCPP_CONSTEXPR int __to_gcc_order(memory_order __order) {
25+
// Avoid switch statement to make this a constexpr.
26+
return __order == memory_order_relaxed
27+
? __ATOMIC_RELAXED
28+
: (__order == memory_order_acquire
29+
? __ATOMIC_ACQUIRE
30+
: (__order == memory_order_release
31+
? __ATOMIC_RELEASE
32+
: (__order == memory_order_seq_cst
33+
? __ATOMIC_SEQ_CST
34+
: (__order == memory_order_acq_rel ? __ATOMIC_ACQ_REL : __ATOMIC_CONSUME))));
35+
}
36+
37+
_LIBCPP_HIDE_FROM_ABI inline _LIBCPP_CONSTEXPR int __to_gcc_failure_order(memory_order __order) {
38+
// Avoid switch statement to make this a constexpr.
39+
return __order == memory_order_relaxed
40+
? __ATOMIC_RELAXED
41+
: (__order == memory_order_acquire
42+
? __ATOMIC_ACQUIRE
43+
: (__order == memory_order_release
44+
? __ATOMIC_RELAXED
45+
: (__order == memory_order_seq_cst
46+
? __ATOMIC_SEQ_CST
47+
: (__order == memory_order_acq_rel ? __ATOMIC_ACQUIRE : __ATOMIC_CONSUME))));
48+
}
49+
50+
#endif
51+
52+
_LIBCPP_END_NAMESPACE_STD
53+
54+
#endif // _LIBCPP___ATOMIC_TO_GCC_ORDER_H

libcxx/include/module.modulemap.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,6 +1103,7 @@ module std_private_atomic_fence [system] { header "__atomic/fence.
11031103
module std_private_atomic_is_always_lock_free [system] { header "__atomic/is_always_lock_free.h" }
11041104
module std_private_atomic_kill_dependency [system] { header "__atomic/kill_dependency.h" }
11051105
module std_private_atomic_memory_order [system] { header "__atomic/memory_order.h" }
1106+
module std_private_atomic_to_gcc_order [system] { header "__atomic/to_gcc_order.h" }
11061107

11071108
module std_private_bit_bit_cast [system] { header "__bit/bit_cast.h" }
11081109
module std_private_bit_bit_ceil [system] { header "__bit/bit_ceil.h" }

0 commit comments

Comments
 (0)