diff options
Diffstat (limited to 'Python/condvar.h')
-rw-r--r-- | Python/condvar.h | 40 |
1 files changed, 12 insertions, 28 deletions
diff --git a/Python/condvar.h b/Python/condvar.h index 1351740..f54adc5 100644 --- a/Python/condvar.h +++ b/Python/condvar.h @@ -48,19 +48,9 @@ * POSIX support */ -#define PyCOND_ADD_MICROSECONDS(tv, interval) \ -do { /* TODO: add overflow and truncation checks */ \ - tv.tv_usec += (long) interval; \ - tv.tv_sec += tv.tv_usec / 1000000; \ - tv.tv_usec %= 1000000; \ -} while (0) - -/* We assume all modern POSIX systems have gettimeofday() */ -#ifdef GETTIMEOFDAY_NO_TZ -#define PyCOND_GETTIMEOFDAY(ptv) gettimeofday(ptv) -#else -#define PyCOND_GETTIMEOFDAY(ptv) gettimeofday(ptv, (struct timezone *)NULL) -#endif +/* These private functions are implemented in Python/thread_pthread.h */ +int _PyThread_cond_init(PyCOND_T *cond); +void _PyThread_cond_after(long long us, struct timespec *abs); /* The following functions return 0 on success, nonzero on error */ #define PyMUTEX_INIT(mut) pthread_mutex_init((mut), NULL) @@ -68,7 +58,7 @@ do { /* TODO: add overflow and truncation checks */ \ #define PyMUTEX_LOCK(mut) pthread_mutex_lock(mut) #define PyMUTEX_UNLOCK(mut) pthread_mutex_unlock(mut) -#define PyCOND_INIT(cond) pthread_cond_init((cond), NULL) +#define PyCOND_INIT(cond) _PyThread_cond_init(cond) #define PyCOND_FINI(cond) pthread_cond_destroy(cond) #define PyCOND_SIGNAL(cond) pthread_cond_signal(cond) #define PyCOND_BROADCAST(cond) pthread_cond_broadcast(cond) @@ -78,22 +68,16 @@ do { /* TODO: add overflow and truncation checks */ \ Py_LOCAL_INLINE(int) PyCOND_TIMEDWAIT(PyCOND_T *cond, PyMUTEX_T *mut, long long us) { - int r; - struct timespec ts; - struct timeval deadline; - - PyCOND_GETTIMEOFDAY(&deadline); - PyCOND_ADD_MICROSECONDS(deadline, us); - ts.tv_sec = deadline.tv_sec; - ts.tv_nsec = deadline.tv_usec * 1000; - - r = pthread_cond_timedwait((cond), (mut), &ts); - if (r == ETIMEDOUT) + struct timespec abs; + _PyThread_cond_after(us, &abs); + int ret = pthread_cond_timedwait(cond, mut, &abs); + if (ret == ETIMEDOUT) { return 1; - else if (r) + } + if (ret) { return -1; - else - return 0; + } + return 0; } #elif defined(NT_THREADS) |