From 24b3f2a8c8cbfe128d6057006e044177740ca677 Mon Sep 17 00:00:00 2001 From: arighi Date: Tue, 8 Mar 2011 09:48:03 +0000 Subject: [PATCH] events: do not inline event_select() The body of the function is too large to be inlined by the compiler, so just move the implementaiton of the function in a events.c. This also fixes the following nightly build errors: FAILED [BUILD]: timer_test In file included from bertos/algo/ramp.h:52, from bertos/algo/ramp.c:104: bertos/hw/hw_stepper.h:49:2: warning: #warning TODO:This is an example implentation, you must implement it! bertos/hw/hw_stepper.h:144:2: warning: #warning TODO: This macro is not implemented (see below) bertos/hw/hw_stepper.h:156:2: warning: #warning TODO: This macro is not implemented (see below) In file included from bertos/mware/event.c:40: bertos/mware/event.h: In function 'event_select': bertos/mware/event.h:318: warning: implicit declaration of function 'timer_clock' bertos/mware/event.h:333: warning: implicit declaration of function 'TIMER_AFTER' In file included from bertos/mware/event.h:343, from bertos/mware/event.c:40: bertos/drv/timer.h: At top level: bertos/drv/timer.h:134: error: static declaration of 'timer_clock' follows non-static declaration git-svn-id: https://src.develer.com/svnoss/bertos/trunk@4758 38d2e660-2303-0410-9eaa-f027e97ec537 --- bertos/mware/event.c | 54 ++++++++++++++++++++++++++++++++++++++++++++ bertos/mware/event.h | 53 +------------------------------------------ 2 files changed, 55 insertions(+), 52 deletions(-) diff --git a/bertos/mware/event.c b/bertos/mware/event.c index 18631508..72663037 100644 --- a/bertos/mware/event.c +++ b/bertos/mware/event.c @@ -41,6 +41,8 @@ #include "cfg/cfg_signal.h" #include "cfg/cfg_timer.h" +#include /* timer_clock() */ + void event_hook_ignore(UNUSED_ARG(Event *, e)) { } @@ -69,3 +71,55 @@ void event_hook_generic(Event *e) e->Ev.Gen.completed = true; MEMORY_BARRIER; } + +/** + * Wait for multiple events + * + * On success return the offset in the \a evs vector of the Event that + * happened, -1 if the timeout expires. + * + * NOTE: timeout == 0 means no timeout. + */ +#if defined(CONFIG_KERN_SIGNALS) && CONFIG_KERN_SIGNALS +int event_select(Event **evs, int n, ticks_t timeout) +{ + sigmask_t mask = (1 << n) - 1; + int i; + + ASSERT(n <= SIG_USER_MAX); + for (i = 0; i < n; i++) + { + Event *e = evs[i]; + /* Map each event to a distinct signal bit */ + event_initSignal(e, proc_current(), 1 << i); + } + mask = timeout ? sig_waitTimeout(mask, timeout) : sig_wait(mask); + i = UINT8_LOG2(mask); + + return i < n ? i : -1; +} +#else +int event_select(Event **evs, int n, ticks_t timeout) +{ + ticks_t end = timer_clock() + timeout; + int i; + + while (1) + { + for (i = 0; i < n; i++) + { + Event *e = evs[i]; + if (ACCESS_SAFE(e->Ev.Gen.completed) == true) + { + e->Ev.Gen.completed = false; + MEMORY_BARRIER; + return i; + } + } + if (timeout && TIMER_AFTER(timer_clock(), end)) + break; + cpu_relax(); + } + return -1; +} +#endif diff --git a/bertos/mware/event.h b/bertos/mware/event.h index 94121413..941a332f 100644 --- a/bertos/mware/event.h +++ b/bertos/mware/event.h @@ -286,58 +286,7 @@ INLINE void event_wait(Event *e) #endif } -/** - * Wait for multiple events - * - * On success return the offset in the \a evs vector of the Event that - * happened, -1 if the timeout expires. - * - * NOTE: timeout == 0 means no timeout. - */ -#if defined(CONFIG_KERN_SIGNALS) && CONFIG_KERN_SIGNALS -INLINE int event_select(Event **evs, int n, ticks_t timeout) -{ - sigmask_t mask = (1 << n) - 1; - int i; - - ASSERT(n <= SIG_USER_MAX); - for (i = 0; i < n; i++) - { - Event *e = evs[i]; - /* Map each event to a distinct signal bit */ - event_initSignal(e, proc_current(), 1 << i); - } - mask = timeout ? sig_waitTimeout(mask, timeout) : sig_wait(mask); - i = UINT8_LOG2(mask); - - return i < n ? i : -1; -} -#else -INLINE int event_select(Event **evs, int n, ticks_t timeout) -{ - ticks_t end = timer_clock() + timeout; - int i; - - while (1) - { - for (i = 0; i < n; i++) - { - Event *e = evs[i]; - if (ACCESS_SAFE(e->Ev.Gen.completed) == true) - { - e->Ev.Gen.completed = false; - MEMORY_BARRIER; - return i; - } - } - if (timeout && TIMER_AFTER(timer_clock(), end)) - break; - cpu_relax(); - } - return -1; -} -#endif - +int event_select(Event **evs, int n, ticks_t timeout); #if CONFIG_TIMER_EVENTS #include /* timer_clock() */ -- 2.25.1