event: always add a memory barrier before returning from event_waitTimeout()
authorarighi <arighi@38d2e660-2303-0410-9eaa-f027e97ec537>
Mon, 1 Nov 2010 16:23:32 +0000 (16:23 +0000)
committerarighi <arighi@38d2e660-2303-0410-9eaa-f027e97ec537>
Mon, 1 Nov 2010 16:23:32 +0000 (16:23 +0000)
In this way we are sure the compiler will not perform optimizations or
instruction reordering: so that the return from event is always done
after the execution of the corresponding event_do().

git-svn-id: https://src.develer.com/svnoss/bertos/trunk@4480 38d2e660-2303-0410-9eaa-f027e97ec537

bertos/mware/event.h

index 4e2aace1e3c8d8bc12bf79c1b5ff0c0ba3bca6c8..b797b7eb25a35add0bef5fa02b9509e9149d40e9 100644 (file)
@@ -256,23 +256,23 @@ INLINE void event_wait(Event *e)
  */
 INLINE bool event_waitTimeout(Event *e, ticks_t timeout)
 {
+       bool ret;
+
 #if defined(CONFIG_KERN_SIGNALS) && CONFIG_KERN_SIGNALS
        e->Ev.Sig.sig_proc = proc_current();
-       return (sig_waitTimeout(e->Ev.Sig.sig_bit, timeout) & SIG_TIMEOUT) ?
+       ret = (sig_waitTimeout(e->Ev.Sig.sig_bit, timeout) & SIG_TIMEOUT) ?
                                false : true;
 #else
        ticks_t end = timer_clock() + timeout;
-       bool ret;
 
        while ((ACCESS_SAFE(e->Ev.Gen.completed) == false) ||
                        TIMER_AFTER(timer_clock(), end))
                cpu_relax();
        ret = e->Ev.Gen.completed;
        e->Ev.Gen.completed = false;
+#endif
        MEMORY_BARRIER;
-
        return ret;
-#endif
 }
 #endif /* CONFIG_TIMER_EVENTS */