aboutsummaryrefslogtreecommitdiffstats
path: root/src/chevents.c
diff options
context:
space:
mode:
authorgdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2009-03-07 15:32:40 +0000
committergdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2009-03-07 15:32:40 +0000
commitd9ff829a71d7b5723206e4923bcab6cbe3f5b715 (patch)
tree5911229eb2c3234ecafc48eefda439814c986f5a /src/chevents.c
parentd785c8a7e5e58dc2ef41afdfee47e605ef1216f5 (diff)
downloadChibiOS-d9ff829a71d7b5723206e4923bcab6cbe3f5b715.tar.gz
ChibiOS-d9ff829a71d7b5723206e4923bcab6cbe3f5b715.tar.bz2
ChibiOS-d9ff829a71d7b5723206e4923bcab6cbe3f5b715.zip
Fixes to the zero timeout. Added a test case.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@813 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'src/chevents.c')
-rw-r--r--src/chevents.c110
1 files changed, 60 insertions, 50 deletions
diff --git a/src/chevents.c b/src/chevents.c
index 83c487dcd..5633b7de3 100644
--- a/src/chevents.c
+++ b/src/chevents.c
@@ -29,10 +29,10 @@
/**
* @brief Registers an Event Listener on an Event Source.
*
- * @param esp pointer to the @p EventSource structure
- * @param elp pointer to the @p EventListener structure
- * @param emask the mask of event flags to be pended to the thread when the
- * event source is broadcasted
+ * @param[in] esp pointer to the @p EventSource structure
+ * @param[in] elp pointer to the @p EventListener structure
+ * @param[in] emask the mask of event flags to be pended to the thread when the
+ * event source is broadcasted
* @note Multiple Event Listeners can specify the same bits to be pended.
*/
void chEvtRegisterMask(EventSource *esp, EventListener *elp, eventmask_t emask) {
@@ -50,8 +50,8 @@ void chEvtRegisterMask(EventSource *esp, EventListener *elp, eventmask_t emask)
/**
* @brief Unregisters an Event Listener from its Event Source.
*
- * @param esp pointer to the @p EventSource structure
- * @param elp pointer to the @p EventListener structure
+ * @param[in] esp pointer to the @p EventSource structure
+ * @param[in] elp pointer to the @p EventListener structure
* @note If the event listener is not registered on the specified event source
* then the function does nothing.
* @note For optimal performance it is better to perform the unregister
@@ -78,7 +78,7 @@ void chEvtUnregister(EventSource *esp, EventListener *elp) {
/**
* @brief Clears the pending events specified in the mask.
*
- * @param mask the events to be cleared
+ * @param[in] mask the events to be cleared
* @return The pending events that were cleared.
*/
eventmask_t chEvtClear(eventmask_t mask) {
@@ -94,10 +94,10 @@ eventmask_t chEvtClear(eventmask_t mask) {
}
/**
- * @brief Pends a set of event flags on the current thread, this is \b much
- * faster than using @p chEvtBroadcast() or @p chEvtSignal().
+ * @brief Pends a set of event flags on the current thread, this is @b much
+ * faster than using @p chEvtBroadcast() or @p chEvtSignal().
*
- * @param mask the events to be pended
+ * @param[in] mask the events to be pended
* @return The current pending events mask.
*/
eventmask_t chEvtPend(eventmask_t mask) {
@@ -113,8 +113,8 @@ eventmask_t chEvtPend(eventmask_t mask) {
/**
* @brief Pends a set of event flags on the specified @p Thread.
*
- * @param tp the thread to be signaled
- * @param mask the event flags set to be pended
+ * @param[in] tp the thread to be signaled
+ * @param[in] mask the event flags set to be pended
*/
void chEvtSignal(Thread *tp, eventmask_t mask) {
@@ -128,8 +128,8 @@ void chEvtSignal(Thread *tp, eventmask_t mask) {
/**
* @brief Pends a set of event flags on the specified @p Thread.
*
- * @param tp the thread to be signaled
- * @param mask the event flags set to be pended
+ * @param[in] tp the thread to be signaled
+ * @param[in] mask the event flags set to be pended
*/
void chEvtSignalI(Thread *tp, eventmask_t mask) {
@@ -144,9 +144,9 @@ void chEvtSignalI(Thread *tp, eventmask_t mask) {
/**
* @brief Signals all the Event Listeners registered on the specified Event
- * Source.
+ * Source.
*
- * @param esp pointer to the @p EventSource structure
+ * @param[in] esp pointer to the @p EventSource structure
*/
void chEvtBroadcast(EventSource *esp) {
@@ -158,9 +158,9 @@ void chEvtBroadcast(EventSource *esp) {
/**
* @brief Signals all the Event Listeners registered on the specified Event
- * Source.
+ * Source.
*
- * @param esp pointer to the @p EventSource structure
+ * @param[in] esp pointer to the @p EventSource structure
*/
void chEvtBroadcastI(EventSource *esp) {
EventListener *elp;
@@ -177,10 +177,10 @@ void chEvtBroadcastI(EventSource *esp) {
/**
* @brief Invokes the event handlers associated with a mask.
*
- * @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.
+ * @param[in] mask mask of the events to be dispatched
+ * @param[in] handlers an array of @p evhandler_t. The array must be
+ * have indexes from zero up the higher registered event
+ * identifier.
*/
void chEvtDispatch(const evhandler_t handlers[], eventmask_t mask) {
eventid_t eid;
@@ -204,10 +204,10 @@ void chEvtDispatch(const evhandler_t handlers[], eventmask_t mask) {
/**
* @brief Waits for exactly one of the specified events.
* @details The function waits for one event among those specified in
- * @p ewmask to become pending then the event is cleared and returned.
+ * @p ewmask to become pending then the event is cleared and returned.
*
- * @param ewmask mask of the events that the function should wait for,
- * @p ALL_EVENTS enables all the events
+ * @param[in] ewmask mask of the events that the function should wait for,
+ * @p ALL_EVENTS enables all the events
* @return The mask of the lowest id served and cleared event.
* @note One and only one event is served in the function, the one with the
* lowest event id. The function is meant to be invoked into a loop in
@@ -235,10 +235,10 @@ eventmask_t chEvtWaitOne(eventmask_t ewmask) {
/**
* @brief Waits for any of the specified events.
* @details The function waits for any event among those specified in
- * @p ewmask to become pending then the events are cleared and returned.
+ * @p ewmask to become pending then the events are cleared and returned.
*
- * @param ewmask mask of the events that the function should wait for,
- * @p ALL_EVENTS enables all the events
+ * @param[in] ewmask mask of the events that the function should wait for,
+ * @p ALL_EVENTS enables all the events
* @return The mask of the served and cleared events.
*/
eventmask_t chEvtWaitAny(eventmask_t ewmask) {
@@ -260,9 +260,9 @@ eventmask_t chEvtWaitAny(eventmask_t ewmask) {
/**
* @brief Waits for all the specified events.
* @details The function waits for all the events specified in @p ewmask to
- * become pending then the events are cleared and returned.
+ * become pending then the events are cleared and returned.
*
- * @param ewmask mask of the event ids that the function should wait for
+ * @param[in] ewmask mask of the event ids that the function should wait for
* @return The mask of the served and cleared events.
*/
eventmask_t chEvtWaitAll(eventmask_t ewmask) {
@@ -284,14 +284,15 @@ eventmask_t chEvtWaitAll(eventmask_t ewmask) {
/**
* @brief Waits for exactly one of the specified events.
* @details The function waits for one event among those specified in
- * @p ewmask to become pending then the event is cleared and returned.
+ * @p ewmask to become pending then the event is cleared and returned.
*
- * @param ewmask mask of the events that the function should wait for,
- * @p ALL_EVENTS enables all the events
- * @param time the number of ticks before the operation timeouts,
- * the following special values are allowed:
- * - @a TIME_ZERO immediate timeout.
- * - @a TIME_INFINITE no timeout.
+ * @param[in] ewmask mask of the events that the function should wait for,
+ * @p ALL_EVENTS enables all the events
+ * @param[in] time the number of ticks before the operation timeouts,
+ * the following special values are allowed:
+ * - @a TIME_ZERO immediate timeout.
+ * - @a TIME_INFINITE no timeout.
+ * .
* @return The mask of the lowest id served and cleared event.
* @retval 0 if the specified timeout expired.
* @note One and only one event is served in the function, the one with the
@@ -306,6 +307,8 @@ eventmask_t chEvtWaitOneTimeout(eventmask_t ewmask, systime_t time) {
chSysLock();
if ((m = (currp->p_epending & ewmask)) == 0) {
+ if (TIME_ZERO == time)
+ return (eventmask_t)0;
currp->p_ewmask = ewmask;
if (chSchGoSleepTimeoutS(PRWTOREVT, time) < RDY_OK)
return (eventmask_t)0;
@@ -321,14 +324,16 @@ eventmask_t chEvtWaitOneTimeout(eventmask_t ewmask, systime_t time) {
/**
* @brief Waits for any of the specified events.
* @details The function waits for any event among those specified in
- * @p ewmask to become pending then the events are cleared and returned.
+ * @p ewmask to become pending then the events are cleared and
+ * returned.
*
- * @param ewmask mask of the events that the function should wait for,
- * @p ALL_EVENTS enables all the events
- * @param time the number of ticks before the operation timeouts,
- * the following special values are allowed:
- * - @a TIME_ZERO immediate timeout.
- * - @a TIME_INFINITE no timeout.
+ * @param[in] ewmask mask of the events that the function should wait for,
+ * @p ALL_EVENTS enables all the events
+ * @param[in] time the number of ticks before the operation timeouts,
+ * the following special values are allowed:
+ * - @a TIME_ZERO immediate timeout.
+ * - @a TIME_INFINITE no timeout.
+ * .
* @return The mask of the served and cleared events.
* @retval 0 if the specified timeout expired.
*/
@@ -338,6 +343,8 @@ eventmask_t chEvtWaitAnyTimeout(eventmask_t ewmask, systime_t time) {
chSysLock();
if ((m = (currp->p_epending & ewmask)) == 0) {
+ if (TIME_ZERO == time)
+ return (eventmask_t)0;
currp->p_ewmask = ewmask;
if (chSchGoSleepTimeoutS(PRWTOREVT, time) < RDY_OK)
return (eventmask_t)0;
@@ -352,13 +359,14 @@ eventmask_t chEvtWaitAnyTimeout(eventmask_t ewmask, systime_t time) {
/**
* @brief Waits for all the specified events.
* @details The function waits for all the events specified in @p ewmask to
- * become pending then the events are cleared and returned.
+ * become pending then the events are cleared and returned.
*
- * @param ewmask mask of the event ids that the function should wait for
- * @param time the number of ticks before the operation timeouts
- * the following special values are allowed:
- * - @a TIME_ZERO immediate timeout.
- * - @a TIME_INFINITE no timeout.
+ * @param[in] ewmask mask of the event ids that the function should wait for
+ * @param[in] time the number of ticks before the operation timeouts,
+ * the following special values are allowed:
+ * - @a TIME_ZERO immediate timeout.
+ * - @a TIME_INFINITE no timeout.
+ * .
* @return The mask of the served and cleared events.
* @retval 0 if the specified timeout expired.
*/
@@ -367,6 +375,8 @@ eventmask_t chEvtWaitAllTimeout(eventmask_t ewmask, systime_t time) {
chSysLock();
if ((currp->p_epending & ewmask) != ewmask) {
+ if (TIME_ZERO == time)
+ return (eventmask_t)0;
currp->p_ewmask = ewmask;
if (chSchGoSleepTimeoutS(PRWTANDEVT, time) < RDY_OK)
return (eventmask_t)0;