workqueue: remove knowledge of td queue state
[fio.git] / workqueue.h
index 3a24f254d650fc66d7833bba79e883e2e33fedf7..837b221d6790f0176eecbc992ea66e9ef5b4691f 100644 (file)
@@ -3,13 +3,25 @@
 
 #include "flist.h"
 
-typedef void (workqueue_fn)(struct thread_data *, struct io_u *);
+struct workqueue_work {
+       struct flist_head list;
+};
+
+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;
@@ -21,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 io_u *io_u);
+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