mirror of
https://github.com/ultravideo/uvg266.git
synced 2024-11-24 10:34:05 +00:00
Fix possible freeze
This commit is contained in:
parent
a96c742ad4
commit
28c3f22ba1
|
@ -54,6 +54,8 @@ typedef struct {
|
||||||
} while (0);
|
} while (0);
|
||||||
#endif //PTHREAD_DUMP
|
#endif //PTHREAD_DUMP
|
||||||
|
|
||||||
|
const struct timespec time_to_wait = {1, 0};
|
||||||
|
|
||||||
static void* threadqueue_worker(void* threadqueue_worker_spec_opaque) {
|
static void* threadqueue_worker(void* threadqueue_worker_spec_opaque) {
|
||||||
threadqueue_worker_spec * const threadqueue_worker_spec = threadqueue_worker_spec_opaque;
|
threadqueue_worker_spec * const threadqueue_worker_spec = threadqueue_worker_spec_opaque;
|
||||||
threadqueue_queue * const threadqueue = threadqueue_worker_spec->threadqueue;
|
threadqueue_queue * const threadqueue = threadqueue_worker_spec->threadqueue;
|
||||||
|
@ -393,9 +395,6 @@ int threadqueue_finalize(threadqueue_queue * const threadqueue) {
|
||||||
|
|
||||||
int threadqueue_flush(threadqueue_queue * const threadqueue) {
|
int threadqueue_flush(threadqueue_queue * const threadqueue) {
|
||||||
int notdone = 1;
|
int notdone = 1;
|
||||||
struct timespec time_to_wait;
|
|
||||||
time_to_wait.tv_sec = 1;
|
|
||||||
time_to_wait.tv_nsec = 0;
|
|
||||||
|
|
||||||
//Lock the queue
|
//Lock the queue
|
||||||
PTHREAD_LOCK(&threadqueue->lock);
|
PTHREAD_LOCK(&threadqueue->lock);
|
||||||
|
@ -442,9 +441,17 @@ int threadqueue_waitfor(threadqueue_queue * const threadqueue, threadqueue_job *
|
||||||
PTHREAD_UNLOCK(&job->lock);
|
PTHREAD_UNLOCK(&job->lock);
|
||||||
|
|
||||||
if (!job_done) {
|
if (!job_done) {
|
||||||
|
int ret;
|
||||||
PTHREAD_COND_BROADCAST(&(threadqueue->cond));
|
PTHREAD_COND_BROADCAST(&(threadqueue->cond));
|
||||||
|
PTHREAD_UNLOCK(&threadqueue->lock);
|
||||||
SLEEP();
|
SLEEP();
|
||||||
PTHREAD_COND_WAIT(&threadqueue->cb_cond, &threadqueue->lock);
|
PTHREAD_LOCK(&threadqueue->lock);
|
||||||
|
ret = pthread_cond_timedwait(&threadqueue->cb_cond, &threadqueue->lock, &time_to_wait);
|
||||||
|
if (ret != 0 && ret != ETIMEDOUT) {
|
||||||
|
fprintf(stderr, "pthread_cond_timedwait failed!\n");
|
||||||
|
assert(0);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} while (!job_done);
|
} while (!job_done);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue