diff --git a/src/compat/compat.c b/src/compat/compat.c index 8816eb873..549077ab2 100644 --- a/src/compat/compat.c +++ b/src/compat/compat.c @@ -45,38 +45,11 @@ pid_t waitpid(pid_t pid, int* state, int options){ // FIXME */ return 0; } - -int pthread_condmonotonic_init(pthread_cond_t* cond){ - if(pthread_cond_init(cond, &cat)){ - return -1; - } - return 0; -} #else // not windows #include #include #include #include -// initializes a pthread_cond_t to use CLOCK_MONOTONIC (as opposed to the -// default CLOCK_REALTIME) if possible. if not possible, initializes a -// regular ol' CLOCK_REALTIME condvar. -int pthread_condmonotonic_init(pthread_cond_t* cond){ - pthread_condattr_t cat; - if(pthread_condattr_init(&cat)){ - return -1; - } - if(pthread_condattr_setclock(&cat, CLOCK_MONOTONIC)){ - pthread_condattr_destroy(&cat); - return -1; - } - if(pthread_cond_init(cond, &cat)){ - pthread_condattr_destroy(&cat); - return -1; - } - pthread_condattr_destroy(&cat); - return 0; -} - int set_fd_nonblocking(int fd, unsigned state, unsigned* oldstate){ int flags = fcntl(fd, F_GETFL); if(flags < 0){ @@ -152,3 +125,25 @@ int clock_nanosleep(clockid_t clockid, int flags, const struct timespec *request } #endif #endif + +// initializes a pthread_cond_t to use CLOCK_MONOTONIC (as opposed to the +// default CLOCK_REALTIME) if possible. if not possible, initializes a +// regular ol' CLOCK_REALTIME condvar. +int pthread_condmonotonic_init(pthread_cond_t* cond){ + pthread_condattr_t cat; + if(pthread_condattr_init(&cat)){ + return -1; + } +#ifndef __APPLE__ + if(pthread_condattr_setclock(&cat, CLOCK_MONOTONIC)){ + pthread_condattr_destroy(&cat); + return -1; + } +#endif + if(pthread_cond_init(cond, &cat)){ + pthread_condattr_destroy(&cat); + return -1; + } + pthread_condattr_destroy(&cat); + return 0; +}