Improve handling of jobs when not using threads

This commit is contained in:
Laurent Fasnacht 2014-05-16 08:40:35 +02:00
parent 519750d630
commit 53b0835316

View file

@ -360,7 +360,10 @@ threadqueue_job * threadqueue_submit(threadqueue_queue * const threadqueue, void
threadqueue_job *job; threadqueue_job *job;
//No lock here... this should be constant //No lock here... this should be constant
if (threadqueue->threads_count == 0) { if (threadqueue->threads_count == 0) {
//FIXME: This should be improved in order to handle dependencies
PERFORMANCE_MEASURE_START();
fptr(arg); fptr(arg);
PERFORMANCE_MEASURE_END(threadqueue, "%s", debug_description);
return NULL; return NULL;
} }
@ -438,6 +441,8 @@ threadqueue_job * threadqueue_submit(threadqueue_queue * const threadqueue, void
} }
int threadqueue_job_dep_add(threadqueue_job *job, threadqueue_job *depends_on) { int threadqueue_job_dep_add(threadqueue_job *job, threadqueue_job *depends_on) {
//If we are not using threads, job are NULL pointers, so we can skip that
if (!job && !depends_on) return 1;
//Lock first the job, and then the dependency //Lock first the job, and then the dependency
PTHREAD_LOCK(&job->lock); PTHREAD_LOCK(&job->lock);
PTHREAD_LOCK(&depends_on->lock); PTHREAD_LOCK(&depends_on->lock);
@ -465,6 +470,8 @@ int threadqueue_job_dep_add(threadqueue_job *job, threadqueue_job *depends_on) {
} }
int threadqueue_job_unwait_job(threadqueue_queue * const threadqueue, threadqueue_job *job) { int threadqueue_job_unwait_job(threadqueue_queue * const threadqueue, threadqueue_job *job) {
//NULL job => no threads, nothing to do
if (!job) return 1;
PTHREAD_LOCK(&job->lock); PTHREAD_LOCK(&job->lock);
job->ndepends--; job->ndepends--;
PTHREAD_UNLOCK(&job->lock); PTHREAD_UNLOCK(&job->lock);