diff options
Diffstat (limited to 'src/chevents.c')
-rw-r--r-- | src/chevents.c | 52 |
1 files changed, 30 insertions, 22 deletions
diff --git a/src/chevents.c b/src/chevents.c index 13f20310d..f8d7d971f 100644 --- a/src/chevents.c +++ b/src/chevents.c @@ -119,6 +119,7 @@ void chEvtSendI(EventSource *esp) { }
}
+#ifdef CH_USE_EVENTS_TIMEOUT
/**
* The function waits for an event and returns the event identifier, if an
* event handler is specified then the handler is executed before returning.
@@ -137,33 +138,14 @@ void chEvtSendI(EventSource *esp) { */
t_eventid chEvtWait(t_eventmask ewmask,
const t_evhandler handlers[]) {
- t_eventid i;
- t_eventmask m;
- chSysLock();
-
- if ((currp->p_epending & ewmask) == 0) {
- currp->p_ewmask = ewmask;
- chSchGoSleepS(PRWTEVENT);
- }
- i = 0, m = 1;
- while ((currp->p_epending & ewmask & m) == 0)
- i += 1, m <<= 1;
- currp->p_epending &= ~m;
-
- chSysUnlock();
-
- if (handlers && handlers[i])
- handlers[i](i);
-
- return i;
+ return chEvtWaitTimeout(ewmask, handlers, TIME_INFINITE);
}
-#ifdef CH_USE_EVENTS_TIMEOUT
static void wakeup(void *p) {
#ifdef CH_USE_DEBUG
if (((Thread *)p)->p_state != PRWTEVENT)
- chDbgPanic("chevents.c, wakeup()\r\n");
+ chDbgPanic("chevents.c, wakeup()");
#endif
chSchReadyI(p, RDY_TIMEOUT);
}
@@ -223,7 +205,33 @@ t_eventid chEvtWaitTimeout(t_eventmask ewmask, return i;
}
-#endif /*CH_USE_EVENTS_TIMEOUT */
+
+#else /* !CH_USE_EVENTS_TIMEOUT */
+t_eventid chEvtWait(t_eventmask ewmask,
+ const t_evhandler handlers[]) {
+ t_eventid i;
+ t_eventmask m;
+
+ chSysLock();
+
+ if ((currp->p_epending & ewmask) == 0) {
+ currp->p_ewmask = ewmask;
+ chSchGoSleepS(PRWTEVENT);
+ }
+ i = 0, m = 1;
+ while ((currp->p_epending & ewmask & m) == 0)
+ i += 1, m <<= 1;
+ currp->p_epending &= ~m;
+
+ chSysUnlock();
+
+ if (handlers && handlers[i])
+ handlers[i](i);
+
+ return i;
+}
+
+#endif /* CH_USE_EVENTS_TIMEOUT */
#endif /* CH_USE_EVENTS */
|