13 struct workqueue_work {
14 struct flist_head list;
17 struct submit_worker {
21 struct flist_head work_list;
27 struct sk_out *sk_out;
30 typedef int (workqueue_work_fn)(struct submit_worker *, struct workqueue_work *);
31 typedef bool (workqueue_pre_sleep_flush_fn)(struct submit_worker *);
32 typedef void (workqueue_pre_sleep_fn)(struct submit_worker *);
33 typedef int (workqueue_alloc_worker_fn)(struct submit_worker *);
34 typedef void (workqueue_free_worker_fn)(struct submit_worker *);
35 typedef int (workqueue_init_worker_fn)(struct submit_worker *);
36 typedef void (workqueue_exit_worker_fn)(struct submit_worker *, unsigned int *);
37 typedef void (workqueue_update_acct_fn)(struct submit_worker *);
39 struct workqueue_ops {
40 workqueue_work_fn *fn;
41 workqueue_pre_sleep_flush_fn *pre_sleep_flush_fn;
42 workqueue_pre_sleep_fn *pre_sleep_fn;
44 workqueue_update_acct_fn *update_acct_fn;
46 workqueue_alloc_worker_fn *alloc_worker_fn;
47 workqueue_free_worker_fn *free_worker_fn;
49 workqueue_init_worker_fn *init_worker_fn;
50 workqueue_exit_worker_fn *exit_worker_fn;
56 unsigned int max_workers;
58 struct thread_data *td;
59 struct workqueue_ops ops;
62 struct submit_worker *workers;
63 unsigned int next_free_worker;
65 pthread_cond_t flush_cond;
66 pthread_mutex_t flush_lock;
67 pthread_mutex_t stat_lock;
68 volatile int wake_idle;
71 int workqueue_init(struct thread_data *td, struct workqueue *wq, struct workqueue_ops *ops, unsigned int max_workers, struct sk_out *sk_out);
72 void workqueue_exit(struct workqueue *wq);
74 void workqueue_enqueue(struct workqueue *wq, struct workqueue_work *work);
75 void workqueue_flush(struct workqueue *wq);
77 static inline bool workqueue_pre_sleep_check(struct submit_worker *sw)
79 struct workqueue *wq = sw->wq;
81 if (!wq->ops.pre_sleep_flush_fn)
84 return wq->ops.pre_sleep_flush_fn(sw);
87 static inline void workqueue_pre_sleep(struct submit_worker *sw)
89 struct workqueue *wq = sw->wq;
91 if (wq->ops.pre_sleep_fn)
92 wq->ops.pre_sleep_fn(sw);
95 static inline int workqueue_init_worker(struct submit_worker *sw)
97 struct workqueue *wq = sw->wq;
99 if (!wq->ops.init_worker_fn)
102 return wq->ops.init_worker_fn(sw);
105 static inline void workqueue_exit_worker(struct submit_worker *sw,
106 unsigned int *sum_cnt)
108 struct workqueue *wq = sw->wq;
109 unsigned int tmp = 1;
111 if (!wq->ops.exit_worker_fn)
117 wq->ops.exit_worker_fn(sw, sum_cnt);