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_MEMORY_ORDER_H 10 #define _LIBCPP___ATOMIC_MEMORY_ORDER_H 11 12 #include <__config> 13 #include <__type_traits/is_same.h> 14 #include <__type_traits/underlying_type.h> 15 16 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 17 # pragma GCC system_header 18 #endif 19 20 _LIBCPP_BEGIN_NAMESPACE_STD 21 22 // Figure out what the underlying type for `memory_order` would be if it were 23 // declared as an unscoped enum (accounting for -fshort-enums). Use this result 24 // to pin the underlying type in C++20. 25 enum __legacy_memory_order { __mo_relaxed, __mo_consume, __mo_acquire, __mo_release, __mo_acq_rel, __mo_seq_cst }; 26 27 using __memory_order_underlying_t = underlying_type<__legacy_memory_order>::type; 28 29 #if _LIBCPP_STD_VER >= 20 30 31 enum class memory_order : __memory_order_underlying_t { 32 relaxed = __mo_relaxed, 33 consume = __mo_consume, 34 acquire = __mo_acquire, 35 release = __mo_release, 36 acq_rel = __mo_acq_rel, 37 seq_cst = __mo_seq_cst 38 }; 39 40 static_assert(is_same<underlying_type<memory_order>::type, __memory_order_underlying_t>::value, 41 "unexpected underlying type for std::memory_order"); 42 43 inline constexpr auto memory_order_relaxed = memory_order::relaxed; 44 inline constexpr auto memory_order_consume = memory_order::consume; 45 inline constexpr auto memory_order_acquire = memory_order::acquire; 46 inline constexpr auto memory_order_release = memory_order::release; 47 inline constexpr auto memory_order_acq_rel = memory_order::acq_rel; 48 inline constexpr auto memory_order_seq_cst = memory_order::seq_cst; 49 50 #else 51 52 enum memory_order { 53 memory_order_relaxed = __mo_relaxed, 54 memory_order_consume = __mo_consume, 55 memory_order_acquire = __mo_acquire, 56 memory_order_release = __mo_release, 57 memory_order_acq_rel = __mo_acq_rel, 58 memory_order_seq_cst = __mo_seq_cst, 59 }; 60 61 #endif // _LIBCPP_STD_VER >= 20 62 63 _LIBCPP_END_NAMESPACE_STD 64 65 #endif // _LIBCPP___ATOMIC_MEMORY_ORDER_H 66