Skip to content

Commit 34933d1

Browse files
authored
[libc++] Improves _LIBCPP_HAS_NO_THREADS guards. (#76624)
Previously the header included several headers, possibly granularized threading headers. This could lead to build errors when these headers were incompatible with threading disabled. Now test the guard before inclusion. This matches the pattern used for no localization and no wide characters. Fixes: #76620
1 parent e044362 commit 34933d1

File tree

7 files changed

+42
-35
lines changed

7 files changed

+42
-35
lines changed

Diff for: libcxx/include/barrier

+6-5
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,16 @@ namespace std
4545
4646
*/
4747

48+
#include <__config>
49+
50+
#ifdef _LIBCPP_HAS_NO_THREADS
51+
# error "<barrier> is not supported since libc++ has been configured without support for threads."
52+
#endif
53+
4854
#include <__assert> // all public C++ headers provide the assertion handler
4955
#include <__atomic/atomic_base.h>
5056
#include <__atomic/memory_order.h>
5157
#include <__availability>
52-
#include <__config>
5358
#include <__memory/unique_ptr.h>
5459
#include <__thread/poll_with_backoff.h>
5560
#include <__thread/timed_backoff_policy.h>
@@ -63,10 +68,6 @@ namespace std
6368
# pragma GCC system_header
6469
#endif
6570

66-
#ifdef _LIBCPP_HAS_NO_THREADS
67-
# error "<barrier> is not supported since libc++ has been configured without support for threads."
68-
#endif
69-
7071
_LIBCPP_PUSH_MACROS
7172
#include <__undef_macros>
7273

Diff for: libcxx/include/future

+6-5
Original file line numberDiff line numberDiff line change
@@ -362,11 +362,16 @@ template <class R, class Alloc> struct uses_allocator<packaged_task<R>, Alloc>;
362362
363363
*/
364364

365+
#include <__config>
366+
367+
#ifdef _LIBCPP_HAS_NO_THREADS
368+
# error "<future> is not supported since libc++ has been configured without support for threads."
369+
#endif
370+
365371
#include <__assert> // all public C++ headers provide the assertion handler
366372
#include <__availability>
367373
#include <__chrono/duration.h>
368374
#include <__chrono/time_point.h>
369-
#include <__config>
370375
#include <__exception/exception_ptr.h>
371376
#include <__memory/addressof.h>
372377
#include <__memory/allocator.h>
@@ -396,10 +401,6 @@ template <class R, class Alloc> struct uses_allocator<packaged_task<R>, Alloc>;
396401
# pragma GCC system_header
397402
#endif
398403

399-
#ifdef _LIBCPP_HAS_NO_THREADS
400-
# error "<future> is not supported since libc++ has been configured without support for threads."
401-
#endif
402-
403404
_LIBCPP_BEGIN_NAMESPACE_STD
404405

405406
// enum class future_errc

Diff for: libcxx/include/latch

+6-5
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,17 @@ namespace std
4040
4141
*/
4242

43+
#include <__config>
44+
45+
#ifdef _LIBCPP_HAS_NO_THREADS
46+
# error "<latch> is not supported since libc++ has been configured without support for threads."
47+
#endif
48+
4349
#include <__assert> // all public C++ headers provide the assertion handler
4450
#include <__atomic/atomic_base.h>
4551
#include <__atomic/atomic_sync.h>
4652
#include <__atomic/memory_order.h>
4753
#include <__availability>
48-
#include <__config>
4954
#include <cstddef>
5055
#include <limits>
5156
#include <version>
@@ -54,10 +59,6 @@ namespace std
5459
# pragma GCC system_header
5560
#endif
5661

57-
#ifdef _LIBCPP_HAS_NO_THREADS
58-
# error "<latch> is not supported since libc++ has been configured without support for threads."
59-
#endif
60-
6162
_LIBCPP_PUSH_MACROS
6263
#include <__undef_macros>
6364

Diff for: libcxx/include/semaphore

+6-5
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,18 @@ using binary_semaphore = counting_semaphore<1>;
4545
4646
*/
4747

48+
#include <__config>
49+
50+
#ifdef _LIBCPP_HAS_NO_THREADS
51+
# error "<semaphore> is not supported since libc++ has been configured without support for threads."
52+
#endif
53+
4854
#include <__assert> // all public C++ headers provide the assertion handler
4955
#include <__atomic/atomic_base.h>
5056
#include <__atomic/atomic_sync.h>
5157
#include <__atomic/memory_order.h>
5258
#include <__availability>
5359
#include <__chrono/time_point.h>
54-
#include <__config>
5560
#include <__thread/poll_with_backoff.h>
5661
#include <__thread/timed_backoff_policy.h>
5762
#include <__threading_support>
@@ -63,10 +68,6 @@ using binary_semaphore = counting_semaphore<1>;
6368
# pragma GCC system_header
6469
#endif
6570

66-
#ifdef _LIBCPP_HAS_NO_THREADS
67-
# error "<semaphore> is not supported since libc++ has been configured without support for threads."
68-
#endif
69-
7071
_LIBCPP_PUSH_MACROS
7172
#include <__undef_macros>
7273

Diff for: libcxx/include/shared_mutex

+6-5
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,18 @@ template <class Mutex>
122122
123123
*/
124124

125+
#include <__config>
126+
127+
# ifdef _LIBCPP_HAS_NO_THREADS
128+
# error "<shared_mutex> is not supported since libc++ has been configured without support for threads."
129+
# endif
130+
125131
#include <__assert> // all public C++ headers provide the assertion handler
126132
#include <__availability>
127133
#include <__chrono/duration.h>
128134
#include <__chrono/steady_clock.h>
129135
#include <__chrono/time_point.h>
130136
#include <__condition_variable/condition_variable.h>
131-
#include <__config>
132137
#include <__memory/addressof.h>
133138
#include <__mutex/mutex.h>
134139
#include <__mutex/tag_types.h>
@@ -147,10 +152,6 @@ _LIBCPP_PUSH_MACROS
147152
# pragma GCC system_header
148153
# endif
149154

150-
# ifdef _LIBCPP_HAS_NO_THREADS
151-
# error "<shared_mutex> is not supported since libc++ has been configured without support for threads."
152-
# endif
153-
154155
_LIBCPP_BEGIN_NAMESPACE_STD
155156

156157
struct _LIBCPP_EXPORTED_FROM_ABI __shared_mutex_base {

Diff for: libcxx/include/stop_token

+6-5
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,13 @@ namespace std {
3131
3232
*/
3333

34-
#include <__assert> // all public C++ headers provide the assertion handler
3534
#include <__config>
35+
36+
#ifdef _LIBCPP_HAS_NO_THREADS
37+
# error "<stop_token> is not supported since libc++ has been configured without support for threads."
38+
#endif
39+
40+
#include <__assert> // all public C++ headers provide the assertion handler
3641
#include <__stop_token/stop_callback.h>
3742
#include <__stop_token/stop_source.h>
3843
#include <__stop_token/stop_token.h>
@@ -42,10 +47,6 @@ namespace std {
4247
# pragma GCC system_header
4348
#endif
4449

45-
#ifdef _LIBCPP_HAS_NO_THREADS
46-
# error "<stop_token> is not supported since libc++ has been configured without support for threads."
47-
#endif
48-
4950
#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
5051
# include <iosfwd>
5152
#endif

Diff for: libcxx/include/thread

+6-5
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,14 @@ void sleep_for(const chrono::duration<Rep, Period>& rel_time);
8686
8787
*/
8888

89+
#include <__config>
90+
91+
#ifdef _LIBCPP_HAS_NO_THREADS
92+
# error "<thread> is not supported since libc++ has been configured without support for threads."
93+
#endif
94+
8995
#include <__assert> // all public C++ headers provide the assertion handler
9096
#include <__availability>
91-
#include <__config>
9297
#include <__thread/formatter.h>
9398
#include <__thread/jthread.h>
9499
#include <__thread/this_thread.h>
@@ -105,10 +110,6 @@ void sleep_for(const chrono::duration<Rep, Period>& rel_time);
105110
# pragma GCC system_header
106111
#endif
107112

108-
#ifdef _LIBCPP_HAS_NO_THREADS
109-
# error "<thread> is not supported since libc++ has been configured without support for threads."
110-
#endif
111-
112113
#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES)
113114
# include <cstddef>
114115
# include <ctime>

0 commit comments

Comments
 (0)