1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 18:34:58 +00:00

LibPthread: Condition variables should use CLOCK_MONOTONIC by default

It's the only clock we have at the moment, so it's a logical choice :^)
This commit is contained in:
Andreas Kling 2019-12-07 16:07:48 +01:00
parent e7dfd40dc3
commit 1670ee5aba

View file

@ -395,7 +395,7 @@ struct WaitNode : public InlineLinkedListNode<WaitNode> {
struct ConditionVariable { struct ConditionVariable {
InlineLinkedList<WaitNode> waiters; InlineLinkedList<WaitNode> waiters;
clockid_t clock; clockid_t clock { CLOCK_MONOTONIC };
}; };
int pthread_cond_init(pthread_cond_t* cond, const pthread_condattr_t* attr) int pthread_cond_init(pthread_cond_t* cond, const pthread_condattr_t* attr)
@ -450,8 +450,10 @@ int pthread_cond_timedwait(pthread_cond_t* cond, pthread_mutex_t* mutex, const s
condvar.waiters.append(&node); condvar.waiters.append(&node);
while (node.waiting) { while (node.waiting) {
struct timespec now; struct timespec now;
if (clock_gettime(condvar.clock, &now) < 0) if (clock_gettime(condvar.clock, &now) < 0) {
dbgprintf("pthread_cond_timedwait: clock_gettime() failed\n");
return errno; return errno;
}
if ((abstime->tv_sec < now.tv_sec) || (abstime->tv_sec == now.tv_sec && abstime->tv_nsec <= now.tv_nsec)) { if ((abstime->tv_sec < now.tv_sec) || (abstime->tv_sec == now.tv_sec && abstime->tv_nsec <= now.tv_nsec)) {
return ETIMEDOUT; return ETIMEDOUT;
} }