00001 /* $Id: semaphore.h 31603 2008-05-12 06:54:17Z adam $ */ 00002 /*****************************************************************************/ 00010 /*****************************************************************************/ 00011 00012 /* (c) 2003 Technische Universitaet Dresden 00013 * This file is part of DROPS, which is distributed under the terms of the 00014 * GNU General Public License 2. Please see the COPYING file for details. 00015 */ 00016 00017 #ifndef _L4_SEMAPHORE_SEMAPHORE_H 00018 #define _L4_SEMAPHORE_SEMAPHORE_H 00019 00020 /* L4 includes */ 00021 #include <l4/sys/types.h> 00022 #include <l4/env/cdefs.h> 00023 #include <l4/thread/thread.h> 00024 #include <l4/util/util.h> 00025 00026 /***************************************************************************** 00027 *** configuration 00028 *****************************************************************************/ 00029 00033 #define L4SEMAPHORE_SEND_ONLY_IPC 0 00034 00038 #ifdef ARCH_x86 00039 #define L4SEMAPHORE_ASM 1 00040 #else 00041 #define L4SEMAPHORE_ASM 0 00042 #endif 00043 00047 #define L4SEMAPHORE_RESTART_IPC 1 00048 00049 /***************************************************************************** 00050 *** types 00051 *****************************************************************************/ 00052 00056 typedef struct l4semaphore 00057 { 00058 volatile int counter; 00059 int pending; 00060 void * queue; 00061 } l4semaphore_t; 00062 00063 /***************************************************************************** 00064 *** defines 00065 *****************************************************************************/ 00066 00073 #define L4SEMAPHORE_INITIALIZER(x) {(x), 0, NULL} 00074 00080 #define L4SEMAPHORE_INIT(x) \ 00081 ((l4semaphore_t)L4SEMAPHORE_INITIALIZER(x)) 00082 00087 #define L4SEMAPHORE_LOCKED_INITIALIZER \ 00088 L4SEMAPHORE_INITIALIZER(0) 00089 00094 #define L4SEMAPHORE_LOCKED \ 00095 ((l4semaphore_t)L4SEMAPHORE_LOCKED_INITIALIZER) 00096 00101 #define L4SEMAPHORE_UNLOCKED_INITIALIZER \ 00102 L4SEMAPHORE_INITIALIZER(1) 00103 00108 #define L4SEMAPHORE_UNLOCKED \ 00109 ((l4semaphore_t)L4SEMAPHORE_UNLOCKED_INITIALIZER) 00110 00111 00112 /* Semaphore thread IPC commands (dw0), check assembler implementation 00113 * if changed! */ 00114 #define L4SEMAPHORE_BLOCK 0x00000001 00115 #define L4SEMAPHORE_RELEASE 0x00000002 00116 #define L4SEMAPHORE_BLOCKTIMED 0x00000003 00117 00118 #define L4SEMAPHORE_RELEASETIMED 0x00000004 00119 00120 __BEGIN_DECLS; 00121 00122 /***************************************************************************** 00123 *** global data 00124 *****************************************************************************/ 00125 00129 extern l4_threadid_t l4semaphore_thread_l4_id; 00130 00131 /***************************************************************************** 00132 *** prototypes 00133 *****************************************************************************/ 00134 00135 /*****************************************************************************/ 00146 /*****************************************************************************/ 00147 L4_CV int 00148 l4semaphore_init(void); 00149 00150 /*****************************************************************************/ 00159 /*****************************************************************************/ 00160 L4_CV int 00161 l4semaphore_set_thread_prio(l4_prio_t prio); 00162 00163 /*****************************************************************************/ 00173 /*****************************************************************************/ 00174 L4_INLINE void 00175 l4semaphore_down(l4semaphore_t * sem); 00176 00177 /*****************************************************************************/ 00196 /*****************************************************************************/ 00197 L4_INLINE int 00198 l4semaphore_down_timed(l4semaphore_t * sem, unsigned timeout); 00199 00200 /*****************************************************************************/ 00211 /*****************************************************************************/ 00212 L4_INLINE int 00213 l4semaphore_try_down(l4semaphore_t * sem); 00214 00215 /*****************************************************************************/ 00225 /*****************************************************************************/ 00226 L4_INLINE void 00227 l4semaphore_up(l4semaphore_t * sem); 00228 00229 __END_DECLS; 00230 00231 00232 #ifdef __GNUC__ 00233 /***************************************************************************** 00234 *** implementation 00235 *****************************************************************************/ 00236 00237 #include <l4/semaphore/archindep.h> 00238 00239 #if L4SEMAPHORE_ASM 00240 # include <l4/semaphore/asm.h> 00241 #else 00242 # include <l4/semaphore/generic.h> 00243 #endif 00244 00245 #endif //__GNUC__ 00246 00247 #endif /* !_L4_SEMAPHORE_SEMAPHORE_H */