summaryrefslogtreecommitdiffstats
path: root/test
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 /test
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 'test')
-rw-r--r--test/TFbuild3
-rw-r--r--test/simple1.c32
2 files changed, 35 insertions, 0 deletions
diff --git a/test/TFbuild b/test/TFbuild
new file mode 100644
index 0000000..d2648ed
--- /dev/null
+++ b/test/TFbuild
@@ -0,0 +1,3 @@
+progs-$(TEST) += simple1 sleep
+
+LIBS += $(objtree)src/libtf.a
diff --git a/test/simple1.c b/test/simple1.c
new file mode 100644
index 0000000..65a787c
--- /dev/null
+++ b/test/simple1.c
@@ -0,0 +1,32 @@
+#include <libtf/tf.h>
+#include <stdio.h>
+
+struct ctx {
+ int id;
+};
+
+static void work_fiber(void *ptr)
+{
+ struct ctx *c = (struct ctx*) ptr;
+
+ printf("Hello%d.1\n", c->id);
+ tf_yield();
+ printf("Hello%d.2\n", c->id);
+}
+
+static void init_fiber(void *ptr)
+{
+ struct ctx *c;
+ int i;
+
+ for (i = 0; i < 6; i++) {
+ c = tf_fiber_create(work_fiber, sizeof(struct ctx));
+ c->id = i;
+ tf_fiber_put(c);
+ }
+}
+
+int main(int argc, char **argv)
+{
+ return tf_main(init_fiber);
+}