From: Stefan Metzmacher Date: Thu, 21 Jun 2018 22:29:53 +0000 (+0200) Subject: pthreadpool: use strict sync processing only with max_threads=0 X-Git-Tag: ldb-1.5.0~332 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e45d33e9;p=thirdparty%2Fsamba.git pthreadpool: use strict sync processing only with max_threads=0 Otherwise it's an error if not at least one thread is possible. This gives a much saner behaviour and doesn't end up with unexpected sync processing. Signed-off-by: Stefan Metzmacher Reviewed-by: Ralph Boehme --- diff --git a/lib/pthreadpool/pthreadpool.c b/lib/pthreadpool/pthreadpool.c index 0f695bcd769..31ff02dd583 100644 --- a/lib/pthreadpool/pthreadpool.c +++ b/lib/pthreadpool/pthreadpool.c @@ -77,6 +77,7 @@ struct pthreadpool { /* * maximum number of threads + * 0 means no real thread, only strict sync processing. */ unsigned max_threads; @@ -649,6 +650,19 @@ int pthreadpool_add_job(struct pthreadpool *pool, int job_id, return EINVAL; } + if (pool->max_threads == 0) { + unlock_res = pthread_mutex_unlock(&pool->mutex); + assert(unlock_res == 0); + + /* + * If no thread are allowed we do strict sync processing. + */ + fn(private_data); + res = pool->signal_fn(job_id, fn, private_data, + pool->signal_fn_private_data); + return res; + } + /* * Add job to the end of the queue */ @@ -671,8 +685,7 @@ int pthreadpool_add_job(struct pthreadpool *pool, int job_id, return res; } - if ((pool->max_threads != 0) && - (pool->num_threads >= pool->max_threads)) { + if (pool->num_threads >= pool->max_threads) { /* * No more new threads, we just queue the request */ @@ -707,8 +720,5 @@ int pthreadpool_add_job(struct pthreadpool *pool, int job_id, unlock_res = pthread_mutex_unlock(&pool->mutex); assert(unlock_res == 0); - fn(private_data); - res = pool->signal_fn(job_id, fn, private_data, - pool->signal_fn_private_data); return res; }