summaryrefslogtreecommitdiff
path: root/mainloop2.h
diff options
context:
space:
mode:
Diffstat (limited to 'mainloop2.h')
-rw-r--r--mainloop2.h67
1 files changed, 67 insertions, 0 deletions
diff --git a/mainloop2.h b/mainloop2.h
new file mode 100644
index 0000000..e78877a
--- /dev/null
+++ b/mainloop2.h
@@ -0,0 +1,67 @@
+#ifndef _MAINLOOP_H
+#define _MAINLOOP_H
+
+#include <glib.h>
+#include "jobqueue.h"
+#include "epoll.h"
+
+typedef struct MainLoop MainLoop;
+
+typedef void (* MainFdFunc) (int fd,
+ EPollEventType mask,
+ gpointer data);
+
+MainLoop *main_loop_new (Executor *executor);
+void main_loop_run (MainLoop *loop);
+void main_loop_add_fd (MainLoop *loop,
+ int fd,
+ JobQueue *queue,
+ MainFdFunc func,
+ gpointer data);
+void main_loop_set_fd_poll_mask (MainLoop *loop,
+ int fd,
+ EPollEventType poll_mask);
+void main_loop_remove_fd (MainLoop *loop,
+ int fd);
+
+/* Missing: */
+
+/* Maybe these functions really belong in the JobQueue?
+ * That would require support from the executor though.
+ * But fundamentally these are valid (in a threaded server)
+ * without fds, which is what the main loop provides.
+ * The executor already has a gcond_wait() that could be
+ * made a timed one.
+ *
+ * Note that a good priority queue is going to be needed in
+ * whatever class eventually implements these.
+ *
+ * Also, note that cancellation support is essential for these
+ * tasks.
+ *
+ * Yes, should probably happen in JobQueue + Executor:
+ *
+ * executor should maintain all jobs in a priority queue
+ * sorted by execution time.
+ *
+ * normal jobs get an execution time of "now", where timeout
+ * jobs get an execution of sometime in the future.
+ *
+ * this avoids starvation of timeouts since a timeout will
+ * eventually move to the front of the queue (with a time
+ * in the past possibly)
+ *
+ *
+ *
+ */
+#if 0
+void main_loop_add_timeout (MainLoop *loop,
+ JobQueue *queue,
+ MainFunc *task);
+void main_loop_add_idle (MainLoop *loop,
+ JobQueue *queue,
+ MainFunc *task);
+#endif
+
+#endif /* _MAINLOO_H_ */
+