From 7f3e0e57b2a13aa4797a8409e6e63671cb6d6993 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Tue, 11 Feb 2014 13:00:24 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/kernel_3_dev@6701 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/nil/include/nil.h | 8 ++++++++ os/nil/src/nil.c | 37 ++++++++++++++++++++++++++++++++++--- 2 files changed, 42 insertions(+), 3 deletions(-) (limited to 'os') diff --git a/os/nil/include/nil.h b/os/nil/include/nil.h index 7ba088dac..161c79a6d 100644 --- a/os/nil/include/nil.h +++ b/os/nil/include/nil.h @@ -596,6 +596,13 @@ typedef struct { */ #define chSchIsRescRequiredI() ((bool)(nil.current != nil.next)) +/** + * @brief Returns a pointer to the current @p thread_t. + * + * @xclass + */ +#define chThdGetSelfX() nil.current + /** * @brief Delays the invoking thread for the specified number of seconds. * @note The specified time is rounded up to a value allowed by the real @@ -802,6 +809,7 @@ extern "C" { void chEvtSignal(thread_t *tp, eventmask_t mask); void chEvtSignalI(thread_t *tp, eventmask_t mask); eventmask_t chEvtWaitAnyTimeout(eventmask_t mask, systime_t timeout); + eventmask_t chEvtWaitAnyTimeoutS(eventmask_t mask, systime_t timeout); #ifdef __cplusplus } #endif diff --git a/os/nil/src/nil.c b/os/nil/src/nil.c index 9141129cb..edd717600 100644 --- a/os/nil/src/nil.c +++ b/os/nil/src/nil.c @@ -489,7 +489,9 @@ msg_t chSemWaitTimeout(semaphore_t *sp, systime_t timeout) { msg_t msg; chSysLock(); + msg = chSemWaitTimeoutS(sp, timeout); + chSysUnlock(); return msg; } @@ -599,8 +601,10 @@ void chSemSignalI(semaphore_t *sp) { void chSemReset(semaphore_t *sp, cnt_t n) { chSysLock(); + chSemResetI(sp, n); chSchRescheduleS(); + chSysUnlock(); } @@ -654,8 +658,10 @@ void chSemResetI(semaphore_t *sp, cnt_t n) { void chEvtSignal(thread_t *tp, eventmask_t mask) { chSysLock(); + chEvtSignalI(tp, mask); chSchRescheduleS(); + chSysUnlock(); } @@ -697,11 +703,38 @@ void chEvtSignalI(thread_t *tp, eventmask_t mask) { * @api */ eventmask_t chEvtWaitAnyTimeout(eventmask_t mask, systime_t timeout) { - thread_t *ctp = nil.current; eventmask_t m; chSysLock(); + m = chEvtWaitAnyTimeoutS(mask, timeout); + + chSysUnlock(); + return m; +} + +/** + * @brief Waits for any of the specified events. + * @details The function waits for any event among those specified in + * @p mask to become pending then the events are cleared and + * returned. + * + * @param[in] mask mask of the event flags that the function should wait + * for, @p ALL_EVENTS enables all the events + * @param[in] timeout the number of ticks before the operation timeouts, + * the following special values are allowed: + * - @a TIME_IMMEDIATE immediate timeout. + * - @a TIME_INFINITE no timeout. + * . + * @return The mask of the served and cleared events. + * @retval 0 if the operation has timed out. + * + * @sclass + */ +eventmask_t chEvtWaitAnyTimeoutS(eventmask_t mask, systime_t timeout) { + thread_t *ctp = nil.current; + eventmask_t m; + if ((m = (ctp->epmask & mask)) == 0) { if (TIME_IMMEDIATE == timeout) { chSysUnlock(); @@ -715,8 +748,6 @@ eventmask_t chEvtWaitAnyTimeout(eventmask_t mask, systime_t timeout) { m = ctp->epmask & mask; } ctp->epmask &= ~m; - - chSysUnlock(); return m; } -- cgit v1.2.3