Date: Tue, 22 Jun 2010 08:05:54 +0000 (UTC) From: Jeff Roberson <jeff@FreeBSD.org> To: src-committers@freebsd.org, svn-src-projects@freebsd.org Subject: svn commit: r209422 - in projects/ofed/head/sys: kern sys Message-ID: <201006220805.o5M85sxc083308@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: jeff Date: Tue Jun 22 08:05:54 2010 New Revision: 209422 URL: http://svn.freebsd.org/changeset/base/209422 Log: - Add a taskqueue_cancel() routine that is compatible with the similar workqueue_cancel() in linux. This is like taskqueue_drain() except it will stop the task from running at all if it has not yet been scheduled. Sponsored by: Isilon Systems, iX Systems, and Panasas. Modified: projects/ofed/head/sys/kern/subr_taskqueue.c projects/ofed/head/sys/sys/taskqueue.h Modified: projects/ofed/head/sys/kern/subr_taskqueue.c ============================================================================== --- projects/ofed/head/sys/kern/subr_taskqueue.c Tue Jun 22 08:04:42 2010 (r209421) +++ projects/ofed/head/sys/kern/subr_taskqueue.c Tue Jun 22 08:05:54 2010 (r209422) @@ -250,6 +250,44 @@ taskqueue_run(struct taskqueue *queue) TQ_UNLOCK(queue); } +int +taskqueue_cancel(struct taskqueue *queue, struct task *task) +{ + int pending; + + if (queue->tq_spin) { /* XXX */ + mtx_lock_spin(&queue->tq_mutex); + pending = task->ta_pending; + while (task->ta_pending != 0) { + if ((task->ta_flags & TA_FLAGS_RUNNING) == 0) { + STAILQ_REMOVE(&queue->tq_queue, task, + task, ta_link); + task->ta_pending = 0; + break; + } else + msleep_spin(task, &queue->tq_mutex, "-", 0); + } + mtx_unlock_spin(&queue->tq_mutex); + } else { + WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, NULL, __func__); + + mtx_lock(&queue->tq_mutex); + pending = task->ta_pending; + while (task->ta_pending != 0) { + if ((task->ta_flags & TA_FLAGS_RUNNING) == 0) { + STAILQ_REMOVE(&queue->tq_queue, task, + task, ta_link); + task->ta_pending = 0; + break; + } else + msleep(task, &queue->tq_mutex, PWAIT, "-", 0); + } + mtx_unlock(&queue->tq_mutex); + } + + return (pending); +} + void taskqueue_drain(struct taskqueue *queue, struct task *task) { Modified: projects/ofed/head/sys/sys/taskqueue.h ============================================================================== --- projects/ofed/head/sys/sys/taskqueue.h Tue Jun 22 08:04:42 2010 (r209421) +++ projects/ofed/head/sys/sys/taskqueue.h Tue Jun 22 08:05:54 2010 (r209422) @@ -54,6 +54,7 @@ struct taskqueue *taskqueue_create(const int taskqueue_start_threads(struct taskqueue **tqp, int count, int pri, const char *name, ...) __printflike(4, 5); int taskqueue_enqueue(struct taskqueue *queue, struct task *task); +int taskqueue_cancel(struct taskqueue *queue, struct task *task); void taskqueue_drain(struct taskqueue *queue, struct task *task); void taskqueue_free(struct taskqueue *queue); void taskqueue_run(struct taskqueue *queue);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201006220805.o5M85sxc083308>