summaryrefslogtreecommitdiffstats
path: root/include/libtf/fiber.h
diff options
context:
space:
mode:
authorTimo Teras <timo.teras@iki.fi>2009-11-19 14:32:11 +0200
committerTimo Teras <timo.teras@iki.fi>2009-11-24 08:12:45 +0200
commite4e54c2ec744e884f6f55c135bea78e815d28d6c (patch)
tree3278c0bdb3eedc47eaf71ef53b9ff849cb136593 /include/libtf/fiber.h
downloadlibtf-e4e54c2ec744e884f6f55c135bea78e815d28d6c.tar.bz2
libtf-e4e54c2ec744e884f6f55c135bea78e815d28d6c.tar.xz
libtf: initial commit
libtf is to be user-space cooperative threading library similar to State Threads (http://state-threads.sourceforge.net/), but with additional support for multiple cores, using better algorithms and taking advantage of new Linux kernel syscalls such as eventfd, signalfd and epoll (edge-triggered mode). Initial implementation has setjmp based user-space context switching and trivial testcase. Works on Linux/x86. TFbuild uses ideas from different build systems, namely Kbuild, but it's inner workings are quite different. All build files are included (using macro trickery) instead of recursive making. Thus the build dependency graph is complete and should yield good make performance. Also parallel stuff should work.
Diffstat (limited to 'include/libtf/fiber.h')
-rw-r--r--include/libtf/fiber.h52
1 files changed, 52 insertions, 0 deletions
diff --git a/include/libtf/fiber.h b/include/libtf/fiber.h
new file mode 100644
index 0000000..48d4924
--- /dev/null
+++ b/include/libtf/fiber.h
@@ -0,0 +1,52 @@
+/* tf.h - libtf main include
+ *
+ * Copyright (C) 2009 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_FIBER_H
+#define TF_FIBER_H
+
+#include <errno.h>
+#include <libtf/defines.h>
+#include <libtf/atomic.h>
+#include <libtf/list.h>
+
+#ifndef TF_STACK_SIZE
+#define TF_STACK_SIZE 4096
+#endif
+
+struct tf_fiber {
+ unsigned int ref_count;
+ struct tf_list_node queue_node;
+ char data[TF_EMPTY_ARRAY];
+};
+
+typedef void (*tf_fiber_proc)(void *fiber);
+
+int tf_main(tf_fiber_proc fiber_main);
+
+void *tf_fiber_create(tf_fiber_proc fiber_main, int private_size);
+void *tf_fiber_get(void *data);
+void tf_fiber_put(void *data);
+
+int tf_schedule(int err);
+void tf_kill(void *fiber);
+
+static inline int tf_yield(void)
+{
+ return tf_schedule(EAGAIN);
+}
+
+static inline int tf_exit(void)
+{
+ return tf_schedule(EFAULT);
+}
+
+#endif