mirror of
https://github.com/samba-team/samba.git
synced 2025-01-11 05:18:09 +03:00
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>
This commit is contained in:
parent
03830a3226
commit
e45d33e92e
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user