posix: declare timespec_to_timeoutms() in posix_clock.h
Provide a single declaration of timespec_to_timeoutms() (which is a private function), in the private header file posix_clock.h . Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
This commit is contained in:
parent
3d146aed05
commit
fffbd76683
7 changed files with 22 additions and 29 deletions
|
@ -15,8 +15,6 @@
|
|||
|
||||
LOG_MODULE_REGISTER(pthread_cond, CONFIG_PTHREAD_COND_LOG_LEVEL);
|
||||
|
||||
int64_t timespec_to_timeoutms(const struct timespec *abstime);
|
||||
|
||||
__pinned_bss
|
||||
static struct k_condvar posix_cond_pool[CONFIG_MAX_PTHREAD_COND_COUNT];
|
||||
|
||||
|
@ -168,7 +166,7 @@ int pthread_cond_wait(pthread_cond_t *cv, pthread_mutex_t *mut)
|
|||
|
||||
int pthread_cond_timedwait(pthread_cond_t *cv, pthread_mutex_t *mut, const struct timespec *abstime)
|
||||
{
|
||||
return cond_wait(cv, mut, K_MSEC((int32_t)timespec_to_timeoutms(abstime)));
|
||||
return cond_wait(cv, mut, K_MSEC(timespec_to_timeoutms(abstime)));
|
||||
}
|
||||
|
||||
int pthread_cond_init(pthread_cond_t *cvar, const pthread_condattr_t *att)
|
||||
|
|
|
@ -4,6 +4,9 @@
|
|||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include "posix_clock.h"
|
||||
|
||||
#include <zephyr/kernel.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
|
@ -34,7 +37,6 @@ K_SEM_DEFINE(mq_sem, 1, 1);
|
|||
/* Initialize the list */
|
||||
sys_slist_t mq_list = SYS_SLIST_STATIC_INIT(&mq_list);
|
||||
|
||||
int64_t timespec_to_timeoutms(const struct timespec *abstime);
|
||||
static mqueue_object *find_in_list(const char *name);
|
||||
static int32_t send_message(mqueue_desc *mqd, const char *msg_ptr, size_t msg_len,
|
||||
k_timeout_t timeout);
|
||||
|
@ -255,9 +257,8 @@ int mq_timedsend(mqd_t mqdes, const char *msg_ptr, size_t msg_len,
|
|||
unsigned int msg_prio, const struct timespec *abstime)
|
||||
{
|
||||
mqueue_desc *mqd = (mqueue_desc *)mqdes;
|
||||
int32_t timeout = (int32_t) timespec_to_timeoutms(abstime);
|
||||
|
||||
return send_message(mqd, msg_ptr, msg_len, K_MSEC(timeout));
|
||||
return send_message(mqd, msg_ptr, msg_len, K_MSEC(timespec_to_timeoutms(abstime)));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -286,9 +287,8 @@ int mq_timedreceive(mqd_t mqdes, char *msg_ptr, size_t msg_len,
|
|||
unsigned int *msg_prio, const struct timespec *abstime)
|
||||
{
|
||||
mqueue_desc *mqd = (mqueue_desc *)mqdes;
|
||||
int32_t timeout = (int32_t) timespec_to_timeoutms(abstime);
|
||||
|
||||
return receive_message(mqd, msg_ptr, msg_len, K_MSEC(timeout));
|
||||
return receive_message(mqd, msg_ptr, msg_len, K_MSEC(timespec_to_timeoutms(abstime)));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include "posix_clock.h"
|
||||
#include "posix_internal.h"
|
||||
|
||||
#include <zephyr/init.h>
|
||||
|
@ -18,8 +19,6 @@ LOG_MODULE_REGISTER(pthread_mutex, CONFIG_PTHREAD_MUTEX_LOG_LEVEL);
|
|||
|
||||
static SYS_SEM_DEFINE(lock, 1, 1);
|
||||
|
||||
int64_t timespec_to_timeoutms(const struct timespec *abstime);
|
||||
|
||||
#define MUTEX_MAX_REC_LOCK 32767
|
||||
|
||||
/*
|
||||
|
@ -212,8 +211,7 @@ int pthread_mutex_trylock(pthread_mutex_t *m)
|
|||
int pthread_mutex_timedlock(pthread_mutex_t *m,
|
||||
const struct timespec *abstime)
|
||||
{
|
||||
int32_t timeout = (int32_t)timespec_to_timeoutms(abstime);
|
||||
return acquire_mutex(m, K_MSEC(timeout));
|
||||
return acquire_mutex(m, K_MSEC(timespec_to_timeoutms(abstime)));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
/*
|
||||
* Copyright (c) 2023, Meta
|
||||
* Copyright (c) 2025 Tenstorrent AI ULC
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
@ -7,10 +8,10 @@
|
|||
#ifndef ZEPHYR_LIB_POSIX_POSIX_CLOCK_H_
|
||||
#define ZEPHYR_LIB_POSIX_POSIX_CLOCK_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include <time.h>
|
||||
|
||||
#include <zephyr/kernel.h>
|
||||
#include <zephyr/posix/posix_types.h>
|
||||
uint32_t timespec_to_timeoutms(const struct timespec *abstime);
|
||||
|
||||
__syscall int __posix_clock_get_base(clockid_t clock_id, struct timespec *ts);
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include "posix_clock.h"
|
||||
#include "posix_internal.h"
|
||||
#include "pthread_sched.h"
|
||||
|
||||
|
@ -81,7 +82,6 @@ BUILD_ASSERT((PTHREAD_CANCEL_ENABLE == 0 || PTHREAD_CANCEL_DISABLE == 0) &&
|
|||
BUILD_ASSERT(CONFIG_POSIX_PTHREAD_ATTR_STACKSIZE_BITS + CONFIG_POSIX_PTHREAD_ATTR_GUARDSIZE_BITS <=
|
||||
32);
|
||||
|
||||
int64_t timespec_to_timeoutms(const struct timespec *abstime);
|
||||
static void posix_thread_recycle(void);
|
||||
|
||||
__pinned_data
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include "posix_clock.h"
|
||||
#include "posix_internal.h"
|
||||
|
||||
#include <zephyr/init.h>
|
||||
|
@ -27,9 +28,8 @@ struct posix_rwlockattr {
|
|||
bool pshared: 1;
|
||||
};
|
||||
|
||||
int64_t timespec_to_timeoutms(const struct timespec *abstime);
|
||||
static uint32_t read_lock_acquire(struct posix_rwlock *rwl, int32_t timeout);
|
||||
static uint32_t write_lock_acquire(struct posix_rwlock *rwl, int32_t timeout);
|
||||
static uint32_t read_lock_acquire(struct posix_rwlock *rwl, uint32_t timeout);
|
||||
static uint32_t write_lock_acquire(struct posix_rwlock *rwl, uint32_t timeout);
|
||||
|
||||
LOG_MODULE_REGISTER(pthread_rwlock, CONFIG_PTHREAD_RWLOCK_LOG_LEVEL);
|
||||
|
||||
|
@ -198,7 +198,6 @@ int pthread_rwlock_rdlock(pthread_rwlock_t *rwlock)
|
|||
int pthread_rwlock_timedrdlock(pthread_rwlock_t *rwlock,
|
||||
const struct timespec *abstime)
|
||||
{
|
||||
int32_t timeout;
|
||||
uint32_t ret = 0U;
|
||||
struct posix_rwlock *rwl;
|
||||
|
||||
|
@ -206,14 +205,12 @@ int pthread_rwlock_timedrdlock(pthread_rwlock_t *rwlock,
|
|||
return EINVAL;
|
||||
}
|
||||
|
||||
timeout = (int32_t) timespec_to_timeoutms(abstime);
|
||||
|
||||
rwl = get_posix_rwlock(*rwlock);
|
||||
if (rwl == NULL) {
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
if (read_lock_acquire(rwl, timeout) != 0U) {
|
||||
if (read_lock_acquire(rwl, timespec_to_timeoutms(abstime)) != 0U) {
|
||||
ret = ETIMEDOUT;
|
||||
}
|
||||
|
||||
|
@ -271,7 +268,6 @@ int pthread_rwlock_wrlock(pthread_rwlock_t *rwlock)
|
|||
int pthread_rwlock_timedwrlock(pthread_rwlock_t *rwlock,
|
||||
const struct timespec *abstime)
|
||||
{
|
||||
int32_t timeout;
|
||||
uint32_t ret = 0U;
|
||||
struct posix_rwlock *rwl;
|
||||
|
||||
|
@ -279,14 +275,12 @@ int pthread_rwlock_timedwrlock(pthread_rwlock_t *rwlock,
|
|||
return EINVAL;
|
||||
}
|
||||
|
||||
timeout = (int32_t) timespec_to_timeoutms(abstime);
|
||||
|
||||
rwl = get_posix_rwlock(*rwlock);
|
||||
if (rwl == NULL) {
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
if (write_lock_acquire(rwl, timeout) != 0U) {
|
||||
if (write_lock_acquire(rwl, timespec_to_timeoutms(abstime)) != 0U) {
|
||||
ret = ETIMEDOUT;
|
||||
}
|
||||
|
||||
|
@ -345,7 +339,7 @@ int pthread_rwlock_unlock(pthread_rwlock_t *rwlock)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static uint32_t read_lock_acquire(struct posix_rwlock *rwl, int32_t timeout)
|
||||
static uint32_t read_lock_acquire(struct posix_rwlock *rwl, uint32_t timeout)
|
||||
{
|
||||
uint32_t ret = 0U;
|
||||
|
||||
|
@ -360,7 +354,7 @@ static uint32_t read_lock_acquire(struct posix_rwlock *rwl, int32_t timeout)
|
|||
return ret;
|
||||
}
|
||||
|
||||
static uint32_t write_lock_acquire(struct posix_rwlock *rwl, int32_t timeout)
|
||||
static uint32_t write_lock_acquire(struct posix_rwlock *rwl, uint32_t timeout)
|
||||
{
|
||||
uint32_t ret = 0U;
|
||||
int64_t elapsed_time, st_time = k_uptime_get();
|
||||
|
|
|
@ -4,11 +4,13 @@
|
|||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include "posix_clock.h"
|
||||
|
||||
#include <zephyr/kernel.h>
|
||||
#include <ksched.h>
|
||||
#include <zephyr/posix/time.h>
|
||||
|
||||
int64_t timespec_to_timeoutms(const struct timespec *abstime)
|
||||
uint32_t timespec_to_timeoutms(const struct timespec *abstime)
|
||||
{
|
||||
int64_t milli_secs, secs, nsecs;
|
||||
struct timespec curtime;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue