From ec4178dd0ff7587b79a8c525aa88d467642ce629 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Mon, 2 Feb 2009 12:48:17 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@712 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- src/chevents.c | 45 ++++++++++++++++++++++++++++++++++----------- src/chmsg.c | 38 +++++++++++++++++++------------------- src/chsem.c | 13 ++++++++++--- src/include/events.h | 2 ++ src/include/messages.h | 4 ++-- src/templates/chconf.h | 29 +++++++++++++++++------------ 6 files changed, 84 insertions(+), 47 deletions(-) (limited to 'src') diff --git a/src/chevents.c b/src/chevents.c index dc096767e..8391f3a0c 100644 --- a/src/chevents.c +++ b/src/chevents.c @@ -91,8 +91,8 @@ eventmask_t chEvtClear(eventmask_t mask) { } /** - * @brief Makes an events mask pending in the current thread, this is \b much - * faster than using @p chEvtBroadcast(). + * @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 * @return The current pending events mask. @@ -107,6 +107,37 @@ eventmask_t chEvtPend(eventmask_t mask) { return 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 + */ +void chEvtSignal(Thread *tp, eventmask_t mask) { + + chSysLock(); + + chEvtSignalI(tp, mask); + + chSysUnlock(); +} + +/** + * @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 + */ +void chEvtSignalI(Thread *tp, eventmask_t mask) { + + tp->p_epending |= mask; + + /* Test on the AND/OR conditions wait states.*/ + if (((tp->p_state == PRWTOREVT) && ((tp->p_epending & tp->p_ewmask) != 0)) || + ((tp->p_state == PRWTANDEVT) && ((tp->p_epending & tp->p_ewmask) == tp->p_ewmask))) + chSchReadyI(tp)->p_rdymsg = RDY_OK; +} + /** * @brief Signals all the Event Listeners registered on the specified Event * Source. @@ -134,15 +165,7 @@ void chEvtBroadcastI(EventSource *esp) { elp = esp->es_next; while (elp != (EventListener *)esp) { - Thread *tp = elp->el_listener; - - tp->p_epending |= elp->el_mask; - - /* Test on the AND/OR conditions wait states.*/ - if (((tp->p_state == PRWTOREVT) && ((tp->p_epending & tp->p_ewmask) != 0)) || - ((tp->p_state == PRWTANDEVT) && ((tp->p_epending & tp->p_ewmask) == tp->p_ewmask))) - chSchReadyI(tp)->p_rdymsg = RDY_OK; - + chEvtSignalI(elp->el_listener, elp->el_mask); elp = elp->el_next; } } diff --git a/src/chmsg.c b/src/chmsg.c index 6f253067c..71eb431ef 100644 --- a/src/chmsg.c +++ b/src/chmsg.c @@ -24,24 +24,27 @@ #include #ifdef CH_USE_MESSAGES + +#ifdef CH_USE_MESSAGES_PRIORITY +#define msg_insert(tp, qp) prio_insert(tp, qp) +#else +#define msg_insert(tp, qp) queue_insert(tp, qp) +#endif + /** * @brief Sends a message to the specified thread. * @details The sender is stopped until the receiver executes a * @p chMsgRelease()after receiving the message. * * @param tp the pointer to the thread - * @param msg the message, it can be a pointer to a complex structure + * @param msg the message * @return The return message from @p chMsgRelease(). */ msg_t chMsgSend(Thread *tp, msg_t msg) { chSysLock(); -#ifdef CH_USE_MESSAGES_PRIORITY - prio_insert(currp, &tp->p_msgqueue); -#else - queue_insert(currp, &tp->p_msgqueue); -#endif + msg_insert(currp, &tp->p_msgqueue); currp->p_msg = msg; currp->p_wtthdp = tp; if (tp->p_state == PRWTMSG) @@ -53,32 +56,29 @@ msg_t chMsgSend(Thread *tp, msg_t msg) { return msg; } -#ifdef CH_USE_MESSAGES_EVENT +#if defined(CH_USE_EVENTS) && defined(CH_USE_MESSAGES_EVENT) /** - * @brief Sends a message to the specified thread and atomically triggers - * an event. + * @brief Sends a message to the specified thread and atomically pends an + * events set. * @details The sender is stopped until the receiver executes a * @p chMsgRelease() after receiving the message. * * @param tp the pointer to the thread - * @param msg the message, it can be a pointer to a complex structure - * @param esp the event source to pulse while sending the message + * @param msg the message + * @param mask the event flags set to be pended * @return The return message from @p chMsgRelease(). * @note This function assumes that the receiving thread is not sleeping into * a @p chMsgWait(). The use case is that the server thread is waiting * for both messages AND events while waiting into @p chEvtWaitXXX(). */ -msg_t chMsgSendWithEvent(Thread *tp, msg_t msg, EventSource *esp) { +msg_t chMsgSendWithEvent(Thread *tp, msg_t msg, eventmask_t mask) { chSysLock(); chDbgAssert(tp->p_state != PRWTMSG, "chmsg.c, chMsgSendWithEvent()"); -#ifdef CH_USE_MESSAGES_PRIORITY - prio_insert(currp, &tp->p_msgqueue); -#else - queue_insert(currp, &tp->p_msgqueue); -#endif - chEvtBroadcastI(esp); + + chEvtSignalI(tp, mask); + msg_insert(currp, &tp->p_msgqueue); currp->p_wtthdp = tp; currp->p_msg = msg; chSchGoSleepS(PRSNDMSG); @@ -87,7 +87,7 @@ msg_t chMsgSendWithEvent(Thread *tp, msg_t msg, EventSource *esp) { chSysUnlock(); return msg; } -#endif +#endif /* defined(CH_USE_EVENTS) && defined(CH_USE_MESSAGES_EVENT) */ /** * @brief Suspends the thread and waits for an incoming message. diff --git a/src/chsem.c b/src/chsem.c index 3af4854f5..bc7e8f1b7 100644 --- a/src/chsem.c +++ b/src/chsem.c @@ -25,6 +25,13 @@ #include #ifdef CH_USE_SEMAPHORES + +#ifdef CH_USE_SEMAPHORES_PRIORITY +#define sem_insert(tp, qp) prio_insert(tp, qp) +#else +#define sem_insert(tp, qp) queue_insert(tp, qp) +#endif + /** * @brief Initializes a semaphore with the specified counter value. * @@ -110,7 +117,7 @@ msg_t chSemWait(Semaphore *sp) { msg_t chSemWaitS(Semaphore *sp) { if (--sp->s_cnt < 0) { - queue_insert(currp, &sp->s_queue); + sem_insert(currp, &sp->s_queue); currp->p_wtsemp = sp; chSchGoSleepS(PRWTSEM); return currp->p_rdymsg; @@ -157,7 +164,7 @@ msg_t chSemWaitTimeout(Semaphore *sp, systime_t time) { msg_t chSemWaitTimeoutS(Semaphore *sp, systime_t time) { if (--sp->s_cnt < 0) { - queue_insert(currp, &sp->s_queue); + sem_insert(currp, &sp->s_queue); currp->p_wtsemp = sp; return chSchGoSleepTimeoutS(PRWTSEM, time); } @@ -221,7 +228,7 @@ msg_t chSemSignalWait(Semaphore *sps, Semaphore *spw) { chSchReadyI(fifo_remove(&sps->s_queue))->p_rdymsg = RDY_OK; if (--spw->s_cnt < 0) { - queue_insert(currp, &spw->s_queue); + sem_insert(currp, &spw->s_queue); currp->p_wtsemp = spw; chSchGoSleepS(PRWTSEM); msg = currp->p_rdymsg; diff --git a/src/include/events.h b/src/include/events.h index 34c35d487..53d7bd72e 100644 --- a/src/include/events.h +++ b/src/include/events.h @@ -82,6 +82,8 @@ extern "C" { void chEvtUnregister(EventSource *esp, EventListener *elp); eventmask_t chEvtClear(eventmask_t mask); eventmask_t chEvtPend(eventmask_t mask); + void chEvtSignal(Thread *tp, eventmask_t mask); + void chEvtSignalI(Thread *tp, eventmask_t mask); void chEvtBroadcast(EventSource *esp); void chEvtBroadcastI(EventSource *esp); void chEvtDispatch(const evhandler_t handlers[], eventmask_t mask); diff --git a/src/include/messages.h b/src/include/messages.h index c93d6a2d7..d4bbb9851 100644 --- a/src/include/messages.h +++ b/src/include/messages.h @@ -47,8 +47,8 @@ extern "C" { msg_t chMsgGet(void); void chMsgRelease(msg_t msg); -#ifdef CH_USE_MESSAGES_EVENT - msg_t chMsgSendWithEvent(Thread *tp, msg_t msg, EventSource *esp); +#if defined(CH_USE_EVENTS) && defined(CH_USE_MESSAGES_EVENT) + msg_t chMsgSendWithEvent(Thread *tp, msg_t msg, eventmask_t mask); #endif #ifdef __cplusplus } diff --git a/src/templates/chconf.h b/src/templates/chconf.h index f1b7f1b17..9f7a69135 100644 --- a/src/templates/chconf.h +++ b/src/templates/chconf.h @@ -56,13 +56,18 @@ * in the kernel.*/ #define CH_USE_SEMAPHORES +/** Configuration option: If enabled then the threads are enqueued on semaphores + * by priority rather than FIFO order. + * @note requires @p CH_USE_SEMAPHORES.*/ +#define CH_USE_SEMAPHORES_PRIORITY + /** Configuration option: if specified then the Semaphores atomic Signal+Wait * APIs are included in the kernel.*/ #define CH_USE_SEMSW /** Configuration option: if specified then the Semaphores with timeout APIs * are included in the kernel. - * @note requires @p CH_USE_SEMAPHORES.*/ + * @note requires @p CH_USE_SEMAPHORES.*/ #define CH_USE_SEMAPHORES_TIMEOUT /** Configuration option: if specified then the Mutexes APIs are included in @@ -71,12 +76,12 @@ /** Configuration option: if specified then the Conditional Variables APIs are * included in the kernel. - * @note requires @p CH_USE_MUTEXES.*/ + * @note requires @p CH_USE_MUTEXES.*/ #define CH_USE_CONDVARS /** Configuration option: if specified then the Conditional Variables APIs are * included in the kernel. - * @note requires @p CH_USE_CONDVARS and @p CH_USE_MUTEXES.*/ + * @note requires @p CH_USE_CONDVARS and @p CH_USE_MUTEXES.*/ #define CH_USE_CONDVARS_TIMEOUT /** Configuration option: if specified then the Events APIs are included in @@ -84,8 +89,8 @@ #define CH_USE_EVENTS /** Configuration option: if specified then the @p chEvtWaitXXXTimeout() - * functions are included in the kernel. - * @note requires @p CH_USE_EVENTS. + * functions are included in the kernel. + * @note requires @p CH_USE_EVENTS. */ #define CH_USE_EVENTS_TIMEOUT @@ -95,12 +100,12 @@ /** Configuration option: if specified then the @p chMsgSendWithEvent() * function is included in the kernel. - * @note requires @p CH_USE_MESSAGES.*/ + * @note requires @p CH_USE_MESSAGES.*/ #define CH_USE_MESSAGES_EVENT /** Configuration option: If enabled then the threads serve messages by * priority instead of FIFO order. - * @note requires @p CH_USE_MESSAGES.*/ + * @note requires @p CH_USE_MESSAGES.*/ #define CH_USE_MESSAGES_PRIORITY /** Configuration option: if specified then the I/O queues APIs are included @@ -113,7 +118,7 @@ /** Configuration option: if specified then the I/O queues with timeout * APIs are included in the kernel. - * @note requires @p CH_USE_SEMAPHORES_TIMEOUT.*/ + * @note requires @p CH_USE_SEMAPHORES_TIMEOUT.*/ #define CH_USE_QUEUES_TIMEOUT /** Configuration option: if specified then the full duplex serial driver APIs @@ -130,9 +135,9 @@ /** Configuration option: Number of RAM bytes to use as system heap. If set to * zero then the whole available RAM is used as system heap. - * @note In order to use the whole RAM as system heap the linker script must - * provide the @p __heap_base__ and @p __heap_end__ symbols. - * @note requires @p CH_USE_HEAP. + * @note In order to use the whole RAM as system heap the linker script must + * provide the @p __heap_base__ and @p __heap_end__ symbols. + * @note requires @p CH_USE_HEAP. */ #define CH_HEAP_SIZE 0 @@ -146,7 +151,7 @@ /** Configuration option: if specified then the dynamic objects creation APIs * are included in the kernel. - * @note requires @p CH_USE_WAITEXIT. + * @note requires @p CH_USE_WAITEXIT. */ #define CH_USE_DYNAMIC -- cgit v1.2.3