fibril.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2006 Ondrej Palkovsky
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  *
00009  * - Redistributions of source code must retain the above copyright
00010  *   notice, this list of conditions and the following disclaimer.
00011  * - Redistributions in binary form must reproduce the above copyright
00012  *   notice, this list of conditions and the following disclaimer in the
00013  *   documentation and/or other materials provided with the distribution.
00014  * - The name of the author may not be used to endorse or promote products
00015  *   derived from this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
00018  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00019  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
00020  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
00021  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
00022  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00023  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00024  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00025  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00026  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00027  */
00028 
00035 #ifndef LIBC_FIBRIL_H_
00036 #define LIBC_FIBRIL_H_
00037 
00038 #include <libarch/fibril.h>
00039 #include <adt/list.h>
00040 #include <libarch/tls.h>
00041 
00042 #define context_set_generic(c, _pc, stack, size, ptls) \
00043         (c)->pc = (sysarg_t) (_pc); \
00044         (c)->sp = ((sysarg_t) (stack)) + (size) - SP_DELTA; \
00045         (c)->tls = (sysarg_t) (ptls);
00046 
00047 #define FIBRIL_SERIALIZED  1
00048 #define FIBRIL_WRITER      2
00049 
00050 struct fibril;
00051 
00052 typedef struct {
00053         struct fibril *owned_by;
00054 } fibril_owner_info_t;
00055 
00056 typedef enum {
00057         FIBRIL_PREEMPT,
00058         FIBRIL_TO_MANAGER,
00059         FIBRIL_FROM_MANAGER,
00060         FIBRIL_FROM_DEAD
00061 } fibril_switch_type_t;
00062 
00063 typedef sysarg_t fid_t;
00064 
00065 typedef struct fibril {
00066         link_t link;
00067         context_t ctx;
00068         void *stack;
00069         void *arg;
00070         int (*func)(void *);
00071         tcb_t *tcb;
00072         
00073         struct fibril *clean_after_me;
00074         int retval;
00075         int flags;
00076         
00077         fibril_owner_info_t *waits_for;
00078 } fibril_t;
00079 
00081 #define fibril_local __thread
00082 
00083 extern int context_save(context_t *ctx) __attribute__((returns_twice));
00084 extern void context_restore(context_t *ctx) __attribute__((noreturn));
00085 
00086 extern fid_t fibril_create(int (*func)(void *), void *arg);
00087 extern fibril_t *fibril_setup(void);
00088 extern void fibril_teardown(fibril_t *f);
00089 extern int fibril_switch(fibril_switch_type_t stype);
00090 extern void fibril_add_ready(fid_t fid);
00091 extern void fibril_add_manager(fid_t fid);
00092 extern void fibril_remove_manager(void);
00093 extern fid_t fibril_get_id(void);
00094 extern void fibril_inc_sercount(void);
00095 extern void fibril_dec_sercount(void);
00096 extern int fibril_get_sercount(void);
00097 
00098 static inline int fibril_yield(void)
00099 {
00100         return fibril_switch(FIBRIL_PREEMPT);
00101 }
00102 
00103 #endif
00104 

Generated on Thu Jun 2 07:45:45 2011 for HelenOS/USB by  doxygen 1.4.7