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 *);
29 struct workqueue_ops {
30 workqueue_work_fn *fn;
31 workqueue_pre_sleep_flush_fn *pre_sleep_flush_fn;
32 workqueue_pre_sleep_fn *pre_sleep_fn;
33 workqueue_alloc_worker_fn *alloc_worker_fn;
34 workqueue_free_worker_fn *free_worker_fn;
35 workqueue_init_worker_fn *init_worker_fn;
39 unsigned int max_workers;
41 struct thread_data *td;
42 struct workqueue_ops ops;
45 struct submit_worker *workers;
46 unsigned int next_free_worker;
48 pthread_cond_t flush_cond;
49 pthread_mutex_t flush_lock;
50 pthread_mutex_t stat_lock;
51 volatile int wake_idle;
54 int workqueue_init(struct thread_data *td, struct workqueue *wq, struct workqueue_ops *ops, unsigned int max_workers);
55 void workqueue_exit(struct workqueue *wq);
57 bool workqueue_enqueue(struct workqueue *wq, struct workqueue_work *work);
58 void workqueue_flush(struct workqueue *wq);
60 static inline bool workqueue_pre_sleep_check(struct submit_worker *sw)
62 struct workqueue *wq = sw->wq;
64 if (!wq->ops.pre_sleep_flush_fn)
67 return wq->ops.pre_sleep_flush_fn(sw);
70 static inline void workqueue_pre_sleep(struct submit_worker *sw)
72 struct workqueue *wq = sw->wq;
74 if (wq->ops.pre_sleep_fn)
75 wq->ops.pre_sleep_fn(sw);
78 static inline int workqueue_init_worker(struct submit_worker *sw)
80 struct workqueue *wq = sw->wq;
82 if (!wq->ops.init_worker_fn)
85 return wq->ops.init_worker_fn(sw);