summaryrefslogtreecommitdiff
path: root/lib/pthreadpool
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2018-06-22 00:29:53 +0200
committerStefan Metzmacher <metze@samba.org>2018-07-12 14:25:18 +0200
commite45d33e92e47995faa7c523cf82dfb65efb190f8 (patch)
tree59d536cd2b6691a077fe0d10a0edec5ca8ff0b33 /lib/pthreadpool
parent03830a3226d43f13e58dcf68874d50e19793144d (diff)
downloadsamba-e45d33e92e47995faa7c523cf82dfb65efb190f8.tar.gz
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 <metze@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org>
Diffstat (limited to 'lib/pthreadpool')
-rw-r--r--lib/pthreadpool/pthreadpool.c20
1 files changed, 15 insertions, 5 deletions
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;
}