diff options
author | sam <sam@FreeBSD.org> | 2006-03-30 23:06:59 +0000 |
---|---|---|
committer | sam <sam@FreeBSD.org> | 2006-03-30 23:06:59 +0000 |
commit | a2a6bebf93f725ca7f3b3836038396bcaa8e87a0 (patch) | |
tree | 9288adde7c7e86ffd6d434d76300f9bad2428a9c | |
parent | 017427c851c4988096f2827bdea2e4574b0abc1f (diff) | |
download | FreeBSD-src-a2a6bebf93f725ca7f3b3836038396bcaa8e87a0.zip FreeBSD-src-a2a6bebf93f725ca7f3b3836038396bcaa8e87a0.tar.gz |
fixup error handling in taskqueue_start_threads: check for kthread_create
failing, print a message when we fail for some reason as most callers do
not check the return value (e.g. 'cuz they're called from SYSINIT)
Reviewed by: scottl
MFC after: 1 week
-rw-r--r-- | sys/kern/subr_taskqueue.c | 31 |
1 files changed, 20 insertions, 11 deletions
diff --git a/sys/kern/subr_taskqueue.c b/sys/kern/subr_taskqueue.c index 72c75a4..00a842d 100644 --- a/sys/kern/subr_taskqueue.c +++ b/sys/kern/subr_taskqueue.c @@ -316,31 +316,40 @@ taskqueue_start_threads(struct taskqueue **tqp, int count, int pri, va_list ap; struct taskqueue *tq; char ktname[MAXCOMLEN]; - int i; + int i, error; if (count <= 0) return (EINVAL); tq = *tqp; - if ((tq->tq_pproc = malloc(sizeof(struct proc *) * count, M_TASKQUEUE, - M_NOWAIT | M_ZERO)) == NULL) - return (ENOMEM); - va_start(ap, name); vsnprintf(ktname, MAXCOMLEN, name, ap); va_end(ap); + tq->tq_pproc = malloc(sizeof(struct proc *) * count, M_TASKQUEUE, + M_NOWAIT | M_ZERO); + if (tq->tq_pproc == NULL) { + printf("%s: no memory for %s threads\n", __func__, ktname); + return (ENOMEM); + } + for (i = 0; i < count; i++) { if (count == 1) - kthread_create(taskqueue_thread_loop, tqp, + error = kthread_create(taskqueue_thread_loop, tqp, &tq->tq_pproc[i], 0, 0, ktname); else - kthread_create(taskqueue_thread_loop, tqp, + error = kthread_create(taskqueue_thread_loop, tqp, &tq->tq_pproc[i], 0, 0, "%s_%d", ktname, i); - mtx_lock_spin(&sched_lock); - sched_prio(FIRST_THREAD_IN_PROC(tq->tq_pproc[i]), pri); - mtx_unlock_spin(&sched_lock); - tq->tq_pcount++; + if (error == 0) { + mtx_lock_spin(&sched_lock); + sched_prio(FIRST_THREAD_IN_PROC(tq->tq_pproc[i]), pri); + mtx_unlock_spin(&sched_lock); + tq->tq_pcount++; + } else { + /* should be ok to continue, taskqueue_free will dtrt */ + printf("%s: kthread_create(%s): error %d", + __func__, ktname, error); + } } return (0); |