diff options
author | Timo Teras <timo.teras@iki.fi> | 2010-03-10 13:58:39 +0200 |
---|---|---|
committer | Timo Teras <timo.teras@iki.fi> | 2010-03-10 13:58:39 +0200 |
commit | 5ef38570315dc68d7ddf8d9475d9a8830528e8a4 (patch) | |
tree | f88fc542b5231614ac6c22a75baea90d82449d6c /test | |
parent | 43e69b26126b8708b70680c6b4806eb3844386ab (diff) | |
download | libtf-5ef38570315dc68d7ddf8d9475d9a8830528e8a4.tar.bz2 libtf-5ef38570315dc68d7ddf8d9475d9a8830528e8a4.tar.xz |
libtf: separate scheduler fibre, change the core api
Diffstat (limited to 'test')
-rw-r--r-- | test/httpget.c | 16 | ||||
-rw-r--r-- | test/read.c | 11 | ||||
-rw-r--r-- | test/simple1.c | 13 | ||||
-rw-r--r-- | test/sleep.c | 17 |
4 files changed, 23 insertions, 34 deletions
diff --git a/test/httpget.c b/test/httpget.c index fed6c06..9aec886 100644 --- a/test/httpget.c +++ b/test/httpget.c @@ -44,20 +44,16 @@ err: ctx->hostname, bytes, -r, strerror(-r)); } -static void init_fiber(void *ptr) +int main(int argc, char **argv) { - struct tf_main_ctx *ctx = (struct tf_main_ctx *) ptr; struct ctx *c; int i; - for (i = 1; i < ctx->argc; i++) { - c = tf_fiber_create(ping_fiber, sizeof(struct ctx)); - c->hostname = ctx->argv[i]; + tf_scheduler_enable(NULL); + for (i = 1; i < argc; i++) { + c = tf_fiber_create(NULL, ping_fiber, sizeof(struct ctx)); + c->hostname = argv[i]; tf_fiber_put(c); } -} - -int main(int argc, char **argv) -{ - return tf_main_args(init_fiber, argc, argv); + tf_scheduler_disable(); } diff --git a/test/read.c b/test/read.c index 6d8306b..3d318a3 100644 --- a/test/read.c +++ b/test/read.c @@ -32,13 +32,10 @@ static void io_fiber(void *ptr) tf_close(&fin); } -static void init_fiber(void *ptr) -{ - tf_fiber_put(tf_fiber_create(time_fiber, 0)); - tf_fiber_put(tf_fiber_create(io_fiber, 0)); -} - int main(int argc, char **argv) { - return tf_main(init_fiber); + tf_scheduler_enable(NULL); + tf_fiber_put(tf_fiber_create(NULL, time_fiber, 0)); + tf_fiber_put(tf_fiber_create(NULL, io_fiber, 0)); + tf_scheduler_disable(); } diff --git a/test/simple1.c b/test/simple1.c index 65a787c..6a05b7a 100644 --- a/test/simple1.c +++ b/test/simple1.c @@ -10,23 +10,20 @@ static void work_fiber(void *ptr) struct ctx *c = (struct ctx*) ptr; printf("Hello%d.1\n", c->id); - tf_yield(); + tf_fiber_yield(); printf("Hello%d.2\n", c->id); } -static void init_fiber(void *ptr) +int main(int argc, char **argv) { struct ctx *c; int i; + tf_scheduler_enable(NULL); for (i = 0; i < 6; i++) { - c = tf_fiber_create(work_fiber, sizeof(struct ctx)); + c = tf_fiber_create(NULL, work_fiber, sizeof(struct ctx)); c->id = i; tf_fiber_put(c); } -} - -int main(int argc, char **argv) -{ - return tf_main(init_fiber); + tf_scheduler_disable(); } diff --git a/test/sleep.c b/test/sleep.c index 7e39b5c..82399e1 100644 --- a/test/sleep.c +++ b/test/sleep.c @@ -8,24 +8,23 @@ struct ctx { static void work_fiber(void *ptr) { //struct ctx *c = (struct ctx*) ptr; - tf_msleep(rand() % 5000); + printf("one\n"); tf_msleep(rand() % 5000); + printf("two\n"); tf_msleep(rand() % 5000); + printf("three\n"); } -static void init_fiber(void *ptr) +int main(int argc, char **argv) { struct ctx *c; int i; - for (i = 0; i < 1000; i++) { - c = tf_fiber_create(work_fiber, sizeof(struct ctx)); + tf_scheduler_enable(NULL); + for (i = 0; i < 100; i++) { + c = tf_fiber_create(NULL, work_fiber, sizeof(struct ctx)); tf_fiber_put(c); } -} - -int main(int argc, char **argv) -{ - return tf_main(init_fiber); + tf_scheduler_disable(); } |