Skip to content

Commit 32190b0

Browse files
author
Yifan Zhu
committed
[libc] add rwlock implementation
1 parent c26a993 commit 32190b0

File tree

4 files changed

+540
-5
lines changed

4 files changed

+540
-5
lines changed

libc/config/config.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@
4949
"LIBC_CONF_RAW_MUTEX_DEFAULT_SPIN_COUNT": {
5050
"value": 100,
5151
"doc": "Default number of spins before blocking if a mutex is in contention (default to 100)."
52+
},
53+
"LIBC_CONF_RWLOCK_DEFAULT_SPIN_COUNT": {
54+
"value": 100,
55+
"doc": "Default number of spins before blocking if a rwlock is in contention (default to 100)."
5256
}
5357
}
5458
}

libc/docs/configure.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ to learn about the defaults for your platform and target.
3636
- ``LIBC_CONF_PRINTF_FLOAT_TO_STR_USE_MEGA_LONG_DOUBLE_TABLE``: Use large table for better printf long double performance.
3737
* **"pthread" options**
3838
- ``LIBC_CONF_RAW_MUTEX_DEFAULT_SPIN_COUNT``: Default number of spins before blocking if a mutex is in contention (default to 100).
39+
- ``LIBC_CONF_RWLOCK_DEFAULT_SPIN_COUNT``: Default number of spins before blocking if a rwlock is in contention (default to 100).
3940
- ``LIBC_CONF_TIMEOUT_ENSURE_MONOTONICITY``: Automatically adjust timeout to CLOCK_MONOTONIC (default to true). POSIX API may require CLOCK_REALTIME, which can be unstable and leading to unexpected behavior. This option will convert the real-time timestamp to monotonic timestamp relative to the time of call.
4041
* **"string" options**
4142
- ``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.

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

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ add_header_library(
2222
libc.src.__support.time.linux.abs_timeout
2323
)
2424

25-
set(raw_mutex_additional_flags)
25+
set(monotonicity_flags)
2626
if (LIBC_CONF_TIMEOUT_ENSURE_MONOTONICITY)
27-
set(raw_mutex_additional_flags -DLIBC_COPT_TIMEOUT_ENSURE_MONOTONICITY=1)
27+
set(monotonicity_flags -DLIBC_COPT_TIMEOUT_ENSURE_MONOTONICITY=1)
2828
else()
29-
set(raw_mutex_additional_flags -DLIBC_COPT_TIMEOUT_ENSURE_MONOTONICITY=0)
29+
set(monotonicity_flags -DLIBC_COPT_TIMEOUT_ENSURE_MONOTONICITY=0)
3030
endif()
3131

3232
add_header_library(
@@ -42,8 +42,19 @@ add_header_library(
4242
libc.hdr.types.pid_t
4343
COMPILE_OPTIONS
4444
-DLIBC_COPT_RAW_MUTEX_DEFAULT_SPIN_COUNT=${LIBC_CONF_RAW_MUTEX_DEFAULT_SPIN_COUNT}
45-
${raw_mutex_additional_flags}
46-
45+
${monotonicity_flags}
46+
)
47+
48+
add_header_library(
49+
rwlock
50+
HDRS
51+
rwlock.h
52+
DEPENDS
53+
.futex_utils
54+
.raw_mutex
55+
COMPILE_OPTIONS
56+
-DLIBC_COPT_RWLOCK_DEFAULT_SPIN_COUNT=${LIBC_CONF_RWLOCK_DEFAULT_SPIN_COUNT}
57+
${monotonicity_flags}
4758
)
4859

4960
add_header_library(

0 commit comments

Comments
 (0)