Skip to content

Commit 46db8d8

Browse files
committed
[libc++] Granularize <atomic>
Reviewed By: Mordante, #libc Spies: arichardson, libcxx-commits, krytarowski Differential Revision: https://reviews.llvm.org/D142972
1 parent 62e4f81 commit 46db8d8

32 files changed

+2563
-2159
lines changed

libcxx/include/CMakeLists.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,20 @@ set(files
193193
__algorithm/unwrap_range.h
194194
__algorithm/upper_bound.h
195195
__assert
196+
__atomic/aliases.h
197+
__atomic/atomic.h
198+
__atomic/atomic_base.h
199+
__atomic/atomic_flag.h
200+
__atomic/atomic_init.h
201+
__atomic/atomic_lock_free.h
202+
__atomic/atomic_sync.h
203+
__atomic/check_memory_order.h
204+
__atomic/contention_t.h
205+
__atomic/cxx_atomic_impl.h
206+
__atomic/fence.h
207+
__atomic/is_always_lock_free.h
208+
__atomic/kill_dependency.h
209+
__atomic/memory_order.h
196210
__availability
197211
__bit/bit_cast.h
198212
__bit/bit_ceil.h

libcxx/include/__atomic/aliases.h

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
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_ALIASES_H
10+
#define _LIBCPP___ATOMIC_ALIASES_H
11+
12+
#include <__atomic/atomic.h>
13+
#include <__atomic/atomic_lock_free.h>
14+
#include <__atomic/contention_t.h>
15+
#include <__atomic/is_always_lock_free.h>
16+
#include <__config>
17+
#include <__type_traits/conditional.h>
18+
#include <cstddef>
19+
#include <cstdint>
20+
#include <cstdlib>
21+
22+
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
23+
# pragma GCC system_header
24+
#endif
25+
26+
_LIBCPP_BEGIN_NAMESPACE_STD
27+
28+
typedef atomic<bool> atomic_bool;
29+
typedef atomic<char> atomic_char;
30+
typedef atomic<signed char> atomic_schar;
31+
typedef atomic<unsigned char> atomic_uchar;
32+
typedef atomic<short> atomic_short;
33+
typedef atomic<unsigned short> atomic_ushort;
34+
typedef atomic<int> atomic_int;
35+
typedef atomic<unsigned int> atomic_uint;
36+
typedef atomic<long> atomic_long;
37+
typedef atomic<unsigned long> atomic_ulong;
38+
typedef atomic<long long> atomic_llong;
39+
typedef atomic<unsigned long long> atomic_ullong;
40+
#ifndef _LIBCPP_HAS_NO_CHAR8_T
41+
typedef atomic<char8_t> atomic_char8_t;
42+
#endif
43+
typedef atomic<char16_t> atomic_char16_t;
44+
typedef atomic<char32_t> atomic_char32_t;
45+
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
46+
typedef atomic<wchar_t> atomic_wchar_t;
47+
#endif
48+
49+
typedef atomic<int_least8_t> atomic_int_least8_t;
50+
typedef atomic<uint_least8_t> atomic_uint_least8_t;
51+
typedef atomic<int_least16_t> atomic_int_least16_t;
52+
typedef atomic<uint_least16_t> atomic_uint_least16_t;
53+
typedef atomic<int_least32_t> atomic_int_least32_t;
54+
typedef atomic<uint_least32_t> atomic_uint_least32_t;
55+
typedef atomic<int_least64_t> atomic_int_least64_t;
56+
typedef atomic<uint_least64_t> atomic_uint_least64_t;
57+
58+
typedef atomic<int_fast8_t> atomic_int_fast8_t;
59+
typedef atomic<uint_fast8_t> atomic_uint_fast8_t;
60+
typedef atomic<int_fast16_t> atomic_int_fast16_t;
61+
typedef atomic<uint_fast16_t> atomic_uint_fast16_t;
62+
typedef atomic<int_fast32_t> atomic_int_fast32_t;
63+
typedef atomic<uint_fast32_t> atomic_uint_fast32_t;
64+
typedef atomic<int_fast64_t> atomic_int_fast64_t;
65+
typedef atomic<uint_fast64_t> atomic_uint_fast64_t;
66+
67+
typedef atomic< int8_t> atomic_int8_t;
68+
typedef atomic<uint8_t> atomic_uint8_t;
69+
typedef atomic< int16_t> atomic_int16_t;
70+
typedef atomic<uint16_t> atomic_uint16_t;
71+
typedef atomic< int32_t> atomic_int32_t;
72+
typedef atomic<uint32_t> atomic_uint32_t;
73+
typedef atomic< int64_t> atomic_int64_t;
74+
typedef atomic<uint64_t> atomic_uint64_t;
75+
76+
typedef atomic<intptr_t> atomic_intptr_t;
77+
typedef atomic<uintptr_t> atomic_uintptr_t;
78+
typedef atomic<size_t> atomic_size_t;
79+
typedef atomic<ptrdiff_t> atomic_ptrdiff_t;
80+
typedef atomic<intmax_t> atomic_intmax_t;
81+
typedef atomic<uintmax_t> atomic_uintmax_t;
82+
83+
// atomic_*_lock_free : prefer the contention type most highly, then the largest lock-free type
84+
85+
#ifdef __cpp_lib_atomic_is_always_lock_free
86+
# define _LIBCPP_CONTENTION_LOCK_FREE ::std::__libcpp_is_always_lock_free<__cxx_contention_t>::__value
87+
#else
88+
# define _LIBCPP_CONTENTION_LOCK_FREE false
89+
#endif
90+
91+
#if ATOMIC_LLONG_LOCK_FREE == 2
92+
typedef __conditional_t<_LIBCPP_CONTENTION_LOCK_FREE, __cxx_contention_t, long long> __libcpp_signed_lock_free;
93+
typedef __conditional_t<_LIBCPP_CONTENTION_LOCK_FREE, __cxx_contention_t, unsigned long long> __libcpp_unsigned_lock_free;
94+
#elif ATOMIC_INT_LOCK_FREE == 2
95+
typedef __conditional_t<_LIBCPP_CONTENTION_LOCK_FREE, __cxx_contention_t, int> __libcpp_signed_lock_free;
96+
typedef __conditional_t<_LIBCPP_CONTENTION_LOCK_FREE, __cxx_contention_t, unsigned int> __libcpp_unsigned_lock_free;
97+
#elif ATOMIC_SHORT_LOCK_FREE == 2
98+
typedef __conditional_t<_LIBCPP_CONTENTION_LOCK_FREE, __cxx_contention_t, short> __libcpp_signed_lock_free;
99+
typedef __conditional_t<_LIBCPP_CONTENTION_LOCK_FREE, __cxx_contention_t, unsigned short> __libcpp_unsigned_lock_free;
100+
#elif ATOMIC_CHAR_LOCK_FREE == 2
101+
typedef __conditional_t<_LIBCPP_CONTENTION_LOCK_FREE, __cxx_contention_t, char> __libcpp_signed_lock_free;
102+
typedef __conditional_t<_LIBCPP_CONTENTION_LOCK_FREE, __cxx_contention_t, unsigned char> __libcpp_unsigned_lock_free;
103+
#else
104+
// No signed/unsigned lock-free types
105+
#define _LIBCPP_NO_LOCK_FREE_TYPES
106+
#endif
107+
108+
#if !defined(_LIBCPP_NO_LOCK_FREE_TYPES)
109+
typedef atomic<__libcpp_signed_lock_free> atomic_signed_lock_free;
110+
typedef atomic<__libcpp_unsigned_lock_free> atomic_unsigned_lock_free;
111+
#endif
112+
113+
_LIBCPP_END_NAMESPACE_STD
114+
115+
#endif // _LIBCPP___ATOMIC_ALIASES_H

0 commit comments

Comments
 (0)