BeRTOS
|
00001 00137 #ifndef KERN_EVENT_H 00138 #define KERN_EVENT_H 00139 00140 #include <cfg/compiler.h> 00141 #include "cfg/cfg_proc.h" 00142 #include "cfg/cfg_signal.h" 00143 #include "cfg/cfg_timer.h" 00144 00145 #include <cpu/power.h> /* cpu_relax() */ 00146 00147 #if CONFIG_KERN && CONFIG_KERN_SIGNALS 00148 #include <kern/signal.h> 00149 /* Forward decl */ 00150 struct Process; 00151 #endif 00152 00153 typedef struct Event 00154 { 00155 void (*action)(struct Event *); 00156 union 00157 { 00158 #if CONFIG_KERN && CONFIG_KERN_SIGNALS 00159 struct 00160 { 00161 struct Process *sig_proc; /* Process to be signalled */ 00162 sigbit_t sig_bit; /* Signal to send */ 00163 Signal sig; /* Local signal structure (used by generic event) */ 00164 } Sig; 00165 #endif 00166 struct 00167 { 00168 Hook func; /* Pointer to softint hook */ 00169 void *user_data; /* Data to be passed back to user hook */ 00170 } Int; 00171 00172 struct 00173 { 00174 bool completed; /* Generic event completion */ 00175 } Gen; 00176 } Ev; 00177 } Event; 00178 00179 void event_hook_ignore(Event *event); 00180 void event_hook_signal(Event *event); 00181 void event_hook_softint(Event *event); 00182 void event_hook_generic(Event *event); 00183 void event_hook_generic_signal(Event *event); 00184 00186 #define event_initNone(e) \ 00187 ((e)->action = event_hook_ignore) 00188 00190 INLINE Event event_createNone(void) 00191 { 00192 Event e; 00193 e.action = event_hook_ignore; 00194 return e; 00195 } 00196 00198 #define event_initSoftint(e,f,u) \ 00199 ((e)->action = event_hook_softint,(e)->Ev.Int.func = (f), (e)->Ev.Int.user_data = (u)) 00200 00202 INLINE Event event_createSoftint(Hook func, void *user_data) 00203 { 00204 Event e; 00205 e.action = event_hook_softint; 00206 e.Ev.Int.func = func; 00207 e.Ev.Int.user_data = user_data; 00208 return e; 00209 } 00210 00211 #if CONFIG_KERN && CONFIG_KERN_SIGNALS 00212 00213 #define event_initSignal(e,p,s) \ 00214 ((e)->action = event_hook_signal,(e)->Ev.Sig.sig_proc = (p), (e)->Ev.Sig.sig_bit = (s)) 00215 00217 INLINE Event event_createSignal(struct Process *proc, sigbit_t bit) 00218 { 00219 Event e; 00220 e.action = event_hook_signal; 00221 e.Ev.Sig.sig_proc = proc; 00222 e.Ev.Sig.sig_bit = bit; 00223 return e; 00224 } 00225 00229 #define EVENT_GENERIC_SIGNAL SIG_SYSTEM6 00230 00232 #define event_initGeneric(e) \ 00233 ((e)->action = event_hook_generic_signal, \ 00234 (e)->Ev.Sig.sig_proc = proc_current(), \ 00235 (e)->Ev.Sig.sig_bit = EVENT_GENERIC_SIGNAL, \ 00236 (e)->Ev.Sig.sig.wait = 0, (e)->Ev.Sig.sig.recv = 0) 00237 #else 00238 #define event_initGeneric(e) \ 00239 ((e)->action = event_hook_generic, (e)->Ev.Gen.completed = false) 00240 #endif 00241 00247 INLINE Event event_createGeneric(void) 00248 { 00249 Event e; 00250 event_initGeneric(&e); 00251 return e; 00252 } 00253 00261 INLINE void event_wait(Event *e) 00262 { 00263 #if CONFIG_KERN_SIGNALS 00264 e->Ev.Sig.sig_proc = proc_current(); 00265 sig_waitSignal(&e->Ev.Sig.sig, EVENT_GENERIC_SIGNAL); 00266 #else 00267 while (ACCESS_SAFE(e->Ev.Gen.completed) == false) 00268 cpu_relax(); 00269 e->Ev.Gen.completed = false; 00270 MEMORY_BARRIER; 00271 #endif 00272 } 00273 00284 int event_select(Event **evs, int n, ticks_t timeout); 00285 00291 bool event_waitTimeout(Event *e, ticks_t timeout); 00292 00301 INLINE void event_do(struct Event *e) 00302 { 00303 e->action(e); 00304 } 00305 00308 #endif /* KERN_EVENT_H */