summaryrefslogtreecommitdiffstats
path: root/include/libtf/scheduler.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/libtf/scheduler.h')
-rw-r--r--include/libtf/scheduler.h64
1 files changed, 64 insertions, 0 deletions
diff --git a/include/libtf/scheduler.h b/include/libtf/scheduler.h
new file mode 100644
index 0000000..cc8db70
--- /dev/null
+++ b/include/libtf/scheduler.h
@@ -0,0 +1,64 @@
+/* scheduler.h - libtf fiber scheduler header
+ *
+ * Copyright (C) 2009-2010 Timo Teräs <timo.teras@iki.fi>
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 or later as
+ * published by the Free Software Foundation.
+ *
+ * See http://www.gnu.org/ for details.
+ */
+
+#ifndef TF_SCHEDULER_H
+#define TF_SCHEDULER_H
+
+#include <libtf/atomic.h>
+#include <libtf/list.h>
+#include <libtf/heap.h>
+#include <libtf/fiber.h>
+
+struct tf_scheduler {
+ struct tf_list_head scheduled_q;
+ struct tf_list_head running_q;
+ struct tf_heap_head heap;
+ void * active_fiber;
+ void * main_fiber;
+ int num_fibers;
+ tf_mtime_t scheduler_time;
+ unsigned long poll_data[2];
+};
+
+static inline
+struct tf_scheduler *tf_scheduler_get_current(void)
+{
+ extern struct tf_scheduler *__tf_scheduler;
+ TF_BUG_ON(__tf_scheduler == NULL);
+ return __tf_scheduler;
+}
+
+static inline
+tf_mtime_t tf_scheduler_get_mtime(void)
+{
+ return tf_scheduler_get_current()->scheduler_time;
+}
+
+struct tf_scheduler *tf_scheduler_create(void);
+int tf_scheduler_enable(struct tf_scheduler *);
+void tf_scheduler_disable(void);
+
+static inline struct tf_scheduler *
+tf_scheduler_get(struct tf_scheduler *s)
+{
+ tf_fiber_get(s);
+ return s;
+}
+
+static inline void
+tf_scheduler_put(struct tf_scheduler *s)
+{
+ tf_fiber_put(s);
+}
+
+#endif
+