Skip to content

Commit b293f6f

Browse files
committed
Add cmake/Modules back- thread mode is set by libcxx
1 parent 2e6cc20 commit b293f6f

File tree

3 files changed

+19
-13
lines changed

3 files changed

+19
-13
lines changed

cmake/Modules/FindLibcCommonUtils.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ if(NOT TARGET llvm-libc-common-utilities)
1212
add_library(llvm-libc-common-utilities INTERFACE)
1313
# TODO: Reorganize the libc shared section so that it can be included without
1414
# adding the root "libc" directory to the include path.
15+
if (NOT(LIBCXX_ENABLE_THREADS))
16+
target_compile_definitions(llvm-libc-common-utilities INTERFACE LIBC_THREAD_MODE=LIBC_THREAD_MODE_SINGLE)
17+
endif()
1518
target_include_directories(llvm-libc-common-utilities INTERFACE ${libc_path})
1619
target_compile_definitions(llvm-libc-common-utilities INTERFACE LIBC_NAMESPACE=__llvm_libc_common_utils)
1720
target_compile_features(llvm-libc-common-utilities INTERFACE cxx_std_17)

libc/src/__support/macros/attributes.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,22 @@
3737
// Vendor provides implementation
3838
#define LIBC_THREAD_MODE_EXTERNAL 2
3939

40+
// libcxx doesn't define LIBC_THREAD_MODE, unless that is passed in the command
41+
// line in the CMake invocation. This defaults to the original implementation
42+
// (before changes in https://github.com/llvm/llvm-project/pull/145358)
43+
#ifndef LIBC_THREAD_MODE
44+
#define LIBC_THREAD_MODE LIBC_THREAD_MODE_PLATFORM
45+
#endif // LIBC_THREAD_MODE
46+
47+
#if LIBC_THREAD_MODE != LIBC_THREAD_MODE_PLATFORM && \
48+
LIBC_THREAD_MODE != LIBC_THREAD_MODE_SINGLE && \
49+
LIBC_THREAD_MODE != LIBC_THREAD_MODE_EXTERNAL
50+
#error LIBC_THREAD_MODE must be one of the following values: \
51+
LIBC_THREAD_MODE_PLATFORM, \
52+
LIBC_THREAD_MODE_SINGLE, \
53+
LIBC_THREAD_MODE_EXTERNAL.
54+
#endif
55+
4056
#if LIBC_THREAD_MODE == LIBC_THREAD_MODE_SINGLE
4157
#define LIBC_THREAD_LOCAL
4258
#else

libc/src/__support/threads/mutex.h

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,6 @@
1212
#include "src/__support/macros/attributes.h"
1313
#include "src/__support/macros/config.h"
1414

15-
#if !defined(LIBC_THREAD_MODE)
16-
#error LIBC_THREAD_MODE is undefined
17-
#endif // LIBC_THREAD_MODE
18-
19-
#if LIBC_THREAD_MODE != LIBC_THREAD_MODE_PLATFORM && \
20-
LIBC_THREAD_MODE != LIBC_THREAD_MODE_SINGLE && \
21-
LIBC_THREAD_MODE != LIBC_THREAD_MODE_EXTERNAL
22-
#error LIBC_THREAD_MODE must be one of the following values: \
23-
LIBC_THREAD_MODE_PLATFORM, \
24-
LIBC_THREAD_MODE_SINGLE, \
25-
LIBC_THREAD_MODE_EXTERNAL.
26-
#endif
27-
2815
#if LIBC_THREAD_MODE == LIBC_THREAD_MODE_PLATFORM
2916

3017
// Platform independent code will include this header file which pulls

0 commit comments

Comments
 (0)