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:
parent
e75f285bd1
commit
a10f96e153
9 changed files with 16 additions and 29 deletions
|
@ -256,7 +256,7 @@ int pthread_condattr_init(pthread_condattr_t *att)
|
|||
return EINVAL;
|
||||
}
|
||||
|
||||
attr->clock = CLOCK_MONOTONIC;
|
||||
attr->clock = CLOCK_REALTIME;
|
||||
attr->initialized = true;
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -263,7 +263,8 @@ int mq_timedsend(mqd_t mqdes, const char *msg_ptr, size_t msg_len,
|
|||
return -1;
|
||||
}
|
||||
|
||||
return send_message(mqd, msg_ptr, msg_len, K_MSEC(timespec_to_timeoutms(abstime)));
|
||||
return send_message(mqd, msg_ptr, msg_len,
|
||||
K_MSEC(timespec_to_clock_timeoutms(CLOCK_REALTIME, abstime)));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -298,7 +299,8 @@ int mq_timedreceive(mqd_t mqdes, char *msg_ptr, size_t msg_len,
|
|||
return -1;
|
||||
}
|
||||
|
||||
return receive_message(mqd, msg_ptr, msg_len, K_MSEC(timespec_to_timeoutms(abstime)));
|
||||
return receive_message(mqd, msg_ptr, msg_len,
|
||||
K_MSEC(timespec_to_clock_timeoutms(CLOCK_REALTIME, abstime)));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -216,7 +216,7 @@ int pthread_mutex_timedlock(pthread_mutex_t *m,
|
|||
return EINVAL;
|
||||
}
|
||||
|
||||
return acquire_mutex(m, K_MSEC(timespec_to_timeoutms(abstime)));
|
||||
return acquire_mutex(m, K_MSEC(timespec_to_clock_timeoutms(CLOCK_REALTIME, abstime)));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1154,7 +1154,8 @@ int pthread_timedjoin_np(pthread_t pthread, void **status, const struct timespec
|
|||
return EINVAL;
|
||||
}
|
||||
|
||||
return pthread_timedjoin_internal(pthread, status, K_MSEC(timespec_to_timeoutms(abstime)));
|
||||
return pthread_timedjoin_internal(
|
||||
pthread, status, K_MSEC(timespec_to_clock_timeoutms(CLOCK_REALTIME, abstime)));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -211,7 +211,7 @@ int pthread_rwlock_timedrdlock(pthread_rwlock_t *rwlock,
|
|||
return EINVAL;
|
||||
}
|
||||
|
||||
if (read_lock_acquire(rwl, timespec_to_timeoutms(abstime)) != 0U) {
|
||||
if (read_lock_acquire(rwl, timespec_to_clock_timeoutms(CLOCK_REALTIME, abstime)) != 0U) {
|
||||
ret = ETIMEDOUT;
|
||||
}
|
||||
|
||||
|
@ -282,7 +282,7 @@ int pthread_rwlock_timedwrlock(pthread_rwlock_t *rwlock,
|
|||
return EINVAL;
|
||||
}
|
||||
|
||||
if (write_lock_acquire(rwl, timespec_to_timeoutms(abstime)) != 0U) {
|
||||
if (write_lock_acquire(rwl, timespec_to_clock_timeoutms(CLOCK_REALTIME, abstime)) != 0U) {
|
||||
ret = ETIMEDOUT;
|
||||
}
|
||||
|
||||
|
|
|
@ -161,29 +161,12 @@ int sem_post(sem_t *semaphore)
|
|||
*/
|
||||
int sem_timedwait(sem_t *semaphore, struct timespec *abstime)
|
||||
{
|
||||
int32_t timeout;
|
||||
struct timespec current;
|
||||
int64_t current_ms, abstime_ms;
|
||||
|
||||
if ((abstime == NULL) || !timespec_is_valid(abstime)) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (clock_gettime(CLOCK_REALTIME, ¤t) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
abstime_ms = (int64_t)_ts_to_ms(abstime);
|
||||
current_ms = (int64_t)_ts_to_ms(¤t);
|
||||
|
||||
if (abstime_ms <= current_ms) {
|
||||
timeout = 0;
|
||||
} else {
|
||||
timeout = (int32_t)(abstime_ms - current_ms);
|
||||
}
|
||||
|
||||
if (k_sem_take(semaphore, K_MSEC(timeout))) {
|
||||
if (k_sem_take(semaphore, K_MSEC(timespec_to_clock_timeoutms(CLOCK_REALTIME, abstime)))) {
|
||||
errno = ETIMEDOUT;
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue