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 *);
28 struct workqueue_ops {
29 workqueue_work_fn *fn;
30 workqueue_pre_sleep_flush_fn *pre_sleep_flush_fn;
31 workqueue_pre_sleep_fn *pre_sleep_fn;
32 workqueue_alloc_worker_fn *alloc_worker_fn;
33 workqueue_free_worker_fn *free_worker_fn;
37 unsigned int max_workers;
39 struct thread_data *td;
40 struct workqueue_ops ops;
43 struct submit_worker *workers;
44 unsigned int next_free_worker;
46 pthread_cond_t flush_cond;
47 pthread_mutex_t flush_lock;
48 pthread_mutex_t stat_lock;
49 volatile int wake_idle;
52 int workqueue_init(struct thread_data *td, struct workqueue *wq, struct workqueue_ops *ops, unsigned int max_workers);
53 void workqueue_exit(struct workqueue *wq);
55 bool workqueue_enqueue(struct workqueue *wq, struct workqueue_work *work);
56 void workqueue_flush(struct workqueue *wq);
58 static inline bool workqueue_pre_sleep_check(struct submit_worker *sw)
60 struct workqueue *wq = sw->wq;
62 if (!wq->ops.pre_sleep_flush_fn)
65 return wq->ops.pre_sleep_flush_fn(sw);
68 static inline void workqueue_pre_sleep(struct submit_worker *sw)
70 struct workqueue *wq = sw->wq;
72 if (wq->ops.pre_sleep_fn)
73 wq->ops.pre_sleep_fn(sw);