summaryrefslogtreecommitdiffstats
path: root/src/fiber.c
diff options
context:
space:
mode:
authorTimo Teras <timo.teras@iki.fi>2009-11-25 15:11:20 +0200
committerTimo Teras <timo.teras@iki.fi>2009-11-25 15:11:20 +0200
commit2b19cc385163a43b1d559074a795a8aaab751185 (patch)
tree322473e3446153c1bbaac8d6d990734b09d15977 /src/fiber.c
parentfc1044daf51f32b9d85f8497e4e0bd5a3c1e7fe9 (diff)
downloadlibtf-2b19cc385163a43b1d559074a795a8aaab751185.tar.bz2
libtf-2b19cc385163a43b1d559074a795a8aaab751185.tar.xz
libtf: implement basic networking i/o
pretty much untested. also some slight changes to how scheduler is invoked.
Diffstat (limited to 'src/fiber.c')
-rw-r--r--src/fiber.c38
1 files changed, 11 insertions, 27 deletions
diff --git a/src/fiber.c b/src/fiber.c
index 15c533a..aa83fa8 100644
--- a/src/fiber.c
+++ b/src/fiber.c
@@ -92,7 +92,6 @@ static void run_fiber(struct tf_scheduler *sched, struct tf_fiber *f)
sched->num_fibers--;
break;
case TF_WAKEUP_IMMEDIATE:
- case TF_WAKEUP_TIMEOUT:
break;
default:
TF_BUG_ON("bad scheduler call from fiber");
@@ -152,7 +151,7 @@ int tf_main(tf_fiber_proc main_fiber)
} else
timeout = -1;
- if (tf_poll(timeout) == TF_WAKEUP_TIMEOUT) {
+ if (tf_poll(timeout) == TF_WAKEUP_TIMEOUT && timeout >= 0) {
sched->scheduler_time += timeout;
process_heap(sched);
}
@@ -164,30 +163,20 @@ int tf_main(tf_fiber_proc main_fiber)
return 0;
}
-int tf_schedule(int wakeup)
+int tf_schedule(tf_mtime_diff_t milliseconds)
{
struct tf_scheduler *sched = tf_get_scheduler();
struct tf_fiber *schedf = container_of((void*) sched, struct tf_fiber, data);
struct tf_fiber *f = sched->active_fiber;
- if (wakeup != TF_WAKEUP_TIMEOUT)
- tf_heap_delete(&f->heap_node, &sched->heap);
f->wakeup_type = TF_WAKEUP_NONE;
-
- return tf_uctx_transfer(f, schedf, wakeup);
-}
-
-int tf_schedule_timeout(int milliseconds)
-{
- struct tf_scheduler *sched = tf_get_scheduler();
- struct tf_fiber *f = sched->active_fiber;
-
- if (milliseconds <= 0) {
+ if (milliseconds == TF_NO_TIMEOUT)
tf_heap_delete(&f->heap_node, &sched->heap);
- return TF_WAKEUP_IMMEDIATE;
- }
- tf_heap_change(&f->heap_node, &sched->heap, tf_mtime() + milliseconds);
- return TF_WAKEUP_TIMEOUT;
+ else if (milliseconds != TF_NO_TIMEOUT_CHANGE)
+ tf_heap_change(&f->heap_node, &sched->heap,
+ tf_mtime() + milliseconds);
+
+ return tf_uctx_transfer(f, schedf, TF_WAKEUP_IMMEDIATE);
}
void tf_wakeup(struct tf_fiber *fiber, int wakeup_type)
@@ -204,9 +193,10 @@ void tf_exit(void)
{
struct tf_scheduler *sched = tf_get_scheduler();
struct tf_fiber *f = sched->active_fiber;
+ struct tf_fiber *schedf = container_of((void*) sched, struct tf_fiber, data);
tf_heap_delete(&f->heap_node, &sched->heap);
- tf_schedule(TF_WAKEUP_KILL);
+ tf_uctx_transfer(f, schedf, TF_WAKEUP_KILL);
TF_BUG_ON(1);
}
@@ -220,12 +210,6 @@ int tf_yield(void)
struct tf_fiber *f = sched->active_fiber;
tf_list_add_tail(&f->queue_node, &sched->run_q);
- return tf_schedule(TF_WAKEUP_IMMEDIATE);
-}
-
-int tf_msleep(int milliseconds)
-{
- tf_schedule_timeout(milliseconds);
- return tf_schedule(TF_WAKEUP_TIMEOUT);
+ return tf_schedule(TF_NO_TIMEOUT);
}