tpool_dispatch: fail if it cannot start at least 1 worker.
Sponsored by: Axcient Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Reviewed-by: George Wilson <gwilson@delphix.com> Signed-off-by: Alan Somers <asomers@FreeBSD.org> Closes #16178
This commit is contained in:
parent
89acef992b
commit
f625d038d2
|
@ -423,6 +423,26 @@ tpool_dispatch(tpool_t *tpool, void (*func)(void *), void *arg)
|
||||||
|
|
||||||
pthread_mutex_lock(&tpool->tp_mutex);
|
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)
|
if (tpool->tp_head == NULL)
|
||||||
tpool->tp_head = job;
|
tpool->tp_head = job;
|
||||||
else
|
else
|
||||||
|
@ -430,14 +450,6 @@ tpool_dispatch(tpool_t *tpool, void (*func)(void *), void *arg)
|
||||||
tpool->tp_tail = job;
|
tpool->tp_tail = job;
|
||||||
tpool->tp_njobs++;
|
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);
|
pthread_mutex_unlock(&tpool->tp_mutex);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue