Skip to content

Commit dfbabc6

Browse files
b08902132Eric977
authored andcommitted
fix wrong function parameter
1 parent bdeaaa2 commit dfbabc6

File tree

2 files changed

+19
-14
lines changed

2 files changed

+19
-14
lines changed

libc/docs/dev/undefined_behavior.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,8 @@ direction in this case.
9393
Non-const Constant Return Values
9494
--------------------------------
9595
Some libc functions, like ``dlerror()``, return ``char *`` instead of ``const char *`` and then tell the caller they promise not to to modify this value. Any modification of this value is undefined behavior.
96+
97+
Unrecognized ``clockid_t`` values for ``pthread_rwlock_clock*`` APIs
98+
----------------------------------------------------------------------
99+
POSIX.1-2024 only demands support for ``CLOCK_REALTIME`` and ``CLOCK_MONOTONIC``. Currently,
100+
as in LLVM libc, if other clock ids are used, they will be treated as monotonic clocks.

libc/test/integration/src/pthread/pthread_rwlock_test.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ static void nullptr_test() {
114114
ASSERT_EQ(LIBC_NAMESPACE::pthread_rwlock_wrlock(nullptr), EINVAL);
115115
ASSERT_EQ(LIBC_NAMESPACE::pthread_rwlock_timedrdlock(nullptr, &ts), EINVAL);
116116
ASSERT_EQ(LIBC_NAMESPACE::pthread_rwlock_timedwrlock(nullptr, &ts), EINVAL);
117-
ASSERT_EQ(LIBC_NAMESPACE::pthread_rwlock_clockrdlock(nullptr, &ts), EINVAL);
118-
ASSERT_EQ(LIBC_NAMESPACE::pthread_rwlock_clockwrlock(nullptr, &ts), EINVAL);
117+
ASSERT_EQ(LIBC_NAMESPACE::pthread_rwlock_clockrdlock(nullptr, CLOCK_MONOTONIC, &ts), EINVAL);
118+
ASSERT_EQ(LIBC_NAMESPACE::pthread_rwlock_clockwrlock(nullptr, CLOCK_MONOTONIC, &ts), EINVAL);
119119
ASSERT_EQ(LIBC_NAMESPACE::pthread_rwlock_tryrdlock(nullptr), EINVAL);
120120
ASSERT_EQ(LIBC_NAMESPACE::pthread_rwlock_trywrlock(nullptr), EINVAL);
121121
ASSERT_EQ(LIBC_NAMESPACE::pthread_rwlock_unlock(nullptr), EINVAL);
@@ -163,25 +163,25 @@ static void unusual_timespec_test() {
163163
timespec ts = {0, -1};
164164
ASSERT_EQ(LIBC_NAMESPACE::pthread_rwlock_timedrdlock(&rwlock, &ts), EINVAL);
165165
ASSERT_EQ(LIBC_NAMESPACE::pthread_rwlock_timedwrlock(&rwlock, &ts), EINVAL);
166-
ASSERT_EQ(LIBC_NAMESPACE::pthread_rwlock_clockrdlock(&rwlock, &ts), EINVAL);
167-
ASSERT_EQ(LIBC_NAMESPACE::pthread_rwlock_clockwrlock(&rwlock, &ts), EINVAL);
166+
ASSERT_EQ(LIBC_NAMESPACE::pthread_rwlock_clockrdlock(&rwlock, CLOCK_MONOTONIC, &ts), EINVAL);
167+
ASSERT_EQ(LIBC_NAMESPACE::pthread_rwlock_clockwrlock(&rwlock, CLOCK_MONOTONIC, &ts), EINVAL);
168168
ts.tv_nsec = 1'000'000'000;
169169
ASSERT_EQ(LIBC_NAMESPACE::pthread_rwlock_timedrdlock(&rwlock, &ts), EINVAL);
170-
ASSERT_EQ(LIBC_NAMESPACE::pthread_rwlock_clockrdlock(&rwlock, &ts), EINVAL);
171-
ASSERT_EQ(LIBC_NAMESPACE::pthread_rwlock_clockwrlock(&rwlock, &ts), EINVAL);
170+
ASSERT_EQ(LIBC_NAMESPACE::pthread_rwlock_clockrdlock(&rwlock, CLOCK_MONOTONIC, &ts), EINVAL);
171+
ASSERT_EQ(LIBC_NAMESPACE::pthread_rwlock_clockwrlock(&rwlock, CLOCK_MONOTONIC, &ts), EINVAL);
172172
ts.tv_nsec += 1;
173173
ASSERT_EQ(LIBC_NAMESPACE::pthread_rwlock_timedwrlock(&rwlock, &ts), EINVAL);
174-
ASSERT_EQ(LIBC_NAMESPACE::pthread_rwlock_clockrdlock(&rwlock, &ts), EINVAL);
175-
ASSERT_EQ(LIBC_NAMESPACE::pthread_rwlock_clockwrlock(&rwlock, &ts), EINVAL);
174+
ASSERT_EQ(LIBC_NAMESPACE::pthread_rwlock_clockrdlock(&rwlock, CLOCK_MONOTONIC, &ts), EINVAL);
175+
ASSERT_EQ(LIBC_NAMESPACE::pthread_rwlock_clockwrlock(&rwlock, CLOCK_MONOTONIC, &ts), EINVAL);
176176
ts.tv_nsec = 0;
177177
ts.tv_sec = -1;
178178
ASSERT_EQ(LIBC_NAMESPACE::pthread_rwlock_timedrdlock(&rwlock, &ts),
179179
ETIMEDOUT);
180180
ASSERT_EQ(LIBC_NAMESPACE::pthread_rwlock_timedwrlock(&rwlock, &ts),
181181
ETIMEDOUT);
182-
ASSERT_EQ(LIBC_NAMESPACE::pthread_rwlock_clockrdlock(&rwlock, &ts),
182+
ASSERT_EQ(LIBC_NAMESPACE::pthread_rwlock_clockrdlock(&rwlock, CLOCK_MONOTONIC, &ts),
183183
ETIMEDOUT);
184-
ASSERT_EQ(LIBC_NAMESPACE::pthread_rwlock_clockwrlock(&rwlock, &ts),
184+
ASSERT_EQ(LIBC_NAMESPACE::pthread_rwlock_clockwrlock(&rwlock, CLOCK_MONOTONIC, &ts),
185185
ETIMEDOUT);
186186
}
187187

@@ -198,9 +198,9 @@ static void timedlock_with_deadlock_test() {
198198
ASSERT_EQ(LIBC_NAMESPACE::pthread_rwlock_timedwrlock(&rwlock, &ts),
199199
ETIMEDOUT);
200200
ASSERT_EQ(LIBC_NAMESPACE::pthread_rwlock_timedrdlock(&rwlock, &ts), 0);
201-
ASSERT_EQ(LIBC_NAMESPACE::pthread_rwlock_clockwrlock(&rwlock, &ts),
201+
ASSERT_EQ(LIBC_NAMESPACE::pthread_rwlock_clockwrlock(&rwlock, CLOCK_MONOTONIC, &ts),
202202
ETIMEDOUT);
203-
ASSERT_EQ(LIBC_NAMESPACE::pthread_rwlock_clockrdlock(&rwlock, &ts), 0);
203+
ASSERT_EQ(LIBC_NAMESPACE::pthread_rwlock_clockrdlock(&rwlock, CLOCK_MONOTONIC, &ts), 0);
204204
ASSERT_EQ(LIBC_NAMESPACE::pthread_rwlock_unlock(&rwlock), 0);
205205
ASSERT_EQ(LIBC_NAMESPACE::pthread_rwlock_unlock(&rwlock), 0);
206206
// notice that ts is already expired, but the following should still succeed.
@@ -379,15 +379,15 @@ static void randomized_thread_operation(SharedData *data, ThreadGuard &guard) {
379379
}
380380
case Operation::CLOCK_READ: {
381381
timespec ts = get_ts();
382-
if (LIBC_NAMESPACE::pthread_rwlock_clockrdlock(&data->lock, &ts) == 0) {
382+
if (LIBC_NAMESPACE::pthread_rwlock_clockrdlock(&data->lock, CLOCK_MONOTONIC, &ts) == 0) {
383383
read_ops();
384384
LIBC_NAMESPACE::pthread_rwlock_unlock(&data->lock);
385385
}
386386
break;
387387
}
388388
case Operation::CLOCK_WRITE: {
389389
timespec ts = get_ts();
390-
if (LIBC_NAMESPACE::pthread_rwlock_clockwrlock(&data->lock, &ts) == 0) {
390+
if (LIBC_NAMESPACE::pthread_rwlock_clockwrlock(&data->lock, CLOCK_MONOTONIC, &ts) == 0) {
391391
write_ops();
392392
LIBC_NAMESPACE::pthread_rwlock_unlock(&data->lock);
393393
}

0 commit comments

Comments
 (0)