mirror of
https://github.com/ultravideo/uvg266.git
synced 2024-11-27 19:24:06 +00:00
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.
This commit is contained in:
parent
fd057498fc
commit
a5a925fc28
|
@ -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);
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in a new issue