From 5ef38570315dc68d7ddf8d9475d9a8830528e8a4 Mon Sep 17 00:00:00 2001 From: Timo Teras Date: Wed, 10 Mar 2010 13:58:39 +0200 Subject: libtf: separate scheduler fibre, change the core api --- include/libtf/fiber.h | 82 +++++++++++++-------------------------------------- 1 file changed, 20 insertions(+), 62 deletions(-) (limited to 'include/libtf/fiber.h') diff --git a/include/libtf/fiber.h b/include/libtf/fiber.h index ce3745b..a140607 100644 --- a/include/libtf/fiber.h +++ b/include/libtf/fiber.h @@ -1,6 +1,6 @@ -/* fiber.h - libtf fiber scheduler header +/* fiber.h - libtf fiber manager header * - * Copyright (C) 2009 Timo Teräs + * Copyright (C) 2009-2010 Timo Teräs * All rights reserved. * * This program is free software; you can redistribute it and/or modify it @@ -15,8 +15,6 @@ #include #include -#include -#include #include /* Fiber wakeup reasons */ @@ -27,64 +25,31 @@ #define TF_WAKEUP_THIS_TIMEOUT -ETIMEDOUT #define TF_WAKEUP_FD -EIO -struct tf_poll_data { - int epoll_fd; - int num_waiters; -}; - -/* Scheduler */ -struct tf_fiber; +/* Fiber management */ +struct tf_scheduler; +typedef void (*tf_fiber_proc)(void *fiber); -struct tf_scheduler { - struct tf_list_head run_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; -}; +void *__tf_fiber_create(tf_fiber_proc fiber_main, int private_size); +void *tf_fiber_create(struct tf_scheduler *sched, + tf_fiber_proc fiber_main, int private_size); +void *tf_fiber_get(void *data); +void tf_fiber_put(void *data); +void __tf_fiber_wakeup(void *data, int wakeup_type); +void __tf_fiber_wakeup_heapnode(struct tf_heap_node *node); +int __tf_fiber_schedule(void); +int __tf_fiber_bind_scheduler(struct tf_scheduler *sched); +int __tf_fiber_release_scheduler(struct tf_scheduler *sched); -struct tf_main_ctx { - int argc; - char ** argv; -}; +void tf_fiber_exit(void) attribute_noreturn; +void tf_fiber_kill(void *fiber); +int tf_fiber_yield(void); +/* Scheduling and fiber management */ struct tf_timeout { tf_mtime_t saved_timeout; unsigned int timeout_change; }; -static inline -struct tf_scheduler *tf_get_scheduler(void) -{ - extern struct tf_scheduler *__tf_scheduler; - return __tf_scheduler; -} - -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; -} - -/* Fiber creation */ -typedef void (*tf_fiber_proc)(void *fiber); -int tf_main_args(tf_fiber_proc fiber_main, int argc, char **argv); -static inline int tf_main(tf_fiber_proc fiber_main) -{ - return tf_main_args(fiber_main, 0, NULL); -} - -void *tf_fiber_create(tf_fiber_proc fiber_main, int private_size); -void *tf_fiber_get(void *data); -void tf_fiber_put(void *data); - #define tf_timed(func, timeout) \ ({ \ struct tf_timeout __timeout; \ @@ -92,7 +57,6 @@ void tf_fiber_put(void *data); tf_timeout_pop(&__timeout, (func)); \ }) -//* Scheduling and fiber management */ void tf_timeout_push(struct tf_timeout *timeout, tf_mtime_diff_t milliseconds); int __tf_timeout_pop(struct tf_timeout *timeout, int err); @@ -103,17 +67,11 @@ static inline int tf_timeout_pop(struct tf_timeout *timeout, int err) return err; } -int tf_schedule(void); -void tf_wakeup(struct tf_fiber *fiber, int wakeup_type); -void tf_exit(void) attribute_noreturn; -void tf_kill(void *fiber); -int tf_yield(void); - static inline int tf_msleep(tf_mtime_diff_t milliseconds) { int r; - r = tf_timed(tf_schedule(), milliseconds); + r = tf_timed(__tf_fiber_schedule(), milliseconds); if (r == TF_WAKEUP_THIS_TIMEOUT) r = 0; return r; -- cgit v1.2.3