Update scond_wait_timeout

This commit is contained in:
twinaphex 2015-08-27 09:22:03 +02:00
parent 9960d88d32
commit 76fe1163c2

View File

@ -383,6 +383,7 @@ bool scond_wait_timeout(scond_t *cond, slock_t *lock, int64_t timeout_us)
return ret == WAIT_OBJECT_0;
#else
int ret;
int64_t seconds, remainder;
struct timespec now = {0};
#ifdef __MACH__
@ -413,11 +414,11 @@ bool scond_wait_timeout(scond_t *cond, slock_t *lock, int64_t timeout_us)
clock_gettime(CLOCK_REALTIME, &now);
#endif
now.tv_sec += timeout_us / 1000000;
now.tv_nsec += timeout_us * 1000;
seconds = timeout_us / INT64_C(1000000);
remainder = timeout_us % INT64_C(1000000);
now.tv_sec += now.tv_nsec / 1000000000;
now.tv_nsec = now.tv_nsec % 1000000000;
now.tv_sec += seconds;
now.tv_nsec += remainder * INT64_C(1000);
ret = pthread_cond_timedwait(&cond->cond, &lock->lock, &now);
return (ret == 0);