diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/chevents.c | 21 | ||||
-rw-r--r-- | src/include/events.h | 9 |
2 files changed, 17 insertions, 13 deletions
diff --git a/src/chevents.c b/src/chevents.c index ce2254ab4..f67bea11a 100644 --- a/src/chevents.c +++ b/src/chevents.c @@ -142,22 +142,21 @@ void chEvtBroadcastI(EventSource *esp) { /**
* Invokes the event handlers associated with a mask.
- * @param mask mask of the events that should be invoked by the function,
- * \p ALL_EVENTS enables all the sources
+ * @param mask mask of the events to be dispatched
* @param handlers an array of \p evhandler_t. The array must be
* have indexes from zero up the higher registered event
- * identifier. The array can be \p NULL or contain \p NULL
- * elements (no callbacks specified).
+ * identifier.
*/
void chEvtDispatch(const evhandler_t handlers[], eventmask_t mask) {
- eventid_t i;
- eventmask_t m;
+ eventid_t eid;
- i = 0, m = 1;
- while ((mask & m) == 0) {
- i += 1, m <<= 1;
- mask &= ~m;
- handlers[i](i);
+ eid = 0;
+ while (mask) {
+ if (mask & EVENT_MASK(eid)) {
+ mask &= ~EVENT_MASK(eid);
+ handlers[eid](eid);
+ }
+ eid++;
}
}
diff --git a/src/include/events.h b/src/include/events.h index ae5d8c740..2f3eda366 100644 --- a/src/include/events.h +++ b/src/include/events.h @@ -52,9 +52,13 @@ typedef struct EventSource { EventListener *es_next;
} EventSource;
-/** Returns the event mask from the event identifier.*/
+/** Returns the event mask from the event identifier.
+ * @deprecated use EVENT_MASK() instead.*/
#define EventMask(eid) (1 << (eid))
+/** Returns the event mask from the event identifier.*/
+#define EVENT_MASK(eid) (1 << (eid))
+
/**
* Initializes an Event Source.
* @param esp pointer to the \p EventSource structure
@@ -85,6 +89,7 @@ extern "C" { eventmask_t chEvtPend(eventmask_t mask);
void chEvtBroadcast(EventSource *esp);
void chEvtBroadcastI(EventSource *esp);
+ void chEvtDispatch(const evhandler_t handlers[], eventmask_t mask);
#if defined(CH_OPTIMIZE_SPEED) || !defined(CH_USE_EVENT_TIMEOUT)
eventmask_t chEvtWaitOne(eventmask_t ewmask);
eventmask_t chEvtWaitAny(eventmask_t ewmask);
@@ -115,7 +120,7 @@ extern "C" { * @note Multiple Event Listeners can use the same event identifier, the
* listener will share the callback function.
*/
-#define chEvtRegister(esp, elp, eid) chEvtRegisterMask(esp, elp, EventMask(eid))
+#define chEvtRegister(esp, elp, eid) chEvtRegisterMask(esp, elp, EVENT_MASK(eid))
#if !defined(CH_OPTIMIZE_SPEED) && defined(CH_USE_EVENT_TIMEOUT)
#define chEvtWaitOne(ewmask) chEvtWaitOneTimeout(ewmask, TIME_INFINITE)
|