diff options
Diffstat (limited to 'sys/contrib/openzfs/lib/libtpool/thread_pool.c')
-rw-r--r-- | sys/contrib/openzfs/lib/libtpool/thread_pool.c | 35 |
1 files changed, 24 insertions, 11 deletions
diff --git a/sys/contrib/openzfs/lib/libtpool/thread_pool.c b/sys/contrib/openzfs/lib/libtpool/thread_pool.c index 892beeffa5ae..39b92ae81166 100644 --- a/sys/contrib/openzfs/lib/libtpool/thread_pool.c +++ b/sys/contrib/openzfs/lib/libtpool/thread_pool.c @@ -1,3 +1,4 @@ +// SPDX-License-Identifier: CDDL-1.0 /* * CDDL HEADER START * @@ -6,7 +7,7 @@ * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE - * or http://www.opensolaris.org/os/licensing. + * or https://opensource.org/licenses/CDDL-1.0. * See the License for the specific language governing permissions * and limitations under the License. * @@ -28,6 +29,7 @@ #include <signal.h> #include <errno.h> #include <assert.h> +#include <limits.h> #include "thread_pool_impl.h" static pthread_mutex_t thread_pool_lock = PTHREAD_MUTEX_INITIALIZER; @@ -108,8 +110,7 @@ job_cleanup(void *arg) tpool_active_t **activepp; pthread_mutex_lock(&tpool->tp_mutex); - /* CSTYLED */ - for (activepp = &tpool->tp_active;; activepp = &activep->tpa_next) { + for (activepp = &tpool->tp_active; ; activepp = &activep->tpa_next) { activep = *activepp; if (activep->tpa_tid == my_tid) { *activepp = activep->tpa_next; @@ -423,6 +424,26 @@ tpool_dispatch(tpool_t *tpool, void (*func)(void *), void *arg) pthread_mutex_lock(&tpool->tp_mutex); + if (!(tpool->tp_flags & TP_SUSPEND)) { + if (tpool->tp_idle > 0) + (void) pthread_cond_signal(&tpool->tp_workcv); + else if (tpool->tp_current >= tpool->tp_maximum) { + /* At worker limit. Leave task on queue */ + } else { + if (create_worker(tpool) == 0) { + /* Started a new worker thread */ + tpool->tp_current++; + } else if (tpool->tp_current > 0) { + /* Leave task on queue */ + } else { + /* Cannot start a single worker! */ + pthread_mutex_unlock(&tpool->tp_mutex); + free(job); + return (-1); + } + } + } + if (tpool->tp_head == NULL) tpool->tp_head = job; else @@ -430,14 +451,6 @@ tpool_dispatch(tpool_t *tpool, void (*func)(void *), void *arg) tpool->tp_tail = job; tpool->tp_njobs++; - if (!(tpool->tp_flags & TP_SUSPEND)) { - if (tpool->tp_idle > 0) - (void) pthread_cond_signal(&tpool->tp_workcv); - else if (tpool->tp_current < tpool->tp_maximum && - create_worker(tpool) == 0) - tpool->tp_current++; - } - pthread_mutex_unlock(&tpool->tp_mutex); return (0); } |