mirror of
https://github.com/freebsd/freebsd-src.git
synced 2024-12-04 05:58:57 +00:00
Add taskqueue_drain. This waits for the specified task to finish, if
running, or returns. The calling program is responsible for making sure that nothing new is enqueued. # man page coming soon.
This commit is contained in:
parent
8aebfc9c7e
commit
14889b4229
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=136131
@ -186,11 +186,14 @@ taskqueue_run(struct taskqueue *queue)
|
||||
STAILQ_REMOVE_HEAD(&queue->tq_queue, ta_link);
|
||||
pending = task->ta_pending;
|
||||
task->ta_pending = 0;
|
||||
task->ta_flags |= TAF_PENDING;
|
||||
mtx_unlock(&queue->tq_mutex);
|
||||
|
||||
task->ta_func(task->ta_context, pending);
|
||||
|
||||
mtx_lock(&queue->tq_mutex);
|
||||
task->ta_flags &= ~TAF_PENDING;
|
||||
wakeup(task);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -201,6 +204,17 @@ taskqueue_run(struct taskqueue *queue)
|
||||
mtx_unlock(&queue->tq_mutex);
|
||||
}
|
||||
|
||||
void
|
||||
taskqueue_drain(struct taskqueue *queue, struct task *task)
|
||||
{
|
||||
WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, NULL, "taskqueue_drain");
|
||||
mtx_lock(&queue->tq_mutex);
|
||||
while (task->ta_pending != 0 || (task->ta_flags & TAF_PENDING)) {
|
||||
msleep(task, &queue->tq_mutex, PWAIT, "-", 0);
|
||||
}
|
||||
mtx_unlock(&queue->tq_mutex);
|
||||
}
|
||||
|
||||
static void
|
||||
taskqueue_swi_enqueue(void *context)
|
||||
{
|
||||
|
@ -45,6 +45,9 @@ struct task {
|
||||
int ta_priority; /* priority of task in queue */
|
||||
task_fn_t *ta_func; /* task handler */
|
||||
void *ta_context; /* argument for handler */
|
||||
int ta_flags; /* Flags */
|
||||
};
|
||||
|
||||
#define TAF_PENDING 0x1 /* Task is being run now */
|
||||
|
||||
#endif /* !_SYS__TASK_H_ */
|
||||
|
@ -51,6 +51,7 @@ struct taskqueue *taskqueue_create(const char *name, int mflags,
|
||||
taskqueue_enqueue_fn enqueue,
|
||||
void *context);
|
||||
int taskqueue_enqueue(struct taskqueue *queue, struct task *task);
|
||||
void taskqueue_drain(struct taskqueue *queue, struct task *task);
|
||||
struct taskqueue *taskqueue_find(const char *name);
|
||||
void taskqueue_free(struct taskqueue *queue);
|
||||
void taskqueue_run(struct taskqueue *queue);
|
||||
@ -69,6 +70,7 @@ void taskqueue_thread_enqueue(void *context);
|
||||
(task)->ta_priority = (priority); \
|
||||
(task)->ta_func = (func); \
|
||||
(task)->ta_context = (context); \
|
||||
(task)->ta_flags = 0; \
|
||||
} while (0)
|
||||
|
||||
/*
|
||||
|
Loading…
Reference in New Issue
Block a user