diff options
author | Timo Teras <timo.teras@iki.fi> | 2009-11-25 10:52:15 +0200 |
---|---|---|
committer | Timo Teras <timo.teras@iki.fi> | 2009-11-25 10:52:15 +0200 |
commit | fc1044daf51f32b9d85f8497e4e0bd5a3c1e7fe9 (patch) | |
tree | 52e11c88f17c47c0d086761e50b266f5c5ccd061 /include/libtf/fiber.h | |
parent | cec85dedb7fd66cf2c23cafadd7c53eb7afed78f (diff) | |
download | libtf-fc1044daf51f32b9d85f8497e4e0bd5a3c1e7fe9.tar.bz2 libtf-fc1044daf51f32b9d85f8497e4e0bd5a3c1e7fe9.tar.xz |
libtf: implement basic file i/o with epoll
some scetching of i/o api, and implement basic read and write
functionality. integrate polling to scheduler and an epoll based
polling mechanism.
Diffstat (limited to 'include/libtf/fiber.h')
-rw-r--r-- | include/libtf/fiber.h | 45 |
1 files changed, 31 insertions, 14 deletions
diff --git a/include/libtf/fiber.h b/include/libtf/fiber.h index 09d5ef1..91c0b3b 100644 --- a/include/libtf/fiber.h +++ b/include/libtf/fiber.h @@ -1,4 +1,4 @@ -/* tf.h - libtf main include +/* fiber.h - libtf fiber scheduler header * * Copyright (C) 2009 Timo Teräs <timo.teras@iki.fi> * All rights reserved. @@ -19,16 +19,31 @@ #include <libtf/list.h> #include <libtf/heap.h> +#define TF_UCTX_H "uctx-setjmp.h" + +/* Fiber wakeup reasons */ +#define TF_WAKEUP_NONE 0 +#define TF_WAKEUP_IMMEDIATE EAGAIN +#define TF_WAKEUP_KILL EINTR +#define TF_WAKEUP_TIMEOUT ETIMEDOUT +#define TF_WAKEUP_FD EIO + /* Scheduler */ +struct tf_fiber; + +struct tf_poll_data { + int epoll_fd; + int num_waiters; +}; + struct tf_scheduler { struct tf_list_head run_q; - struct tf_list_head sleep_q; struct tf_heap_head heap; - struct tf_fiber * active_fiber; int num_fibers; - tf_mtime_t scheduler_time; + struct tf_poll_data poll_data; + }; static inline @@ -39,6 +54,12 @@ struct tf_scheduler *tf_get_scheduler(void) } static inline +struct tf_fiber *tf_get_fiber(void) +{ + return tf_get_scheduler()->active_fiber; +} + +static inline tf_mtime_t tf_mtime(void) { return tf_get_scheduler()->scheduler_time; @@ -53,18 +74,14 @@ void *tf_fiber_get(void *data); void tf_fiber_put(void *data); /* Scheduling and fiber management */ -int tf_schedule(int err); -int tf_msleep(int milliseconds); +void tf_exit(void) attribute_noreturn; void tf_kill(void *fiber); -static inline int tf_yield(void) -{ - return tf_schedule(EAGAIN); -} +int tf_schedule(int wakeup_type); +int tf_schedule_timeout(int milliseconds); +void tf_wakeup(struct tf_fiber *fiber, int wakeup_type); -static inline int tf_exit(void) -{ - return tf_schedule(EFAULT); -} +int tf_yield(void); +int tf_msleep(int milliseconds); #endif |