From a5a925fc283d01e844f4e8a4a6c4105f878f0504 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arttu=20Yl=C3=A4-Outinen?= Date: Sat, 11 Feb 2017 15:09:26 +0900 Subject: [PATCH] Replace timed waits by normal waits in threadqueue Replaces calls to pthread_cond_timedwait with pthread_cond_wait in threadqueue.c. Simplifies code, as there should be no need for the timeout. --- src/threadqueue.c | 21 ++------------------- src/threads.h | 39 --------------------------------------- 2 files changed, 2 insertions(+), 58 deletions(-) diff --git a/src/threadqueue.c b/src/threadqueue.c index 8df2783a..d6a2faeb 100644 --- a/src/threadqueue.c +++ b/src/threadqueue.c @@ -458,17 +458,8 @@ int kvz_threadqueue_flush(threadqueue_queue_t * const threadqueue) { notdone = threadqueue->queue_waiting_execution + threadqueue->queue_waiting_dependency + threadqueue->queue_running; if (notdone > 0) { - int ret; PTHREAD_COND_BROADCAST(&(threadqueue->cond)); - - struct timespec wait_moment; - ms_from_now_timespec(&wait_moment, 100); - ret = pthread_cond_timedwait(&threadqueue->cb_cond, &threadqueue->lock, &wait_moment); - if (ret != 0 && ret != ETIMEDOUT) { - fprintf(stderr, "pthread_cond_timedwait failed!\n"); - assert(0); - return 0; - } + PTHREAD_COND_WAIT(&threadqueue->cb_cond, &threadqueue->lock); } } while (notdone > 0); @@ -496,16 +487,8 @@ int kvz_threadqueue_waitfor(threadqueue_queue_t * const threadqueue, threadqueue PTHREAD_UNLOCK(&job->lock); if (!job_done) { - int ret; PTHREAD_COND_BROADCAST(&(threadqueue->cond)); - struct timespec wait_moment; - ms_from_now_timespec(&wait_moment, 100); - ret = pthread_cond_timedwait(&threadqueue->cb_cond, &threadqueue->lock, &wait_moment); - if (ret != 0 && ret != ETIMEDOUT) { - fprintf(stderr, "pthread_cond_timedwait failed!\n"); - assert(0); - return 0; - } + PTHREAD_COND_WAIT(&threadqueue->cb_cond, &threadqueue->lock); } } while (!job_done); diff --git a/src/threads.h b/src/threads.h index af7be592..c34fd4a6 100644 --- a/src/threads.h +++ b/src/threads.h @@ -57,23 +57,6 @@ #define KVZ_CLOCK_T_AS_DOUBLE(ts) ((double)((ts).tv_sec) + (double)((ts).tv_nsec) / 1e9) #define KVZ_CLOCK_T_DIFF(start, stop) ((double)((stop).tv_sec - (start).tv_sec) + (double)((stop).tv_nsec - (start).tv_nsec) / 1e9) -static INLINE struct timespec * ms_from_now_timespec(struct timespec * result, int wait_ms) -{ - KVZ_GET_TIME(result); - int64_t secs = result->tv_sec + wait_ms / E3; - int64_t nsecs = result->tv_nsec + (wait_ms % E3) * (E9 / E3); - - if (nsecs >= E9) { - secs += 1; - nsecs -= E9; - } - - result->tv_sec = secs; - result->tv_nsec = nsecs; - - return result; -} - #define KVZ_ATOMIC_INC(ptr) __sync_add_and_fetch((volatile int32_t*)ptr, 1) #define KVZ_ATOMIC_DEC(ptr) __sync_add_and_fetch((volatile int32_t*)ptr, -1) @@ -88,28 +71,6 @@ static INLINE struct timespec * ms_from_now_timespec(struct timespec * result, i #define KVZ_CLOCK_T_DIFF(start, stop) ((double)((((uint64_t)(stop).dwHighDateTime)<<32 | (uint64_t)(stop).dwLowDateTime) - \ (((uint64_t)(start).dwHighDateTime)<<32 | (uint64_t)(start).dwLowDateTime)) / 1e7) -static INLINE struct timespec * ms_from_now_timespec(struct timespec * result, int wait_ms) -{ - KVZ_CLOCK_T now; - KVZ_GET_TIME(&now); - - int64_t moment_100ns = (int64_t)now.dwHighDateTime << 32 | (int64_t)now.dwLowDateTime; - moment_100ns -= (int64_t)FILETIME_TO_EPOCH; - - int64_t secs = moment_100ns / (E9 / 100) + (wait_ms / E3); - int64_t nsecs = (moment_100ns % (E9 / 100))*100 + ((wait_ms % E3) * (E9 / E3)); - - if (nsecs >= E9) { - secs += 1; - nsecs -= E9; - } - - result->tv_sec = secs; - result->tv_nsec = nsecs; - - return result; -} - #define KVZ_ATOMIC_INC(ptr) InterlockedIncrement((volatile LONG*)ptr) #define KVZ_ATOMIC_DEC(ptr) InterlockedDecrement((volatile LONG*)ptr)