summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibPthread/pthread_cond.cpp
diff options
context:
space:
mode:
authorJelle Raaijmakers <jelle@gmta.nl>2021-11-24 18:40:36 +0100
committerAndreas Kling <kling@serenityos.org>2021-11-24 19:44:57 +0100
commit30580ed7e44a242befff02ea8496de0735351861 (patch)
treef9d9148c764c27c6c28c768c7c1da0b6c16095ee /Userland/Libraries/LibPthread/pthread_cond.cpp
parentce3a63253a59122f31317964202572a736b3cd5e (diff)
downloadserenity-30580ed7e44a242befff02ea8496de0735351861.zip
LibPthread: Initialize conditions with realtime clock
All the way back in commit 1670ee5aba09, the default clock for condition variables was set to `CLOCK_MONOTONIC`, because there was no other clock available. However, if a condition variable is initialized without any additional attributes by an application, they sometimes assume that the absolute time that is passed to e.g. `pthread_cond_timedwait` is actually based on a realtime clock, as can be seen here in SDL2: https://github.com/SerenityPorts/SDL/blob/6f419bdf5f56be236c070a9d364e0d238b868565/src/thread/pthread/SDL_syscond.c#L99 Additionally, the glibc implementation defaults to a realtime clock: https://github.com/bminor/glibc/blob/aac54dcd378209bbdddbcec749561b1d8f167d11/nptl/pthread_cond_init.c#L42 ...so we probably should do so as well :^)
Diffstat (limited to 'Userland/Libraries/LibPthread/pthread_cond.cpp')
-rw-r--r--Userland/Libraries/LibPthread/pthread_cond.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/Userland/Libraries/LibPthread/pthread_cond.cpp b/Userland/Libraries/LibPthread/pthread_cond.cpp
index 7913daec61..41f1c842a1 100644
--- a/Userland/Libraries/LibPthread/pthread_cond.cpp
+++ b/Userland/Libraries/LibPthread/pthread_cond.cpp
@@ -48,7 +48,7 @@ int pthread_cond_init(pthread_cond_t* cond, const pthread_condattr_t* attr)
{
cond->mutex = nullptr;
cond->value = 0;
- cond->clockid = attr ? attr->clockid : CLOCK_MONOTONIC_COARSE;
+ cond->clockid = attr ? attr->clockid : CLOCK_REALTIME_COARSE;
return 0;
}