6 struct workqueue_work {
7 struct flist_head list;
10 struct submit_worker {
14 struct flist_head work_list;
22 typedef void (workqueue_work_fn)(struct submit_worker *, struct workqueue_work *);
23 typedef bool (workqueue_pre_sleep_flush_fn)(struct submit_worker *);
24 typedef void (workqueue_pre_sleep_fn)(struct submit_worker *);
25 typedef int (workqueue_alloc_worker_fn)(struct submit_worker *);
26 typedef void (workqueue_free_worker_fn)(struct submit_worker *);
27 typedef int (workqueue_init_worker_fn)(struct submit_worker *);
28 typedef void (workqueue_exit_worker_fn)(struct submit_worker *);
30 struct workqueue_ops {
31 workqueue_work_fn *fn;
32 workqueue_pre_sleep_flush_fn *pre_sleep_flush_fn;
33 workqueue_pre_sleep_fn *pre_sleep_fn;
35 workqueue_alloc_worker_fn *alloc_worker_fn;
36 workqueue_free_worker_fn *free_worker_fn;
38 workqueue_init_worker_fn *init_worker_fn;
39 workqueue_exit_worker_fn *exit_worker_fn;
43 unsigned int max_workers;
45 struct thread_data *td;
46 struct workqueue_ops ops;
49 struct submit_worker *workers;
50 unsigned int next_free_worker;
52 pthread_cond_t flush_cond;
53 pthread_mutex_t flush_lock;
54 pthread_mutex_t stat_lock;
55 volatile int wake_idle;
58 int workqueue_init(struct thread_data *td, struct workqueue *wq, struct workqueue_ops *ops, unsigned int max_workers);
59 void workqueue_exit(struct workqueue *wq);
61 bool workqueue_enqueue(struct workqueue *wq, struct workqueue_work *work);
62 void workqueue_flush(struct workqueue *wq);
64 static inline bool workqueue_pre_sleep_check(struct submit_worker *sw)
66 struct workqueue *wq = sw->wq;
68 if (!wq->ops.pre_sleep_flush_fn)
71 return wq->ops.pre_sleep_flush_fn(sw);
74 static inline void workqueue_pre_sleep(struct submit_worker *sw)
76 struct workqueue *wq = sw->wq;
78 if (wq->ops.pre_sleep_fn)
79 wq->ops.pre_sleep_fn(sw);
82 static inline int workqueue_init_worker(struct submit_worker *sw)
84 struct workqueue *wq = sw->wq;
86 if (!wq->ops.init_worker_fn)
89 return wq->ops.init_worker_fn(sw);
92 static inline void workqueue_exit_worker(struct submit_worker *sw)
94 struct workqueue *wq = sw->wq;
96 if (!wq->ops.exit_worker_fn)
99 wq->ops.exit_worker_fn(sw);