From: Volker Lendecke Date: Tue, 12 Dec 2017 12:52:56 +0000 (+0100) Subject: pthreadpool: Simplify the logic in add_job a bit X-Git-Tag: talloc-2.1.11~244 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=74aa416be7805547b4c8227032c24afe114631d9;p=thirdparty%2Fsamba.git pthreadpool: Simplify the logic in add_job a bit Signed-off-by: Volker Lendecke Reviewed-by: Jeremy Allison --- diff --git a/lib/pthreadpool/pthreadpool.c b/lib/pthreadpool/pthreadpool.c index b70694a6a1b..2dfda38f144 100644 --- a/lib/pthreadpool/pthreadpool.c +++ b/lib/pthreadpool/pthreadpool.c @@ -678,27 +678,33 @@ int pthreadpool_add_job(struct pthreadpool *pool, int job_id, } res = pthreadpool_create_thread(pool); - if (res != 0) { - if (pool->num_threads == 0) { - /* - * No thread could be created to run job, - * fallback to sync call. - */ - pthreadpool_undo_put_job(pool); - pthread_mutex_unlock(&pool->mutex); - - fn(private_data); - return pool->signal_fn(job_id, fn, private_data, - pool->signal_fn_private_data); - } + if (res == 0) { + res = pthread_mutex_unlock(&pool->mutex); + assert(res == 0); + return 0; + } + if (pool->num_threads != 0) { /* * At least one thread is still available, let * that one run the queued job. */ - res = 0; + res = pthread_mutex_unlock(&pool->mutex); + assert(res == 0); + return 0; } - pthread_mutex_unlock(&pool->mutex); + /* + * No thread could be created to run job, fallback to sync + * call. + */ + pthreadpool_undo_put_job(pool); + + res = pthread_mutex_unlock(&pool->mutex); + assert(res == 0); + + fn(private_data); + res = pool->signal_fn(job_id, fn, private_data, + pool->signal_fn_private_data); return res; }