X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=bertos%2Fmware%2Fevent.h;h=0111ef8cbfa37fbf866f11c0976fa7f3ecbc14f6;hb=446aae6172b8e362264b6a3d08f7b61fb23898a9;hp=e9f9e4a2269d01b36ec665ec85e21cc8589ff99f;hpb=1c11ac0ab0636d07db3899b02c5d89e2d0b020bc;p=bertos.git diff --git a/bertos/mware/event.h b/bertos/mware/event.h index e9f9e4a2..0111ef8c 100644 --- a/bertos/mware/event.h +++ b/bertos/mware/event.h @@ -123,6 +123,12 @@ typedef struct Event struct Process *sig_proc; /* Process to be signalled */ sigbit_t sig_bit; /* Signal to send */ } Sig; + + struct + { + struct Process *sig_proc; /* Process to be signalled */ + Signal sig; /* Signal structure */ + } SigGen; #endif struct { @@ -141,7 +147,7 @@ void event_hook_ignore(Event *event); void event_hook_signal(Event *event); void event_hook_softint(Event *event); void event_hook_generic(Event *event); -void event_hook_generic_timeout(Event *event); +void event_hook_generic_signal(Event *event); /** Initialize the event \a e as a no-op */ #define event_initNone(e) \ @@ -188,24 +194,22 @@ INLINE Event event_createSignal(struct Process *proc, sigbit_t bit) #endif -/** - * Prevent the compiler from optimizing access to the variable \a x, enforcing - * a refetch from memory. This also forbid from reordering successing instances - * of ACCESS_SAFE(). - * - * TODO: move this to cfg/compiler.h - */ -#define ACCESS_SAFE(x) (*(volatile typeof(x) *)&(x)) - #if defined(CONFIG_KERN_SIGNALS) && CONFIG_KERN_SIGNALS /** Initialize the generic sleepable event \a e */ -#define event_initGeneric(e) \ - event_initSignal(e, proc_current(), SIG_SYSTEM5) +#define event_initGeneric(e) \ + ((e)->action = event_hook_generic_signal, \ + (e)->Ev.SigGen.sig_proc = proc_current(), \ + (e)->Ev.SigGen.sig.wait = 0, (e)->Ev.SigGen.sig.recv = 0) #else #define event_initGeneric(e) \ ((e)->action = event_hook_generic, (e)->Ev.Gen.completed = false) #endif +/** + * Signal used to implement generic events. + */ +#define EVENT_GENERIC_SIGNAL SIG_SYSTEM5 + /** * Create a generic sleepable event. * @@ -229,7 +233,7 @@ INLINE void event_wait(Event *e) { #if defined(CONFIG_KERN_SIGNALS) && CONFIG_KERN_SIGNALS e->Ev.Sig.sig_proc = proc_current(); - sig_wait(e->Ev.Sig.sig_bit); + sig_waitSignal(&e->Ev.SigGen.sig, EVENT_GENERIC_SIGNAL); #else while (ACCESS_SAFE(e->Ev.Gen.completed) == false) cpu_relax(); @@ -241,10 +245,6 @@ INLINE void event_wait(Event *e) #if CONFIG_TIMER_EVENTS #include /* timer_clock() */ -/* TODO: move these macros to drv/timer.h */ -#define TIMER_AFTER(x, y) ((long)(y) - (long)(x) < 0) -#define TIMER_BEFORE(x, y) TIMER_AFTER(y, x) - /** * Wait the completion of event \a e or \a timeout elapses. * @@ -256,7 +256,8 @@ INLINE bool event_waitTimeout(Event *e, ticks_t timeout) #if defined(CONFIG_KERN_SIGNALS) && CONFIG_KERN_SIGNALS e->Ev.Sig.sig_proc = proc_current(); - ret = (sig_waitTimeout(e->Ev.Sig.sig_bit, timeout) & SIG_TIMEOUT) ? + ret = (sig_waitTimeoutSignal(&e->Ev.SigGen.sig, + EVENT_GENERIC_SIGNAL, timeout) & SIG_TIMEOUT) ? false : true; #else ticks_t end = timer_clock() + timeout;