summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorTimo Teras <timo.teras@iki.fi>2009-11-24 11:36:24 +0200
committerTimo Teras <timo.teras@iki.fi>2009-11-24 13:26:52 +0200
commit3ea1a77fb5419ffd2f9c997977b383b5faf75423 (patch)
tree6f848510e07e11ca0ce34939bcb7944dfa49a4f5 /test
parente4e54c2ec744e884f6f55c135bea78e815d28d6c (diff)
downloadlibtf-3ea1a77fb5419ffd2f9c997977b383b5faf75423.tar.bz2
libtf-3ea1a77fb5419ffd2f9c997977b383b5faf75423.tar.xz
libtf: implement timeouts
internally put sleepers to d-ary heap based priority queue. the heap value is compared with overflow.
Diffstat (limited to 'test')
-rw-r--r--test/sleep.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/test/sleep.c b/test/sleep.c
new file mode 100644
index 0000000..7e39b5c
--- /dev/null
+++ b/test/sleep.c
@@ -0,0 +1,31 @@
+#include <libtf/tf.h>
+#include <stdio.h>
+
+struct ctx {
+ int timeout;
+};
+
+static void work_fiber(void *ptr)
+{
+ //struct ctx *c = (struct ctx*) ptr;
+
+ tf_msleep(rand() % 5000);
+ tf_msleep(rand() % 5000);
+ tf_msleep(rand() % 5000);
+}
+
+static void init_fiber(void *ptr)
+{
+ struct ctx *c;
+ int i;
+
+ for (i = 0; i < 1000; i++) {
+ c = tf_fiber_create(work_fiber, sizeof(struct ctx));
+ tf_fiber_put(c);
+ }
+}
+
+int main(int argc, char **argv)
+{
+ return tf_main(init_fiber);
+}