event.h
Go to the documentation of this file.00001
00139 #ifndef KERN_EVENT_H
00140 #define KERN_EVENT_H
00141
00142 #include "cfg/cfg_proc.h"
00143 #include "cfg/cfg_signal.h"
00144 #include "cfg/cfg_timer.h"
00145 #include <cfg/compiler.h>
00146
00147 #include <cpu/power.h>
00148
00149 #if CONFIG_KERN && CONFIG_KERN_SIGNALS
00150 #include <kern/signal.h>
00151
00152 struct Process;
00153 #endif
00154
00155 typedef struct Event
00156 {
00157 void (*action)(struct Event *);
00158 union
00159 {
00160 #if CONFIG_KERN && CONFIG_KERN_SIGNALS
00161 struct
00162 {
00163 struct Process *sig_proc;
00164 sigbit_t sig_bit;
00165 Signal sig;
00166 } Sig;
00167 #endif
00168 struct
00169 {
00170 Hook func;
00171 void *user_data;
00172 } Int;
00173
00174 struct
00175 {
00176 bool completed;
00177 } Gen;
00178 } Ev;
00179 } Event;
00180
00181 void event_hook_ignore(Event *event);
00182 void event_hook_signal(Event *event);
00183 void event_hook_softint(Event *event);
00184 void event_hook_generic(Event *event);
00185 void event_hook_generic_signal(Event *event);
00186
00188 #define event_initNone(e) \
00189 ((e)->action = event_hook_ignore)
00190
00192 INLINE Event event_createNone(void)
00193 {
00194 Event e;
00195 e.action = event_hook_ignore;
00196 return e;
00197 }
00198
00200 #define event_initSoftint(e,f,u) \
00201 ((e)->action = event_hook_softint,(e)->Ev.Int.func = (f), (e)->Ev.Int.user_data = (u))
00202
00204 INLINE Event event_createSoftint(Hook func, void *user_data)
00205 {
00206 Event e;
00207 e.action = event_hook_softint;
00208 e.Ev.Int.func = func;
00209 e.Ev.Int.user_data = user_data;
00210 return e;
00211 }
00212
00213 #if CONFIG_KERN && CONFIG_KERN_SIGNALS
00214
00215 #define event_initSignal(e,p,s) \
00216 ((e)->action = event_hook_signal,(e)->Ev.Sig.sig_proc = (p), (e)->Ev.Sig.sig_bit = (s))
00217
00219 INLINE Event event_createSignal(struct Process *proc, sigbit_t bit)
00220 {
00221 Event e;
00222 e.action = event_hook_signal;
00223 e.Ev.Sig.sig_proc = proc;
00224 e.Ev.Sig.sig_bit = bit;
00225 return e;
00226 }
00227
00231 #define EVENT_GENERIC_SIGNAL SIG_SYSTEM6
00232
00234 #define event_initGeneric(e) \
00235 ((e)->action = event_hook_generic_signal, \
00236 (e)->Ev.Sig.sig_proc = proc_current(), \
00237 (e)->Ev.Sig.sig_bit = EVENT_GENERIC_SIGNAL, \
00238 (e)->Ev.Sig.sig.wait = 0, (e)->Ev.Sig.sig.recv = 0)
00239 #else
00240 #define event_initGeneric(e) \
00241 ((e)->action = event_hook_generic, (e)->Ev.Gen.completed = false)
00242 #endif
00243
00249 INLINE Event event_createGeneric(void)
00250 {
00251 Event e;
00252 event_initGeneric(&e);
00253 return e;
00254 }
00255
00263 INLINE void event_wait(Event *e)
00264 {
00265 #if CONFIG_KERN_SIGNALS
00266 e->Ev.Sig.sig_proc = proc_current();
00267 sig_waitSignal(&e->Ev.Sig.sig, EVENT_GENERIC_SIGNAL);
00268 #else
00269 while (ACCESS_SAFE(e->Ev.Gen.completed) == false)
00270 cpu_relax();
00271 e->Ev.Gen.completed = false;
00272 MEMORY_BARRIER;
00273 #endif
00274 }
00275
00286 int event_select(Event **evs, int n, ticks_t timeout);
00287
00293 bool event_waitTimeout(Event *e, ticks_t timeout);
00294
00303 INLINE void event_do(struct Event *e)
00304 {
00305 e->action(e);
00306 }
00307
00310 #endif