posix: cond: use clock specified via pthread_condattr_t
Use the clock specified via pthread_condattr_t in pthread_cond_timedwait(). Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
This commit is contained in:
parent
8b60aa75fa
commit
bb9ec32cf6
1 changed files with 19 additions and 3 deletions
|
@ -86,15 +86,17 @@ static struct posix_cond *to_posix_cond(pthread_cond_t *cvar)
|
|||
/* Record the associated posix_cond in mu and mark as initialized */
|
||||
*cvar = mark_pthread_obj_initialized(bit);
|
||||
cv = &posix_cond_pool[bit];
|
||||
(void)pthread_condattr_init((pthread_condattr_t *)&cv->attr);
|
||||
|
||||
return cv;
|
||||
}
|
||||
|
||||
static int cond_wait(pthread_cond_t *cond, pthread_mutex_t *mu, k_timeout_t timeout)
|
||||
static int cond_wait(pthread_cond_t *cond, pthread_mutex_t *mu, const struct timespec *abstime)
|
||||
{
|
||||
int ret;
|
||||
struct k_mutex *m;
|
||||
struct posix_cond *cv;
|
||||
k_timeout_t timeout = K_FOREVER;
|
||||
|
||||
m = to_posix_mutex(mu);
|
||||
cv = to_posix_cond(cond);
|
||||
|
@ -102,6 +104,10 @@ static int cond_wait(pthread_cond_t *cond, pthread_mutex_t *mu, k_timeout_t time
|
|||
return EINVAL;
|
||||
}
|
||||
|
||||
if (abstime != NULL) {
|
||||
timeout = K_MSEC(timespec_to_clock_timeoutms(cv->attr.clock, abstime));
|
||||
}
|
||||
|
||||
LOG_DBG("Waiting on cond %p with timeout %llx", cv, timeout.ticks);
|
||||
ret = k_condvar_wait(&cv->condvar, m, timeout);
|
||||
if (ret == -EAGAIN) {
|
||||
|
@ -164,17 +170,18 @@ int pthread_cond_broadcast(pthread_cond_t *cvar)
|
|||
|
||||
int pthread_cond_wait(pthread_cond_t *cv, pthread_mutex_t *mut)
|
||||
{
|
||||
return cond_wait(cv, mut, K_FOREVER);
|
||||
return cond_wait(cv, mut, NULL);
|
||||
}
|
||||
|
||||
int pthread_cond_timedwait(pthread_cond_t *cv, pthread_mutex_t *mut, const struct timespec *abstime)
|
||||
{
|
||||
return cond_wait(cv, mut, K_MSEC(timespec_to_timeoutms(abstime)));
|
||||
return cond_wait(cv, mut, abstime);
|
||||
}
|
||||
|
||||
int pthread_cond_init(pthread_cond_t *cvar, const pthread_condattr_t *att)
|
||||
{
|
||||
struct posix_cond *cv;
|
||||
struct posix_condattr *attr = (struct posix_condattr *)attr;
|
||||
|
||||
*cvar = PTHREAD_COND_INITIALIZER;
|
||||
cv = to_posix_cond(cvar);
|
||||
|
@ -182,6 +189,15 @@ int pthread_cond_init(pthread_cond_t *cvar, const pthread_condattr_t *att)
|
|||
return ENOMEM;
|
||||
}
|
||||
|
||||
if (attr != NULL) {
|
||||
if (!attr->initialized) {
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
(void)pthread_condattr_destroy((pthread_condattr_t *)&cv->attr);
|
||||
cv->attr = *attr;
|
||||
}
|
||||
|
||||
LOG_DBG("Initialized cond %p", cv);
|
||||
|
||||
return 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue