mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 15:54: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:
parent
e7dfd40dc3
commit
1670ee5aba
1 changed files with 4 additions and 2 deletions
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue