posix: always require clockid_t argument to timespec_to_timeoutms()

Always require the clockid_t argument to timespec_to_timeoutms() and
remove the unused variant that accepts no clockid_t parameter.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
This commit is contained in:
Chris Friedt 2025-04-23 09:16:54 -04:00 committed by Benjamin Cabé
commit 615ae7e1b5
8 changed files with 11 additions and 17 deletions

View file

@ -105,7 +105,7 @@ static int cond_wait(pthread_cond_t *cond, pthread_mutex_t *mu, const struct tim
} }
if (abstime != NULL) { if (abstime != NULL) {
timeout = K_MSEC(timespec_to_clock_timeoutms(cv->attr.clock, abstime)); timeout = K_MSEC(timespec_to_timeoutms(cv->attr.clock, abstime));
} }
LOG_DBG("Waiting on cond %p with timeout %llx", cv, timeout.ticks); LOG_DBG("Waiting on cond %p with timeout %llx", cv, timeout.ticks);

View file

@ -264,7 +264,7 @@ int mq_timedsend(mqd_t mqdes, const char *msg_ptr, size_t msg_len,
} }
return send_message(mqd, msg_ptr, msg_len, return send_message(mqd, msg_ptr, msg_len,
K_MSEC(timespec_to_clock_timeoutms(CLOCK_REALTIME, abstime))); K_MSEC(timespec_to_timeoutms(CLOCK_REALTIME, abstime)));
} }
/** /**
@ -300,7 +300,7 @@ int mq_timedreceive(mqd_t mqdes, char *msg_ptr, size_t msg_len,
} }
return receive_message(mqd, msg_ptr, msg_len, return receive_message(mqd, msg_ptr, msg_len,
K_MSEC(timespec_to_clock_timeoutms(CLOCK_REALTIME, abstime))); K_MSEC(timespec_to_timeoutms(CLOCK_REALTIME, abstime)));
} }
/** /**

View file

@ -216,7 +216,7 @@ int pthread_mutex_timedlock(pthread_mutex_t *m,
return EINVAL; return EINVAL;
} }
return acquire_mutex(m, K_MSEC(timespec_to_clock_timeoutms(CLOCK_REALTIME, abstime))); return acquire_mutex(m, K_MSEC(timespec_to_timeoutms(CLOCK_REALTIME, abstime)));
} }
/** /**

View file

@ -22,8 +22,7 @@ static inline bool timespec_is_valid(const struct timespec *ts)
return (ts->tv_nsec >= 0) && (ts->tv_nsec < NSEC_PER_SEC); return (ts->tv_nsec >= 0) && (ts->tv_nsec < NSEC_PER_SEC);
} }
uint32_t timespec_to_clock_timeoutms(clockid_t clock_id, const struct timespec *abstime); uint32_t timespec_to_timeoutms(clockid_t clock_id, const struct timespec *abstime);
uint32_t timespec_to_timeoutms(const struct timespec *abstime);
__syscall int __posix_clock_get_base(clockid_t clock_id, struct timespec *ts); __syscall int __posix_clock_get_base(clockid_t clock_id, struct timespec *ts);

View file

@ -1154,8 +1154,8 @@ int pthread_timedjoin_np(pthread_t pthread, void **status, const struct timespec
return EINVAL; return EINVAL;
} }
return pthread_timedjoin_internal( return pthread_timedjoin_internal(pthread, status,
pthread, status, K_MSEC(timespec_to_clock_timeoutms(CLOCK_REALTIME, abstime))); K_MSEC(timespec_to_timeoutms(CLOCK_REALTIME, abstime)));
} }
/** /**

View file

@ -211,7 +211,7 @@ int pthread_rwlock_timedrdlock(pthread_rwlock_t *rwlock,
return EINVAL; return EINVAL;
} }
if (read_lock_acquire(rwl, timespec_to_clock_timeoutms(CLOCK_REALTIME, abstime)) != 0U) { if (read_lock_acquire(rwl, timespec_to_timeoutms(CLOCK_REALTIME, abstime)) != 0U) {
ret = ETIMEDOUT; ret = ETIMEDOUT;
} }
@ -282,7 +282,7 @@ int pthread_rwlock_timedwrlock(pthread_rwlock_t *rwlock,
return EINVAL; return EINVAL;
} }
if (write_lock_acquire(rwl, timespec_to_clock_timeoutms(CLOCK_REALTIME, abstime)) != 0U) { if (write_lock_acquire(rwl, timespec_to_timeoutms(CLOCK_REALTIME, abstime)) != 0U) {
ret = ETIMEDOUT; ret = ETIMEDOUT;
} }

View file

@ -166,7 +166,7 @@ int sem_timedwait(sem_t *semaphore, struct timespec *abstime)
return -1; return -1;
} }
if (k_sem_take(semaphore, K_MSEC(timespec_to_clock_timeoutms(CLOCK_REALTIME, abstime)))) { if (k_sem_take(semaphore, K_MSEC(timespec_to_timeoutms(CLOCK_REALTIME, abstime)))) {
errno = ETIMEDOUT; errno = ETIMEDOUT;
return -1; return -1;
} }

View file

@ -10,7 +10,7 @@
#include <ksched.h> #include <ksched.h>
#include <zephyr/posix/time.h> #include <zephyr/posix/time.h>
uint32_t timespec_to_clock_timeoutms(clockid_t clock_id, const struct timespec *abstime) uint32_t timespec_to_timeoutms(clockid_t clock_id, const struct timespec *abstime)
{ {
int64_t milli_secs, secs, nsecs; int64_t milli_secs, secs, nsecs;
struct timespec curtime; struct timespec curtime;
@ -27,8 +27,3 @@ uint32_t timespec_to_clock_timeoutms(clockid_t clock_id, const struct timespec *
return milli_secs; return milli_secs;
} }
uint32_t timespec_to_timeoutms(const struct timespec *abstime)
{
return timespec_to_clock_timeoutms(CLOCK_MONOTONIC, abstime);
}