Implement drain_workqueue() function.
MFC after: 1 week Sponsored by: Mellanox Technologies
This commit is contained in:
parent
5a4cafab40
commit
67489f9300
@ -36,10 +36,13 @@
|
||||
#include <linux/timer.h>
|
||||
#include <linux/slab.h>
|
||||
|
||||
#include <asm/atomic.h>
|
||||
|
||||
#include <sys/taskqueue.h>
|
||||
|
||||
struct workqueue_struct {
|
||||
struct taskqueue *taskqueue;
|
||||
atomic_t draining;
|
||||
};
|
||||
|
||||
struct work_struct {
|
||||
@ -95,6 +98,9 @@ static inline int
|
||||
queue_work(struct workqueue_struct *wq, struct work_struct *work)
|
||||
{
|
||||
work->taskqueue = wq->taskqueue;
|
||||
/* Check for draining */
|
||||
if (atomic_read(&wq->draining) != 0)
|
||||
return (!work->work_task.ta_pending);
|
||||
/* Return opposite value to align with Linux logic */
|
||||
return (!taskqueue_enqueue(wq->taskqueue, &work->work_task));
|
||||
}
|
||||
@ -106,7 +112,9 @@ queue_delayed_work(struct workqueue_struct *wq, struct delayed_work *work,
|
||||
int pending;
|
||||
|
||||
work->work.taskqueue = wq->taskqueue;
|
||||
if (delay != 0) {
|
||||
if (atomic_read(&wq->draining) != 0) {
|
||||
pending = work->work.work_task.ta_pending;
|
||||
} else if (delay != 0) {
|
||||
pending = work->work.work_task.ta_pending;
|
||||
callout_reset(&work->timer, delay, linux_delayed_work_fn, work);
|
||||
} else {
|
||||
@ -124,6 +132,7 @@ schedule_delayed_work(struct delayed_work *dwork,
|
||||
struct workqueue_struct wq;
|
||||
|
||||
wq.taskqueue = taskqueue_thread;
|
||||
atomic_set(&wq.draining, 0);
|
||||
return (queue_delayed_work(&wq, dwork, delay));
|
||||
}
|
||||
|
||||
@ -153,6 +162,14 @@ flush_taskqueue(struct taskqueue *tq)
|
||||
PRELE(curproc);
|
||||
}
|
||||
|
||||
static inline void
|
||||
drain_workqueue(struct workqueue_struct *wq)
|
||||
{
|
||||
atomic_inc(&wq->draining);
|
||||
flush_taskqueue(wq->taskqueue);
|
||||
atomic_dec(&wq->draining);
|
||||
}
|
||||
|
||||
static inline int
|
||||
cancel_work_sync(struct work_struct *work)
|
||||
{
|
||||
|
@ -945,6 +945,7 @@ linux_create_workqueue_common(const char *name, int cpus)
|
||||
wq = kmalloc(sizeof(*wq), M_WAITOK);
|
||||
wq->taskqueue = taskqueue_create(name, M_WAITOK,
|
||||
taskqueue_thread_enqueue, &wq->taskqueue);
|
||||
atomic_set(&wq->draining, 0);
|
||||
taskqueue_start_threads(&wq->taskqueue, cpus, PWAIT, "%s", name);
|
||||
|
||||
return (wq);
|
||||
|
Loading…
x
Reference in New Issue
Block a user