Skip to content

Commit

Permalink
Do not use pthread_condattr_setclock() on MacOS X
Browse files Browse the repository at this point in the history
Apparently newer MacOS X supports CLOCK_MONOTONIC, but there is no pthread_condattr_setclock()... Oh my god how did they screw POSIX so much???
There is no way around this, other than always using a realtime clock
  • Loading branch information
LekKit authored Nov 22, 2022
1 parent fbba21a commit 357cd04
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/threading.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ typedef struct {
#else

#include <time.h>
#ifndef CLOCK_MONOTONIC
#if !defined(CLOCK_MONOTONIC) || defined(__APPLE__)
#include <sys/time.h>
#endif
#include <pthread.h>
Expand Down Expand Up @@ -105,7 +105,7 @@ cond_var_t condvar_create()
#ifdef _WIN32
cond->event = CreateEventW(NULL, FALSE, FALSE, NULL);
if (cond->event) return cond;
#elif defined(CLOCK_MONOTONIC)
#elif defined(CLOCK_MONOTONIC) && !defined(__APPLE__)
pthread_condattr_t cond_attr;
pthread_condattr_init(&cond_attr);
if (pthread_condattr_setclock(&cond_attr, CLOCK_MONOTONIC) == 0
Expand Down Expand Up @@ -142,7 +142,7 @@ bool condvar_wait(cond_var_t cond, unsigned timeout_ms)
ret = pthread_cond_wait(&cond_p->cond, &cond_p->lock) == 0;
} else {
struct timespec ts = {0};
#ifdef CLOCK_MONOTONIC
#if defined(CLOCK_MONOTONIC) && !defined(__APPLE__)
clock_gettime(CLOCK_MONOTONIC, &ts);
ts.tv_nsec += timeout_ms * 1000000;
ts.tv_sec += ts.tv_nsec / 1000000000;
Expand Down

0 comments on commit 357cd04

Please sign in to comment.