workqueue: remove knowledge of td queue state
[fio.git] / workqueue.h
index 26b3aee1602171e9b090363c275003a53b13791a..837b221d6790f0176eecbc992ea66e9ef5b4691f 100644 (file)
@@ -7,13 +7,21 @@ struct workqueue_work {
        struct flist_head list;
 };
 
-typedef void (workqueue_fn)(struct thread_data *, struct workqueue_work *);
+typedef void (workqueue_work_fn)(struct thread_data *, struct workqueue_work *);
+typedef bool (workqueue_pre_sleep_flush_fn)(struct thread_data *);
+typedef void (workqueue_pre_sleep_fn)(struct thread_data *);
+
+struct workqueue_ops {
+       workqueue_work_fn *fn;
+       workqueue_pre_sleep_flush_fn *pre_sleep_flush_fn;
+       workqueue_pre_sleep_fn *pre_sleep_fn;
+};
 
 struct workqueue {
        unsigned int max_workers;
 
        struct thread_data *td;
-       workqueue_fn *fn;
+       struct workqueue_ops ops;
 
        uint64_t work_seq;
        struct submit_worker *workers;
@@ -25,10 +33,24 @@ struct workqueue {
        volatile int wake_idle;
 };
 
-int workqueue_init(struct thread_data *td, struct workqueue *wq, workqueue_fn *fn, unsigned int max_workers);
+int workqueue_init(struct thread_data *td, struct workqueue *wq, struct workqueue_ops *ops, unsigned int max_workers);
 void workqueue_exit(struct workqueue *wq);
 
 bool workqueue_enqueue(struct workqueue *wq, struct workqueue_work *work);
 void workqueue_flush(struct workqueue *wq);
 
+static inline bool workqueue_pre_sleep_check(struct workqueue *wq)
+{
+       if (!wq->ops.pre_sleep_flush_fn)
+               return false;
+
+       return wq->ops.pre_sleep_flush_fn(wq->td);
+}
+
+static inline void workqueue_pre_sleep(struct workqueue *wq)
+{
+       if (wq->ops.pre_sleep_fn)
+               wq->ops.pre_sleep_fn(wq->td);
+}
+
 #endif