Skip to content

Commit 1254b65

Browse files
committed
Switch mutex implementation to match errno's implementation
1 parent d47e596 commit 1254b65

File tree

12 files changed

+88
-80
lines changed

12 files changed

+88
-80
lines changed

libc/cmake/modules/LLVMLibCCompileOptionRules.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,10 @@ function(_get_compile_options_from_config output_var)
110110
list(APPEND config_options "-DLIBC_ERRNO_MODE=${LIBC_CONF_ERRNO_MODE}")
111111
endif()
112112

113+
if(LIBC_CONF_THREAD_MODE)
114+
list(APPEND config_options "-DLIBC_THREAD_MODE=${LIBC_CONF_THREAD_MODE}")
115+
endif()
116+
113117
set(${output_var} ${config_options} PARENT_SCOPE)
114118
endfunction(_get_compile_options_from_config)
115119

libc/config/baremetal/config.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
"value": "LIBC_ERRNO_MODE_EXTERNAL"
55
}
66
},
7+
"threads": {
8+
"LIBC_CONF_THREAD_MODE": {
9+
"value": "LIBC_THREAD_MODE_SINGLE"
10+
}
11+
},
712
"printf": {
813
"LIBC_CONF_PRINTF_DISABLE_FIXED_POINT": {
914
"value": true

libc/config/config.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55
"doc": "The implementation used for errno, acceptable values are LIBC_ERRNO_MODE_DEFAULT, LIBC_ERRNO_MODE_UNDEFINED, LIBC_ERRNO_MODE_THREAD_LOCAL, LIBC_ERRNO_MODE_SHARED, LIBC_ERRNO_MODE_EXTERNAL, LIBC_ERRNO_MODE_SYSTEM, and LIBC_ERRNO_MODE_SYSTEM_INLINE."
66
}
77
},
8+
"threads": {
9+
"LIBC_CONF_THREAD_MODE": {
10+
"value": "LIBC_THREAD_MODE_PLATFORM",
11+
"doc": "The implementation used for Mutex, acceptable values are LIBC_THREAD_MODE_PLATFORM, LIBC_THREAD_MODE_SINGLE, and LIBC_THREAD_MODE_EXTERNAL."
12+
}
13+
},
814
"printf": {
915
"LIBC_CONF_PRINTF_DISABLE_FLOAT": {
1016
"value": false,

libc/config/gpu/amdgpu/config.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
"value": "LIBC_ERRNO_MODE_SHARED"
55
}
66
},
7+
"threads": {
8+
"LIBC_CONF_THREAD_MODE": {
9+
"value": "LIBC_THREAD_MODE_SINGLE"
10+
}
11+
},
712
"printf": {
813
"LIBC_CONF_PRINTF_DISABLE_FLOAT": {
914
"value": true

libc/config/gpu/nvptx/config.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
"value": "LIBC_ERRNO_MODE_SHARED"
55
}
66
},
7+
"threads": {
8+
"LIBC_CONF_THREAD_MODE": {
9+
"value": "LIBC_THREAD_MODE_SINGLE"
10+
}
11+
},
712
"printf": {
813
"LIBC_CONF_PRINTF_DISABLE_FLOAT": {
914
"value": true

libc/docs/configure.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,7 @@ to learn about the defaults for your platform and target.
6060
* **"string" options**
6161
- ``LIBC_CONF_MEMSET_X86_USE_SOFTWARE_PREFETCHING``: Inserts prefetch for write instructions (PREFETCHW) for memset on x86 to recover performance when hardware prefetcher is disabled.
6262
- ``LIBC_CONF_STRING_UNSAFE_WIDE_READ``: Read more than a byte at a time to perform byte-string operations like strlen.
63+
* **"threads" options**
64+
- ``LIBC_CONF_THREAD_MODE``: The implementation used for Mutex, acceptable values are LIBC_THREAD_MODE_PLATFORM, LIBC_THREAD_MODE_SINGLE, and LIBC_THREAD_MODE_EXTERNAL.
6365
* **"time" options**
6466
- ``LIBC_CONF_TIME_64BIT``: Force the size of time_t to 64 bits, even on platforms where compatibility considerations would otherwise make it 32-bit.

libc/src/__support/threads/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@ if(TARGET libc.src.__support.threads.${LIBC_TARGET_OS}.mutex)
4242
.mutex
4343
libc.src.__support.CPP.mutex
4444
)
45+
elseif(NOT (LIBC_CONF_THREAD_MODE STREQUAL LIBC_THREAD_MODE_PLATFORM))
46+
add_header_library(
47+
mutex
48+
HDRS
49+
mutex.h
50+
DEPENDS
51+
.mutex_common
52+
)
4553
endif()
4654

4755
add_header_library(

libc/src/__support/threads/baremetal/CMakeLists.txt

Lines changed: 0 additions & 5 deletions
This file was deleted.

libc/src/__support/threads/baremetal/mutex.h

Lines changed: 0 additions & 32 deletions
This file was deleted.

libc/src/__support/threads/gpu/CMakeLists.txt

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)