mirror of
https://github.com/ultravideo/uvg266.git
synced 2024-11-28 03:34:06 +00:00
Tentative fix for race condition
This commit is contained in:
parent
b194e19708
commit
68ad323e84
|
@ -42,7 +42,6 @@ static void* threadqueue_worker(void* threadqueue_worker_spec_opaque) {
|
||||||
|
|
||||||
for(;;) {
|
for(;;) {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
int signal_count = 0;
|
|
||||||
threadqueue_job * job_to_run = NULL;
|
threadqueue_job * job_to_run = NULL;
|
||||||
|
|
||||||
PTHREAD_LOCK(&threadqueue->lock);
|
PTHREAD_LOCK(&threadqueue->lock);
|
||||||
|
@ -88,6 +87,7 @@ static void* threadqueue_worker(void* threadqueue_worker_spec_opaque) {
|
||||||
|
|
||||||
//Ok we got a job (and we have a lock on it)
|
//Ok we got a job (and we have a lock on it)
|
||||||
if (job_to_run) {
|
if (job_to_run) {
|
||||||
|
int queue_waiting_dependency_decr, queue_waiting_execution_incr;
|
||||||
threadqueue_job * const job = job_to_run;
|
threadqueue_job * const job = job_to_run;
|
||||||
|
|
||||||
assert(job->state == THREADQUEUE_JOB_STATE_QUEUED || (job == next_job && job->state == THREADQUEUE_JOB_STATE_RUNNING));
|
assert(job->state == THREADQUEUE_JOB_STATE_QUEUED || (job == next_job && job->state == THREADQUEUE_JOB_STATE_RUNNING));
|
||||||
|
@ -121,9 +121,10 @@ static void* threadqueue_worker(void* threadqueue_worker_spec_opaque) {
|
||||||
|
|
||||||
job->state = THREADQUEUE_JOB_STATE_DONE;
|
job->state = THREADQUEUE_JOB_STATE_DONE;
|
||||||
|
|
||||||
signal_count = 0;
|
|
||||||
next_job = NULL;
|
next_job = NULL;
|
||||||
|
|
||||||
|
queue_waiting_dependency_decr = 0;
|
||||||
|
queue_waiting_execution_incr = 0;
|
||||||
//Decrease counter of dependencies
|
//Decrease counter of dependencies
|
||||||
for (i = 0; i < job->rdepends_count; ++i) {
|
for (i = 0; i < job->rdepends_count; ++i) {
|
||||||
threadqueue_job * const depjob = job->rdepends[i];
|
threadqueue_job * const depjob = job->rdepends[i];
|
||||||
|
@ -139,11 +140,9 @@ static void* threadqueue_worker(void* threadqueue_worker_spec_opaque) {
|
||||||
next_job = depjob;
|
next_job = depjob;
|
||||||
depjob->state = THREADQUEUE_JOB_STATE_RUNNING;
|
depjob->state = THREADQUEUE_JOB_STATE_RUNNING;
|
||||||
} else {
|
} else {
|
||||||
++signal_count;
|
++queue_waiting_execution_incr;
|
||||||
++threadqueue->queue_waiting_execution;
|
|
||||||
}
|
}
|
||||||
assert(threadqueue->queue_waiting_dependency > 0);
|
++queue_waiting_dependency_decr;
|
||||||
--threadqueue->queue_waiting_dependency;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PTHREAD_UNLOCK(&depjob->lock);
|
PTHREAD_UNLOCK(&depjob->lock);
|
||||||
|
@ -153,9 +152,11 @@ static void* threadqueue_worker(void* threadqueue_worker_spec_opaque) {
|
||||||
|
|
||||||
//Signal the queue that we've done a job
|
//Signal the queue that we've done a job
|
||||||
PTHREAD_LOCK(&threadqueue->lock);
|
PTHREAD_LOCK(&threadqueue->lock);
|
||||||
for (i = 0; i < signal_count; ++i) {
|
assert(threadqueue->queue_waiting_dependency >= queue_waiting_dependency_decr);
|
||||||
PTHREAD_COND_SIGNAL(&threadqueue->cond);
|
threadqueue->queue_waiting_dependency -= queue_waiting_dependency_decr;
|
||||||
}
|
threadqueue->queue_waiting_execution += queue_waiting_execution_incr;
|
||||||
|
PTHREAD_COND_BROADCAST(&threadqueue->cond);
|
||||||
|
|
||||||
//PTHREAD_COND_BROADCAST(&threadqueue->cond);
|
//PTHREAD_COND_BROADCAST(&threadqueue->cond);
|
||||||
//Don't log this one
|
//Don't log this one
|
||||||
//PTHREAD_COND_SIGNAL(&threadqueue->cb_cond);
|
//PTHREAD_COND_SIGNAL(&threadqueue->cb_cond);
|
||||||
|
|
Loading…
Reference in a new issue