-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[libc] add pthread_rwlock_clockrdlock and pthread_rwlock_clockwrlock … #100543
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write If you have received no comments on your PR for a week, you can request a review If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
@llvm/pr-subscribers-libc Author: Eric977 (Eric977) Changesadd pthread_rwlock_clockrdlock and pthread_rwlock_clockwrlock Full diff: https://github.com/llvm/llvm-project/pull/100543.diff 10 Files Affected:
diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt
index 2334fed773702..260424291f3ab 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -692,6 +692,8 @@ if(LLVM_LIBC_FULL_BUILD)
libc.src.pthread.pthread_mutexattr_setrobust
libc.src.pthread.pthread_mutexattr_settype
libc.src.pthread.pthread_once
+ libc.src.pthread.pthread_rwlock_clockrdlock
+ libc.src.pthread.pthread_rwlock_clockwrlock
libc.src.pthread.pthread_rwlock_destroy
libc.src.pthread.pthread_rwlock_init
libc.src.pthread.pthread_rwlock_rdlock
diff --git a/libc/config/linux/riscv/entrypoints.txt b/libc/config/linux/riscv/entrypoints.txt
index 07466805b34cd..ead1fabc397ee 100644
--- a/libc/config/linux/riscv/entrypoints.txt
+++ b/libc/config/linux/riscv/entrypoints.txt
@@ -703,6 +703,8 @@ if(LLVM_LIBC_FULL_BUILD)
libc.src.pthread.pthread_mutexattr_setrobust
libc.src.pthread.pthread_mutexattr_settype
libc.src.pthread.pthread_once
+ libc.src.pthread.pthread_rwlock_clockrdlock
+ libc.src.pthread.pthread_rwlock_clockwrlock
libc.src.pthread.pthread_rwlock_destroy
libc.src.pthread.pthread_rwlock_init
libc.src.pthread.pthread_rwlock_rdlock
diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index 035ceb8ca57bf..6911b2972f80c 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -790,6 +790,8 @@ if(LLVM_LIBC_FULL_BUILD)
libc.src.pthread.pthread_mutexattr_setrobust
libc.src.pthread.pthread_mutexattr_settype
libc.src.pthread.pthread_once
+ libc.src.pthread.pthread_rwlock_clockrdlock
+ libc.src.pthread.pthread_rwlock_clockwrlock
libc.src.pthread.pthread_rwlock_destroy
libc.src.pthread.pthread_rwlock_init
libc.src.pthread.pthread_rwlock_rdlock
diff --git a/libc/src/pthread/CMakeLists.txt b/libc/src/pthread/CMakeLists.txt
index dc748b22e0378..70d10e6c4e3f8 100644
--- a/libc/src/pthread/CMakeLists.txt
+++ b/libc/src/pthread/CMakeLists.txt
@@ -556,6 +556,28 @@ add_entrypoint_object(
libc.src.__support.threads.linux.rwlock
)
+add_entrypoint_object(
+ pthread_rwlock_clockrdlock
+ SRCS
+ pthread_rwlock_clockrdlock.cpp
+ HDRS
+ pthread_rwlock_clockrdlock.h
+ DEPENDS
+ libc.include.pthread
+ libc.src.__support.threads.linux.rwlock
+)
+
+add_entrypoint_object(
+ pthread_rwlock_clockwrlock
+ SRCS
+ pthread_rwlock_clockwrlock.cpp
+ HDRS
+ pthread_rwlock_clockwrlock.h
+ DEPENDS
+ libc.include.pthread
+ libc.src.__support.threads.linux.rwlock
+)
+
add_entrypoint_object(
pthread_rwlock_timedrdlock
SRCS
diff --git a/libc/src/pthread/pthread_rwlock_clockrdlock.cpp b/libc/src/pthread/pthread_rwlock_clockrdlock.cpp
new file mode 100644
index 0000000000000..421bbbab0011a
--- /dev/null
+++ b/libc/src/pthread/pthread_rwlock_clockrdlock.cpp
@@ -0,0 +1,51 @@
+//===-- Implementation of the Rwlock's clockrdlock function
+//--------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/pthread/pthread_rwlock_clockrdlock.h"
+
+#include "src/__support/common.h"
+#include "src/__support/macros/config.h"
+#include "src/__support/threads/linux/rwlock.h"
+
+#include <errno.h>
+#include <pthread.h>
+
+namespace LIBC_NAMESPACE_DECL {
+
+static_assert(
+ sizeof(RwLock) == sizeof(pthread_rwlock_t) &&
+ alignof(RwLock) == alignof(pthread_rwlock_t),
+ "The public pthread_rwlock_t type must be of the same size and alignment "
+ "as the internal rwlock type.");
+
+LLVM_LIBC_FUNCTION(int, pthread_rwlock_clockrdlock,
+ (pthread_rwlock_t * rwlock, clockid_t clockid,
+ const struct timespec *abstime)) {
+ if (!rwlock)
+ return EINVAL;
+ if (clockid != CLOCK_MONOTONIC && clockid != CLOCK_REALTIME)
+ return EINVAL;
+ bool is_realtime = (clockid == CLOCK_REALTIME);
+ RwLock *rw = reinterpret_cast<RwLock *>(rwlock);
+ LIBC_ASSERT(abstime && "clockrdlock called with a null timeout");
+ auto timeout = internal::AbsTimeout::from_timespec(
+ *abstime, /*is_realtime=*/is_realtime);
+ if (LIBC_LIKELY(timeout.has_value()))
+ return static_cast<int>(rw->read_lock(timeout.value()));
+
+ switch (timeout.error()) {
+ case internal::AbsTimeout::Error::Invalid:
+ return EINVAL;
+ case internal::AbsTimeout::Error::BeforeEpoch:
+ return ETIMEDOUT;
+ }
+ __builtin_unreachable();
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/pthread/pthread_rwlock_clockrdlock.h b/libc/src/pthread/pthread_rwlock_clockrdlock.h
new file mode 100644
index 0000000000000..dd11d3cdf0814
--- /dev/null
+++ b/libc/src/pthread/pthread_rwlock_clockrdlock.h
@@ -0,0 +1,23 @@
+//===-- Implementation header for Rwlock's clockrdlock function -------*-
+// C++-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC_PTHREAD_PTHREAD_RWLOCK_CLOCKRDLOCK_H
+#define LLVM_LIBC_SRC_PTHREAD_PTHREAD_RWLOCK_CLOCKRDLOCK_H
+
+#include "src/__support/macros/config.h"
+#include <pthread.h>
+
+namespace LIBC_NAMESPACE_DECL {
+
+int pthread_rwlock_clockrdlock(pthread_rwlock_t *rwlock, clockid_t clockid,
+ const struct timespec *abstime);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_PTHREAD_PTHREAD_RWLOCK_CLOCKRDLOCK_H
diff --git a/libc/src/pthread/pthread_rwlock_clockwrlock.cpp b/libc/src/pthread/pthread_rwlock_clockwrlock.cpp
new file mode 100644
index 0000000000000..8c65970670c07
--- /dev/null
+++ b/libc/src/pthread/pthread_rwlock_clockwrlock.cpp
@@ -0,0 +1,52 @@
+//===-- Implementation of the Rwlock's clockwrlock function
+//--------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/pthread/pthread_rwlock_clockwrlock.h"
+
+#include "src/__support/common.h"
+#include "src/__support/macros/config.h"
+#include "src/__support/threads/linux/rwlock.h"
+#include "src/__support/time/linux/abs_timeout.h"
+
+#include <errno.h>
+#include <pthread.h>
+
+namespace LIBC_NAMESPACE_DECL {
+
+static_assert(
+ sizeof(RwLock) == sizeof(pthread_rwlock_t) &&
+ alignof(RwLock) == alignof(pthread_rwlock_t),
+ "The public pthread_rwlock_t type must be of the same size and alignment "
+ "as the internal rwlock type.");
+
+LLVM_LIBC_FUNCTION(int, pthread_rwlock_clockwrlock,
+ (pthread_rwlock_t * rwlock, clockid_t clockid,
+ const struct timespec *abstime)) {
+ if (!rwlock)
+ return EINVAL;
+ if (clockid != CLOCK_MONOTONIC && clockid != CLOCK_REALTIME)
+ return EINVAL;
+ bool is_realtime = (clockid == CLOCK_REALTIME);
+ RwLock *rw = reinterpret_cast<RwLock *>(rwlock);
+ LIBC_ASSERT(abstime && "clockwrlock called with a null timeout");
+ auto timeout = internal::AbsTimeout::from_timespec(
+ *abstime, /*is_realtime=*/is_realtime);
+ if (LIBC_LIKELY(timeout.has_value()))
+ return static_cast<int>(rw->write_lock(timeout.value()));
+
+ switch (timeout.error()) {
+ case internal::AbsTimeout::Error::Invalid:
+ return EINVAL;
+ case internal::AbsTimeout::Error::BeforeEpoch:
+ return ETIMEDOUT;
+ }
+ __builtin_unreachable();
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/pthread/pthread_rwlock_clockwrlock.h b/libc/src/pthread/pthread_rwlock_clockwrlock.h
new file mode 100644
index 0000000000000..ee0ec15a521a9
--- /dev/null
+++ b/libc/src/pthread/pthread_rwlock_clockwrlock.h
@@ -0,0 +1,23 @@
+//===-- Implementation header for Rwlock's clockwrlock function -------*-
+// C++-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC_PTHREAD_PTHREAD_RWLOCK_CLOCKWRLOCK_H
+#define LLVM_LIBC_SRC_PTHREAD_PTHREAD_RWLOCK_CLOCKWRLOCK_H
+
+#include "src/__support/macros/config.h"
+#include <pthread.h>
+
+namespace LIBC_NAMESPACE_DECL {
+
+int pthread_rwlock_clockwrlock(pthread_rwlock_t *rwlock, clockid_t clockid,
+ const struct timespec *abstime);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_PTHREAD_PTHREAD_RWLOCK_CLOCKWRLOCK_H
diff --git a/libc/test/integration/src/pthread/CMakeLists.txt b/libc/test/integration/src/pthread/CMakeLists.txt
index fa5fd3ad55d5f..eb26822597c2f 100644
--- a/libc/test/integration/src/pthread/CMakeLists.txt
+++ b/libc/test/integration/src/pthread/CMakeLists.txt
@@ -32,9 +32,11 @@ add_integration_test(
libc.src.pthread.pthread_rwlock_rdlock
libc.src.pthread.pthread_rwlock_tryrdlock
libc.src.pthread.pthread_rwlock_timedrdlock
+ libc.src.pthread.pthread_rwlock_clockrdlock
libc.src.pthread.pthread_rwlock_wrlock
libc.src.pthread.pthread_rwlock_trywrlock
libc.src.pthread.pthread_rwlock_timedwrlock
+ libc.src.pthread.pthread_rwlock_clockwrlock
libc.src.pthread.pthread_rwlock_unlock
libc.src.pthread.pthread_create
libc.src.pthread.pthread_join
diff --git a/libc/test/integration/src/pthread/pthread_rwlock_test.cpp b/libc/test/integration/src/pthread/pthread_rwlock_test.cpp
index 455003b6af811..39194ce55fe30 100644
--- a/libc/test/integration/src/pthread/pthread_rwlock_test.cpp
+++ b/libc/test/integration/src/pthread/pthread_rwlock_test.cpp
@@ -15,6 +15,8 @@
#include "src/__support/threads/sleep.h"
#include "src/pthread/pthread_create.h"
#include "src/pthread/pthread_join.h"
+#include "src/pthread/pthread_rwlock_clockrdlock.h"
+#include "src/pthread/pthread_rwlock_clockwrlock.h"
#include "src/pthread/pthread_rwlock_destroy.h"
#include "src/pthread/pthread_rwlock_init.h"
#include "src/pthread/pthread_rwlock_rdlock.h"
@@ -112,6 +114,8 @@ static void nullptr_test() {
ASSERT_EQ(LIBC_NAMESPACE::pthread_rwlock_wrlock(nullptr), EINVAL);
ASSERT_EQ(LIBC_NAMESPACE::pthread_rwlock_timedrdlock(nullptr, &ts), EINVAL);
ASSERT_EQ(LIBC_NAMESPACE::pthread_rwlock_timedwrlock(nullptr, &ts), EINVAL);
+ ASSERT_EQ(LIBC_NAMESPACE::pthread_rwlock_clockrdlock(nullptr, &ts), EINVAL);
+ ASSERT_EQ(LIBC_NAMESPACE::pthread_rwlock_clockwrlock(nullptr, &ts), EINVAL);
ASSERT_EQ(LIBC_NAMESPACE::pthread_rwlock_tryrdlock(nullptr), EINVAL);
ASSERT_EQ(LIBC_NAMESPACE::pthread_rwlock_trywrlock(nullptr), EINVAL);
ASSERT_EQ(LIBC_NAMESPACE::pthread_rwlock_unlock(nullptr), EINVAL);
@@ -159,16 +163,26 @@ static void unusual_timespec_test() {
timespec ts = {0, -1};
ASSERT_EQ(LIBC_NAMESPACE::pthread_rwlock_timedrdlock(&rwlock, &ts), EINVAL);
ASSERT_EQ(LIBC_NAMESPACE::pthread_rwlock_timedwrlock(&rwlock, &ts), EINVAL);
+ ASSERT_EQ(LIBC_NAMESPACE::pthread_rwlock_clockrdlock(&rwlock, &ts), EINVAL);
+ ASSERT_EQ(LIBC_NAMESPACE::pthread_rwlock_clockwrlock(&rwlock, &ts), EINVAL);
ts.tv_nsec = 1'000'000'000;
ASSERT_EQ(LIBC_NAMESPACE::pthread_rwlock_timedrdlock(&rwlock, &ts), EINVAL);
+ ASSERT_EQ(LIBC_NAMESPACE::pthread_rwlock_clockrdlock(&rwlock, &ts), EINVAL);
+ ASSERT_EQ(LIBC_NAMESPACE::pthread_rwlock_clockwrlock(&rwlock, &ts), EINVAL);
ts.tv_nsec += 1;
ASSERT_EQ(LIBC_NAMESPACE::pthread_rwlock_timedwrlock(&rwlock, &ts), EINVAL);
+ ASSERT_EQ(LIBC_NAMESPACE::pthread_rwlock_clockrdlock(&rwlock, &ts), EINVAL);
+ ASSERT_EQ(LIBC_NAMESPACE::pthread_rwlock_clockwrlock(&rwlock, &ts), EINVAL);
ts.tv_nsec = 0;
ts.tv_sec = -1;
ASSERT_EQ(LIBC_NAMESPACE::pthread_rwlock_timedrdlock(&rwlock, &ts),
ETIMEDOUT);
ASSERT_EQ(LIBC_NAMESPACE::pthread_rwlock_timedwrlock(&rwlock, &ts),
ETIMEDOUT);
+ ASSERT_EQ(LIBC_NAMESPACE::pthread_rwlock_clockrdlock(&rwlock, &ts),
+ ETIMEDOUT);
+ ASSERT_EQ(LIBC_NAMESPACE::pthread_rwlock_clockwrlock(&rwlock, &ts),
+ ETIMEDOUT);
}
static void timedlock_with_deadlock_test() {
@@ -184,6 +198,9 @@ static void timedlock_with_deadlock_test() {
ASSERT_EQ(LIBC_NAMESPACE::pthread_rwlock_timedwrlock(&rwlock, &ts),
ETIMEDOUT);
ASSERT_EQ(LIBC_NAMESPACE::pthread_rwlock_timedrdlock(&rwlock, &ts), 0);
+ ASSERT_EQ(LIBC_NAMESPACE::pthread_rwlock_clockwrlock(&rwlock, &ts),
+ ETIMEDOUT);
+ ASSERT_EQ(LIBC_NAMESPACE::pthread_rwlock_clockrdlock(&rwlock, &ts), 0);
ASSERT_EQ(LIBC_NAMESPACE::pthread_rwlock_unlock(&rwlock), 0);
ASSERT_EQ(LIBC_NAMESPACE::pthread_rwlock_unlock(&rwlock), 0);
// notice that ts is already expired, but the following should still succeed.
@@ -270,9 +287,11 @@ enum class Operation : int {
WRITE = 1,
TIMED_READ = 2,
TIMED_WRITE = 3,
- TRY_READ = 4,
- TRY_WRITE = 5,
- COUNT = 6
+ CLOCK_READ = 4,
+ CLOCK_WRITE = 5,
+ TRY_READ = 6,
+ TRY_WRITE = 7,
+ COUNT = 8
};
LIBC_NAMESPACE::RawMutex *io_mutex;
@@ -358,6 +377,22 @@ static void randomized_thread_operation(SharedData *data, ThreadGuard &guard) {
}
break;
}
+ case Operation::CLOCK_READ: {
+ timespec ts = get_ts();
+ if (LIBC_NAMESPACE::pthread_rwlock_clockrdlock(&data->lock, &ts) == 0) {
+ read_ops();
+ LIBC_NAMESPACE::pthread_rwlock_unlock(&data->lock);
+ }
+ break;
+ }
+ case Operation::CLOCK_WRITE: {
+ timespec ts = get_ts();
+ if (LIBC_NAMESPACE::pthread_rwlock_clockwrlock(&data->lock, &ts) == 0) {
+ write_ops();
+ LIBC_NAMESPACE::pthread_rwlock_unlock(&data->lock);
+ }
+ break;
+ }
case Operation::TRY_READ: {
if (LIBC_NAMESPACE::pthread_rwlock_tryrdlock(&data->lock) == 0) {
read_ops();
|
Hi @SchrodingerZhu, could you please review this pull request? Thank you! |
sure. I will take a look at this ASAP |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add the function definitions to headergen:
llvm-project/libc/newhdrgen/yaml/pthread.yaml
Line 367 in dbb8b7a
- name: pthread_rwlock_timedwrlock |
and
llvm-project/libc/spec/posix.td
Line 1313 in dbb8b7a
FunctionSpec< |
Hi @SchrodingerZhu, I have add the function definitions. |
Thank you for this PR! First, my apology that I somehow break the pthread integration test in a recent patch. You can re-enable the test temporarily via the following the patch. I am trying to address this in a separate PR already. diff --git a/libc/src/__support/threads/CMakeLists.txt b/libc/src/__support/threads/CMakeLists.txt
index f1a2f162acfc..ab474b23bcbf 100644
--- a/libc/src/__support/threads/CMakeLists.txt
+++ b/libc/src/__support/threads/CMakeLists.txt
@@ -101,7 +101,7 @@ endif()
set(tid_dep)
if (LLVM_LIBC_FULL_BUILD)
- list(APPEND tid_dep libc.src.__support.thread)
+ list(APPEND tid_dep libc.src.__support.threads.thread)
else()
list(APPEND tid_dep libc.src.__support.OSUtil.osutil)
list(APPEND tid_dep libc.include.sys_syscall) You should be able to see that your integration test cases are broken due to some minor issues. Could you address them? Thank you! [162/169] Building CXX object libc/test/integration/src/pthread/CMakeFi...src.pthread.pthread_rwlock_test.__build__.dir/pthread_rwlock_test.cpp.o
FAILED: libc/test/integration/src/pthread/CMakeFiles/libc.test.integration.src.pthread.pthread_rwlock_test.__build__.dir/pthread_rwlock_test.cpp.o
sccache /usr/bin/clang++ -DLIBC_NAMESPACE=__llvm_libc_19_0_0_git -I/home/schrodinger/development/llvm-project/libc -isystem /home/schrodinger/development/llvm-project/build/libc/include -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -O2 -g -DNDEBUG -std=gnu++17 -mcpu=native -fpie -ffreestanding -fno-exceptions -fno-rtti -DLIBC_FULL_BUILD -DLIBC_COPT_RAW_MUTEX_DEFAULT_SPIN_COUNT=100 -DLIBC_COPT_TIMEOUT_ENSURE_MONOTONICITY=1 -DLIBC_COPT_ENABLE_TID_CACHE=1 -MD -MT libc/test/integration/src/pthread/CMakeFiles/libc.test.integration.src.pthread.pthread_rwlock_test.__build__.dir/pthread_rwlock_test.cpp.o -MF libc/test/integration/src/pthread/CMakeFiles/libc.test.integration.src.pthread.pthread_rwlock_test.__build__.dir/pthread_rwlock_test.cpp.o.d -o libc/test/integration/src/pthread/CMakeFiles/libc.test.integration.src.pthread.pthread_rwlock_test.__build__.dir/pthread_rwlock_test.cpp.o -c /home/schrodinger/development/llvm-project/libc/test/integration/src/pthread/pthread_rwlock_test.cpp
/home/schrodinger/development/llvm-project/libc/test/integration/src/pthread/pthread_rwlock_test.cpp:117:68: error: too few arguments to function call, expected 3, have 2
117 | ASSERT_EQ(LIBC_NAMESPACE::pthread_rwlock_clockrdlock(nullptr, &ts), EINVAL);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~
/home/schrodinger/development/llvm-project/libc/test/IntegrationTest/test.h:62:35: note: expanded from macro 'ASSERT_EQ'
62 | __CHECK_EQ(__FILE__, __LINE__, (val1), (val2), true)
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
/home/schrodinger/development/llvm-project/libc/test/IntegrationTest/test.h:33:8: note: expanded from macro '__CHECK_EQ'
33 | if ((val1) != (val2)) { \
| ^~~~
/home/schrodinger/development/llvm-project/libc/src/pthread/pthread_rwlock_clockrdlock.h:17:5: note: 'pthread_rwlock_clockrdlock' declared here
17 | int pthread_rwlock_clockrdlock(pthread_rwlock_t *__restrict rwlock,
| ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
18 | clockid_t clockid,
| ~~~~~~~~~~~~~~~~~~
19 | const timespec *__restrict abstime);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/schrodinger/development/llvm-project/libc/test/integration/src/pthread/pthread_rwlock_test.cpp:118:68: error: too few arguments to function call, expected 3, have 2
118 | ASSERT_EQ(LIBC_NAMESPACE::pthread_rwlock_clockwrlock(nullptr, &ts), EINVAL);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~
/home/schrodinger/development/llvm-project/libc/test/IntegrationTest/test.h:62:35: note: expanded from macro 'ASSERT_EQ'
62 | __CHECK_EQ(__FILE__, __LINE__, (val1), (val2), true)
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
/home/schrodinger/development/llvm-project/libc/test/IntegrationTest/test.h:33:8: note: expanded from macro '__CHECK_EQ'
33 | if ((val1) != (val2)) { \
| ^~~~
/home/schrodinger/development/llvm-project/libc/src/pthread/pthread_rwlock_clockwrlock.h:17:5: note: 'pthread_rwlock_clockwrlock' declared here
17 | int pthread_rwlock_clockwrlock(pthread_rwlock_t *__restrict rwlock,
| ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
18 | clockid_t clockid,
| ~~~~~~~~~~~~~~~~~~
19 | const timespec *__restrict abstime);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/schrodinger/development/llvm-project/libc/test/integration/src/pthread/pthread_rwlock_test.cpp:166:68: error: too few arguments to function call, expected 3, have 2
166 | ASSERT_EQ(LIBC_NAMESPACE::pthread_rwlock_clockrdlock(&rwlock, &ts), EINVAL);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~
/home/schrodinger/development/llvm-project/libc/test/IntegrationTest/test.h:62:35: note: expanded from macro 'ASSERT_EQ'
62 | __CHECK_EQ(__FILE__, __LINE__, (val1), (val2), true)
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
/home/schrodinger/development/llvm-project/libc/test/IntegrationTest/test.h:33:8: note: expanded from macro '__CHECK_EQ'
33 | if ((val1) != (val2)) { \
| ^~~~
/home/schrodinger/development/llvm-project/libc/src/pthread/pthread_rwlock_clockrdlock.h:17:5: note: 'pthread_rwlock_clockrdlock' declared here
17 | int pthread_rwlock_clockrdlock(pthread_rwlock_t *__restrict rwlock,
| ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
18 | clockid_t clockid,
| ~~~~~~~~~~~~~~~~~~
19 | const timespec *__restrict abstime);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/schrodinger/development/llvm-project/libc/test/integration/src/pthread/pthread_rwlock_test.cpp:167:68: error: too few arguments to function call, expected 3, have 2
167 | ASSERT_EQ(LIBC_NAMESPACE::pthread_rwlock_clockwrlock(&rwlock, &ts), EINVAL);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~
/home/schrodinger/development/llvm-project/libc/test/IntegrationTest/test.h:62:35: note: expanded from macro 'ASSERT_EQ'
62 | __CHECK_EQ(__FILE__, __LINE__, (val1), (val2), true)
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
/home/schrodinger/development/llvm-project/libc/test/IntegrationTest/test.h:33:8: note: expanded from macro '__CHECK_EQ'
33 | if ((val1) != (val2)) { \
| ^~~~
/home/schrodinger/development/llvm-project/libc/src/pthread/pthread_rwlock_clockwrlock.h:17:5: note: 'pthread_rwlock_clockwrlock' declared here
17 | int pthread_rwlock_clockwrlock(pthread_rwlock_t *__restrict rwlock,
| ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
18 | clockid_t clockid,
| ~~~~~~~~~~~~~~~~~~
19 | const timespec *__restrict abstime);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/schrodinger/development/llvm-project/libc/test/integration/src/pthread/pthread_rwlock_test.cpp:170:68: error: too few arguments to function call, expected 3, have 2
170 | ASSERT_EQ(LIBC_NAMESPACE::pthread_rwlock_clockrdlock(&rwlock, &ts), EINVAL);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~
/home/schrodinger/development/llvm-project/libc/test/IntegrationTest/test.h:62:35: note: expanded from macro 'ASSERT_EQ'
62 | __CHECK_EQ(__FILE__, __LINE__, (val1), (val2), true)
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
/home/schrodinger/development/llvm-project/libc/test/IntegrationTest/test.h:33:8: note: expanded from macro '__CHECK_EQ'
33 | if ((val1) != (val2)) { \
| ^~~~
/home/schrodinger/development/llvm-project/libc/src/pthread/pthread_rwlock_clockrdlock.h:17:5: note: 'pthread_rwlock_clockrdlock' declared here
17 | int pthread_rwlock_clockrdlock(pthread_rwlock_t *__restrict rwlock,
| ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
18 | clockid_t clockid,
| ~~~~~~~~~~~~~~~~~~
19 | const timespec *__restrict abstime);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/schrodinger/development/llvm-project/libc/test/integration/src/pthread/pthread_rwlock_test.cpp:171:68: error: too few arguments to function call, expected 3, have 2
171 | ASSERT_EQ(LIBC_NAMESPACE::pthread_rwlock_clockwrlock(&rwlock, &ts), EINVAL);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~
/home/schrodinger/development/llvm-project/libc/test/IntegrationTest/test.h:62:35: note: expanded from macro 'ASSERT_EQ'
62 | __CHECK_EQ(__FILE__, __LINE__, (val1), (val2), true)
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
/home/schrodinger/development/llvm-project/libc/test/IntegrationTest/test.h:33:8: note: expanded from macro '__CHECK_EQ'
33 | if ((val1) != (val2)) { \
| ^~~~
/home/schrodinger/development/llvm-project/libc/src/pthread/pthread_rwlock_clockwrlock.h:17:5: note: 'pthread_rwlock_clockwrlock' declared here
17 | int pthread_rwlock_clockwrlock(pthread_rwlock_t *__restrict rwlock,
| ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
18 | clockid_t clockid,
| ~~~~~~~~~~~~~~~~~~
19 | const timespec *__restrict abstime);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/schrodinger/development/llvm-project/libc/test/integration/src/pthread/pthread_rwlock_test.cpp:174:68: error: too few arguments to function call, expected 3, have 2
174 | ASSERT_EQ(LIBC_NAMESPACE::pthread_rwlock_clockrdlock(&rwlock, &ts), EINVAL);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~
/home/schrodinger/development/llvm-project/libc/test/IntegrationTest/test.h:62:35: note: expanded from macro 'ASSERT_EQ'
62 | __CHECK_EQ(__FILE__, __LINE__, (val1), (val2), true)
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
/home/schrodinger/development/llvm-project/libc/test/IntegrationTest/test.h:33:8: note: expanded from macro '__CHECK_EQ'
33 | if ((val1) != (val2)) { \
| ^~~~
/home/schrodinger/development/llvm-project/libc/src/pthread/pthread_rwlock_clockrdlock.h:17:5: note: 'pthread_rwlock_clockrdlock' declared here
17 | int pthread_rwlock_clockrdlock(pthread_rwlock_t *__restrict rwlock,
| ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
18 | clockid_t clockid,
| ~~~~~~~~~~~~~~~~~~
19 | const timespec *__restrict abstime);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/schrodinger/development/llvm-project/libc/test/integration/src/pthread/pthread_rwlock_test.cpp:175:68: error: too few arguments to function call, expected 3, have 2
175 | ASSERT_EQ(LIBC_NAMESPACE::pthread_rwlock_clockwrlock(&rwlock, &ts), EINVAL);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~
/home/schrodinger/development/llvm-project/libc/test/IntegrationTest/test.h:62:35: note: expanded from macro 'ASSERT_EQ'
62 | __CHECK_EQ(__FILE__, __LINE__, (val1), (val2), true)
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
/home/schrodinger/development/llvm-project/libc/test/IntegrationTest/test.h:33:8: note: expanded from macro '__CHECK_EQ'
33 | if ((val1) != (val2)) { \
| ^~~~
/home/schrodinger/development/llvm-project/libc/src/pthread/pthread_rwlock_clockwrlock.h:17:5: note: 'pthread_rwlock_clockwrlock' declared here
17 | int pthread_rwlock_clockwrlock(pthread_rwlock_t *__restrict rwlock,
| ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
18 | clockid_t clockid,
| ~~~~~~~~~~~~~~~~~~
19 | const timespec *__restrict abstime);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/schrodinger/development/llvm-project/libc/test/integration/src/pthread/pthread_rwlock_test.cpp:182:68: error: too few arguments to function call, expected 3, have 2
182 | ASSERT_EQ(LIBC_NAMESPACE::pthread_rwlock_clockrdlock(&rwlock, &ts),
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
183 | ETIMEDOUT);
| ~~~~~~~~~~
/home/schrodinger/development/llvm-project/libc/test/IntegrationTest/test.h:62:35: note: expanded from macro 'ASSERT_EQ'
62 | __CHECK_EQ(__FILE__, __LINE__, (val1), (val2), true)
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
/home/schrodinger/development/llvm-project/libc/test/IntegrationTest/test.h:33:8: note: expanded from macro '__CHECK_EQ'
33 | if ((val1) != (val2)) { \
| ^~~~
/home/schrodinger/development/llvm-project/libc/src/pthread/pthread_rwlock_clockrdlock.h:17:5: note: 'pthread_rwlock_clockrdlock' declared here
17 | int pthread_rwlock_clockrdlock(pthread_rwlock_t *__restrict rwlock,
| ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
18 | clockid_t clockid,
| ~~~~~~~~~~~~~~~~~~
19 | const timespec *__restrict abstime);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/schrodinger/development/llvm-project/libc/test/integration/src/pthread/pthread_rwlock_test.cpp:184:68: error: too few arguments to function call, expected 3, have 2
184 | ASSERT_EQ(LIBC_NAMESPACE::pthread_rwlock_clockwrlock(&rwlock, &ts),
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
185 | ETIMEDOUT);
| ~~~~~~~~~~
/home/schrodinger/development/llvm-project/libc/test/IntegrationTest/test.h:62:35: note: expanded from macro 'ASSERT_EQ'
62 | __CHECK_EQ(__FILE__, __LINE__, (val1), (val2), true)
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
/home/schrodinger/development/llvm-project/libc/test/IntegrationTest/test.h:33:8: note: expanded from macro '__CHECK_EQ'
33 | if ((val1) != (val2)) { \
| ^~~~
/home/schrodinger/development/llvm-project/libc/src/pthread/pthread_rwlock_clockwrlock.h:17:5: note: 'pthread_rwlock_clockwrlock' declared here
17 | int pthread_rwlock_clockwrlock(pthread_rwlock_t *__restrict rwlock,
| ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
18 | clockid_t clockid,
| ~~~~~~~~~~~~~~~~~~
19 | const timespec *__restrict abstime);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/schrodinger/development/llvm-project/libc/test/integration/src/pthread/pthread_rwlock_test.cpp:201:68: error: too few arguments to function call, expected 3, have 2
201 | ASSERT_EQ(LIBC_NAMESPACE::pthread_rwlock_clockwrlock(&rwlock, &ts),
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
202 | ETIMEDOUT);
| ~~~~~~~~~~
/home/schrodinger/development/llvm-project/libc/test/IntegrationTest/test.h:62:35: note: expanded from macro 'ASSERT_EQ'
62 | __CHECK_EQ(__FILE__, __LINE__, (val1), (val2), true)
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
/home/schrodinger/development/llvm-project/libc/test/IntegrationTest/test.h:33:8: note: expanded from macro '__CHECK_EQ'
33 | if ((val1) != (val2)) { \
| ^~~~
/home/schrodinger/development/llvm-project/libc/src/pthread/pthread_rwlock_clockwrlock.h:17:5: note: 'pthread_rwlock_clockwrlock' declared here
17 | int pthread_rwlock_clockwrlock(pthread_rwlock_t *__restrict rwlock,
| ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
18 | clockid_t clockid,
| ~~~~~~~~~~~~~~~~~~
19 | const timespec *__restrict abstime);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/schrodinger/development/llvm-project/libc/test/integration/src/pthread/pthread_rwlock_test.cpp:203:68: error: too few arguments to function call, expected 3, have 2
203 | ASSERT_EQ(LIBC_NAMESPACE::pthread_rwlock_clockrdlock(&rwlock, &ts), 0);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
/home/schrodinger/development/llvm-project/libc/test/IntegrationTest/test.h:62:35: note: expanded from macro 'ASSERT_EQ'
62 | __CHECK_EQ(__FILE__, __LINE__, (val1), (val2), true)
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
/home/schrodinger/development/llvm-project/libc/test/IntegrationTest/test.h:33:8: note: expanded from macro '__CHECK_EQ'
33 | if ((val1) != (val2)) { \
| ^~~~
/home/schrodinger/development/llvm-project/libc/src/pthread/pthread_rwlock_clockrdlock.h:17:5: note: 'pthread_rwlock_clockrdlock' declared here
17 | int pthread_rwlock_clockrdlock(pthread_rwlock_t *__restrict rwlock,
| ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
18 | clockid_t clockid,
| ~~~~~~~~~~~~~~~~~~
19 | const timespec *__restrict abstime);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/schrodinger/development/llvm-project/libc/test/integration/src/pthread/pthread_rwlock_test.cpp:382:68: error: too few arguments to function call, expected 3, have 2
382 | if (LIBC_NAMESPACE::pthread_rwlock_clockrdlock(&data->lock, &ts) == 0) {
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^
/home/schrodinger/development/llvm-project/libc/src/pthread/pthread_rwlock_clockrdlock.h:17:5: note: 'pthread_rwlock_clockrdlock' declared here
17 | int pthread_rwlock_clockrdlock(pthread_rwlock_t *__restrict rwlock,
| ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
18 | clockid_t clockid,
| ~~~~~~~~~~~~~~~~~~
19 | const timespec *__restrict abstime);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/schrodinger/development/llvm-project/libc/test/integration/src/pthread/pthread_rwlock_test.cpp:390:68: error: too few arguments to function call, expected 3, have 2
390 | if (LIBC_NAMESPACE::pthread_rwlock_clockwrlock(&data->lock, &ts) == 0) {
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^
/home/schrodinger/development/llvm-project/libc/src/pthread/pthread_rwlock_clockwrlock.h:17:5: note: 'pthread_rwlock_clockwrlock' declared here
17 | int pthread_rwlock_clockwrlock(pthread_rwlock_t *__restrict rwlock,
| ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
18 | clockid_t clockid,
| ~~~~~~~~~~~~~~~~~~
19 | const timespec *__restrict abstime);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
14 errors generated.
[165/169] Running integration test libc.test.integration.src.pthread.pthread_test
ninja: build stopped: subcommand failed. |
Could you also add the following to our documentation? Thank you! diff --git a/libc/docs/dev/undefined_behavior.rst b/libc/docs/dev/undefined_behavior.rst
index b712780222aa..6c3963f069bb 100644
--- a/libc/docs/dev/undefined_behavior.rst
+++ b/libc/docs/dev/undefined_behavior.rst
@@ -116,3 +116,8 @@ inherited from parent process triggered inside the instruction window between ``
and ``exec*``. As libc failed to maintain its internal states correctly, even though the
functions used inside the signal handlers are marked as ``async-signal-safe`` (such as
``getpid``), they will still return wrong values or lead to other even worse situations.
+
+Unrecognized ``clockid_t`` values for ``pthread_rwlock_clock*`` APIs
+----------------------------------------------------------------------
+POSIX.1-2024 only demands support for ``CLOCK_REALTIME`` and ``CLOCK_MONOTONIC``. Currently,
+as in LLVM libc, if other clock ids are used, they will be treated as monotonic clocks. |
Sorry, I have rebase to resolve conflict, nothing change for previous three commit. |
✅ With the latest revision this PR passed the C/C++ code formatter. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@Eric977 Congratulations on having your first Pull Request (PR) merged into the LLVM Project! Your changes will be combined with recent changes from other authors, then tested Please check whether problems have been caused by your change specifically, as How to do this, and the rest of the post-merge process, is covered in detail here. If your change does cause a problem, it may be reverted, or you can revert it yourself. If you don't get any reports, no action is required from you. Your changes are working as expected, well done! |
Thank you for the patch |
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/71/builds/3242 Here is the relevant piece of the build log for the reference:
|
add pthread_rwlock_clockrdlock and pthread_rwlock_clockwrlock
#99697