Commit | Line | Data |
---|---|---|
a9da8ab2 JA |
1 | #ifndef FIO_RATE_H |
2 | #define FIO_RATE_H | |
3 | ||
4 | #include "flist.h" | |
5 | ||
88271841 JA |
6 | struct workqueue_work { |
7 | struct flist_head list; | |
8 | }; | |
9 | ||
5bb79f69 JA |
10 | typedef void (workqueue_work_fn)(struct thread_data *, struct workqueue_work *); |
11 | typedef bool (workqueue_pre_sleep_flush_fn)(struct thread_data *); | |
12 | typedef void (workqueue_pre_sleep_fn)(struct thread_data *); | |
13 | ||
14 | struct workqueue_ops { | |
15 | workqueue_work_fn *fn; | |
16 | workqueue_pre_sleep_flush_fn *pre_sleep_flush_fn; | |
17 | workqueue_pre_sleep_fn *pre_sleep_fn; | |
18 | }; | |
a9da8ab2 JA |
19 | |
20 | struct workqueue { | |
21 | unsigned int max_workers; | |
22 | ||
23 | struct thread_data *td; | |
5bb79f69 | 24 | struct workqueue_ops ops; |
a9da8ab2 JA |
25 | |
26 | uint64_t work_seq; | |
27 | struct submit_worker *workers; | |
28 | unsigned int next_free_worker; | |
29 | ||
30 | pthread_cond_t flush_cond; | |
31 | pthread_mutex_t flush_lock; | |
2a274336 | 32 | pthread_mutex_t stat_lock; |
a9da8ab2 JA |
33 | volatile int wake_idle; |
34 | }; | |
35 | ||
5bb79f69 | 36 | int workqueue_init(struct thread_data *td, struct workqueue *wq, struct workqueue_ops *ops, unsigned int max_workers); |
a9da8ab2 JA |
37 | void workqueue_exit(struct workqueue *wq); |
38 | ||
88271841 | 39 | bool workqueue_enqueue(struct workqueue *wq, struct workqueue_work *work); |
a9da8ab2 JA |
40 | void workqueue_flush(struct workqueue *wq); |
41 | ||
5bb79f69 JA |
42 | static inline bool workqueue_pre_sleep_check(struct workqueue *wq) |
43 | { | |
44 | if (!wq->ops.pre_sleep_flush_fn) | |
45 | return false; | |
46 | ||
47 | return wq->ops.pre_sleep_flush_fn(wq->td); | |
48 | } | |
49 | ||
50 | static inline void workqueue_pre_sleep(struct workqueue *wq) | |
51 | { | |
52 | if (wq->ops.pre_sleep_fn) | |
53 | wq->ops.pre_sleep_fn(wq->td); | |
54 | } | |
55 | ||
a9da8ab2 | 56 | #endif |