summaryrefslogtreecommitdiffstats
path: root/sys/kern/subr_taskqueue.c
diff options
context:
space:
mode:
authorsam <sam@FreeBSD.org>2008-04-08 17:48:02 +0000
committersam <sam@FreeBSD.org>2008-04-08 17:48:02 +0000
commit2601660586868b1346b15e1dd88a76412cf3197e (patch)
treea70b7d6d94aba47c08d48fac766b9b9f2b2a3e46 /sys/kern/subr_taskqueue.c
parentdb3fbb6a27cc943c342ace34cf3ec9250a366b38 (diff)
downloadFreeBSD-src-2601660586868b1346b15e1dd88a76412cf3197e.zip
FreeBSD-src-2601660586868b1346b15e1dd88a76412cf3197e.tar.gz
change taskqueue_start_threads to create threads instead of proc's
Reviewed by: jhb
Diffstat (limited to 'sys/kern/subr_taskqueue.c')
-rw-r--r--sys/kern/subr_taskqueue.c46
1 files changed, 24 insertions, 22 deletions
diff --git a/sys/kern/subr_taskqueue.c b/sys/kern/subr_taskqueue.c
index 7664861..3a498e8 100644
--- a/sys/kern/subr_taskqueue.c
+++ b/sys/kern/subr_taskqueue.c
@@ -56,8 +56,8 @@ struct taskqueue {
void *tq_context;
struct task *tq_running;
struct mtx tq_mutex;
- struct proc **tq_pproc;
- int tq_pcount;
+ struct thread **tq_threads;
+ int tq_tcount;
int tq_spin;
int tq_flags;
};
@@ -143,10 +143,10 @@ taskqueue_create(const char *name, int mflags,
* Signal a taskqueue thread to terminate.
*/
static void
-taskqueue_terminate(struct proc **pp, struct taskqueue *tq)
+taskqueue_terminate(struct thread **pp, struct taskqueue *tq)
{
- while (tq->tq_pcount > 0) {
+ while (tq->tq_tcount > 0) {
wakeup(tq);
TQ_SLEEP(tq, pp, &tq->tq_mutex, PWAIT, "taskqueue_destroy", 0);
}
@@ -163,9 +163,9 @@ taskqueue_free(struct taskqueue *queue)
TQ_LOCK(queue);
queue->tq_flags &= ~TQ_FLAGS_ACTIVE;
taskqueue_run(queue);
- taskqueue_terminate(queue->tq_pproc, queue);
+ taskqueue_terminate(queue->tq_threads, queue);
mtx_destroy(&queue->tq_mutex);
- free(queue->tq_pproc, M_TASKQUEUE);
+ free(queue->tq_threads, M_TASKQUEUE);
free(queue, M_TASKQUEUE);
}
@@ -341,45 +341,47 @@ taskqueue_start_threads(struct taskqueue **tqp, int count, int pri,
const char *name, ...)
{
va_list ap;
- struct taskqueue *tq;
struct thread *td;
- char ktname[MAXCOMLEN];
+ struct taskqueue *tq;
int i, error;
+ char ktname[MAXCOMLEN];
if (count <= 0)
return (EINVAL);
+
tq = *tqp;
va_start(ap, name);
vsnprintf(ktname, MAXCOMLEN, name, ap);
va_end(ap);
- tq->tq_pproc = malloc(sizeof(struct proc *) * count, M_TASKQUEUE,
+ tq->tq_threads = malloc(sizeof(struct thread *) * count, M_TASKQUEUE,
M_NOWAIT | M_ZERO);
- if (tq->tq_pproc == NULL) {
+ if (tq->tq_threads == NULL) {
printf("%s: no memory for %s threads\n", __func__, ktname);
return (ENOMEM);
}
for (i = 0; i < count; i++) {
if (count == 1)
- error = kproc_create(taskqueue_thread_loop, tqp,
- &tq->tq_pproc[i], RFSTOPPED, 0, ktname);
+ error = kthread_add(taskqueue_thread_loop, tqp, NULL,
+ &tq->tq_threads[i], RFSTOPPED, 0, ktname);
else
- error = kproc_create(taskqueue_thread_loop, tqp,
- &tq->tq_pproc[i], RFSTOPPED, 0, "%s_%d", ktname, i);
+ error = kthread_add(taskqueue_thread_loop, tqp, NULL,
+ &tq->tq_threads[i], RFSTOPPED, 0,
+ "%s_%d", ktname, i);
if (error) {
/* should be ok to continue, taskqueue_free will dtrt */
- printf("%s: kproc_create(%s): error %d",
- __func__, ktname, error);
- tq->tq_pproc[i] = NULL; /* paranoid */
+ printf("%s: kthread_add(%s): error %d", __func__,
+ ktname, error);
+ tq->tq_threads[i] = NULL; /* paranoid */
} else
- tq->tq_pcount++;
+ tq->tq_tcount++;
}
for (i = 0; i < count; i++) {
- if (tq->tq_pproc[i] == NULL)
+ if (tq->tq_threads[i] == NULL)
continue;
- td = FIRST_THREAD_IN_PROC(tq->tq_pproc[i]);
+ td = tq->tq_threads[i];
thread_lock(td);
sched_prio(td, pri);
sched_add(td, SRQ_BORING);
@@ -403,8 +405,8 @@ taskqueue_thread_loop(void *arg)
} while ((tq->tq_flags & TQ_FLAGS_ACTIVE) != 0);
/* rendezvous with thread that asked us to terminate */
- tq->tq_pcount--;
- wakeup_one(tq->tq_pproc);
+ tq->tq_tcount--;
+ wakeup_one(tq->tq_threads);
TQ_UNLOCK(tq);
kproc_exit(0);
}
OpenPOWER on IntegriCloud