/* tf.h - libtf main include * * Copyright (C) 2009 Timo Teräs * All rights reserved. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 or later as * published by the Free Software Foundation. * * See http://www.gnu.org/ for details. */ #ifndef TF_FIBER_H #define TF_FIBER_H #include #include #include #include #ifndef TF_STACK_SIZE #define TF_STACK_SIZE 4096 #endif struct tf_fiber { unsigned int ref_count; struct tf_list_node queue_node; char data[TF_EMPTY_ARRAY]; }; typedef void (*tf_fiber_proc)(void *fiber); int tf_main(tf_fiber_proc fiber_main); void *tf_fiber_create(tf_fiber_proc fiber_main, int private_size); void *tf_fiber_get(void *data); void tf_fiber_put(void *data); int tf_schedule(int err); void tf_kill(void *fiber); static inline int tf_yield(void) { return tf_schedule(EAGAIN); } static inline int tf_exit(void) { return tf_schedule(EFAULT); } #endif