posix + tests: use CLOCK_REALTIME where specified by POSIX

Use CLOCK_REALTIME for the default clock source throughout
the POSIX implementation and tests so that we are
consistent with the specification.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
This commit is contained in:
Chris Friedt 2025-04-23 09:09:50 -04:00 committed by Benjamin Cabé
commit a10f96e153
9 changed files with 16 additions and 29 deletions

View file

@ -71,7 +71,7 @@ static int test_cnd_thread_fn(void *arg)
struct libc_cnd_fixture *const fixture = arg;
if (fixture->do_timedwait) {
zassume_ok(clock_gettime(CLOCK_MONOTONIC, &time_point));
zassume_ok(clock_gettime(CLOCK_REALTIME, &time_point));
timespec_add_ms(&time_point, WAIT_TIME_MS);
res = cnd_timedwait(&fixture->cond, &fixture->mutex, &time_point);
} else {

View file

@ -55,7 +55,7 @@ ZTEST(cond, test_pthread_condattr)
zassert_ok(pthread_condattr_init(&att));
zassert_ok(pthread_condattr_getclock(&att, &clock_id), "pthread_condattr_getclock failed");
zassert_equal(clock_id, CLOCK_MONOTONIC, "clock attribute not set correctly");
zassert_equal(clock_id, CLOCK_REALTIME, "clock attribute not set correctly");
zassert_ok(pthread_condattr_setclock(&att, CLOCK_REALTIME),
"pthread_condattr_setclock failed");

View file

@ -86,8 +86,9 @@ ZTEST(posix_rw_locks, test_rw_lock)
usleep(USEC_PER_MSEC);
LOG_DBG("Parent thread acquiring WR lock again");
time.tv_sec = 2;
time.tv_nsec = 0;
zassert_ok(clock_gettime(CLOCK_REALTIME, &time));
time.tv_sec += 2;
ret = pthread_rwlock_timedwrlock(&rwlock, &time);
if (ret) {
zassert_ok(pthread_rwlock_wrlock(&rwlock), "Failed to acquire write lock");