6 struct workqueue_work {
7 struct flist_head list;
10 struct submit_worker {
14 struct flist_head work_list;
22 typedef int (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 *, unsigned int *);
29 typedef void (workqueue_update_acct_fn)(struct submit_worker *);
31 struct workqueue_ops {
32 workqueue_work_fn *fn;
33 workqueue_pre_sleep_flush_fn *pre_sleep_flush_fn;
34 workqueue_pre_sleep_fn *pre_sleep_fn;
36 workqueue_update_acct_fn *update_acct_fn;
38 workqueue_alloc_worker_fn *alloc_worker_fn;
39 workqueue_free_worker_fn *free_worker_fn;
41 workqueue_init_worker_fn *init_worker_fn;
42 workqueue_exit_worker_fn *exit_worker_fn;
48 unsigned int max_workers;
50 struct thread_data *td;
51 struct workqueue_ops ops;
54 struct submit_worker *workers;
55 unsigned int next_free_worker;
57 pthread_cond_t flush_cond;
58 pthread_mutex_t flush_lock;
59 pthread_mutex_t stat_lock;
60 volatile int wake_idle;
63 int workqueue_init(struct thread_data *td, struct workqueue *wq, struct workqueue_ops *ops, unsigned int max_workers);
64 void workqueue_exit(struct workqueue *wq);
66 void workqueue_enqueue(struct workqueue *wq, struct workqueue_work *work);
67 void workqueue_flush(struct workqueue *wq);
69 static inline bool workqueue_pre_sleep_check(struct submit_worker *sw)
71 struct workqueue *wq = sw->wq;
73 if (!wq->ops.pre_sleep_flush_fn)
76 return wq->ops.pre_sleep_flush_fn(sw);
79 static inline void workqueue_pre_sleep(struct submit_worker *sw)
81 struct workqueue *wq = sw->wq;
83 if (wq->ops.pre_sleep_fn)
84 wq->ops.pre_sleep_fn(sw);
87 static inline int workqueue_init_worker(struct submit_worker *sw)
89 struct workqueue *wq = sw->wq;
91 if (!wq->ops.init_worker_fn)
94 return wq->ops.init_worker_fn(sw);
97 static inline void workqueue_exit_worker(struct submit_worker *sw,
98 unsigned int *sum_cnt)
100 struct workqueue *wq = sw->wq;
101 unsigned int tmp = 1;
103 if (!wq->ops.exit_worker_fn)
109 wq->ops.exit_worker_fn(sw, sum_cnt);