6 struct workqueue_work {
7 struct flist_head list;
10 struct submit_worker {
14 struct flist_head work_list;
20 struct sk_out *sk_out;
23 typedef int (workqueue_work_fn)(struct submit_worker *, struct workqueue_work *);
24 typedef bool (workqueue_pre_sleep_flush_fn)(struct submit_worker *);
25 typedef void (workqueue_pre_sleep_fn)(struct submit_worker *);
26 typedef int (workqueue_alloc_worker_fn)(struct submit_worker *);
27 typedef void (workqueue_free_worker_fn)(struct submit_worker *);
28 typedef int (workqueue_init_worker_fn)(struct submit_worker *);
29 typedef void (workqueue_exit_worker_fn)(struct submit_worker *, unsigned int *);
30 typedef void (workqueue_update_acct_fn)(struct submit_worker *);
32 struct workqueue_ops {
33 workqueue_work_fn *fn;
34 workqueue_pre_sleep_flush_fn *pre_sleep_flush_fn;
35 workqueue_pre_sleep_fn *pre_sleep_fn;
37 workqueue_update_acct_fn *update_acct_fn;
39 workqueue_alloc_worker_fn *alloc_worker_fn;
40 workqueue_free_worker_fn *free_worker_fn;
42 workqueue_init_worker_fn *init_worker_fn;
43 workqueue_exit_worker_fn *exit_worker_fn;
49 unsigned int max_workers;
51 struct thread_data *td;
52 struct workqueue_ops ops;
55 struct submit_worker *workers;
56 unsigned int next_free_worker;
58 pthread_cond_t flush_cond;
59 pthread_mutex_t flush_lock;
60 pthread_mutex_t stat_lock;
61 volatile int wake_idle;
64 int workqueue_init(struct thread_data *td, struct workqueue *wq, struct workqueue_ops *ops, unsigned int max_workers, struct sk_out *sk_out);
65 void workqueue_exit(struct workqueue *wq);
67 void workqueue_enqueue(struct workqueue *wq, struct workqueue_work *work);
68 void workqueue_flush(struct workqueue *wq);
70 static inline bool workqueue_pre_sleep_check(struct submit_worker *sw)
72 struct workqueue *wq = sw->wq;
74 if (!wq->ops.pre_sleep_flush_fn)
77 return wq->ops.pre_sleep_flush_fn(sw);
80 static inline void workqueue_pre_sleep(struct submit_worker *sw)
82 struct workqueue *wq = sw->wq;
84 if (wq->ops.pre_sleep_fn)
85 wq->ops.pre_sleep_fn(sw);
88 static inline int workqueue_init_worker(struct submit_worker *sw)
90 struct workqueue *wq = sw->wq;
92 if (!wq->ops.init_worker_fn)
95 return wq->ops.init_worker_fn(sw);
98 static inline void workqueue_exit_worker(struct submit_worker *sw,
99 unsigned int *sum_cnt)
101 struct workqueue *wq = sw->wq;
102 unsigned int tmp = 1;
104 if (!wq->ops.exit_worker_fn)
110 wq->ops.exit_worker_fn(sw, sum_cnt);