git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@712 35acf78f-673a-0410-8e92-d51de3d6d3f4

This commit is contained in:
gdisirio 2009-02-02 12:48:17 +00:00
parent d1ea164bdb
commit ec4178dd0f
18 changed files with 143 additions and 48 deletions

View File

@ -51,6 +51,11 @@
* 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

View File

@ -51,6 +51,11 @@
* 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

View File

@ -51,6 +51,11 @@
* 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

View File

@ -51,6 +51,11 @@
* 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

View File

@ -51,6 +51,11 @@
* 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

View File

@ -51,6 +51,11 @@
* 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

View File

@ -42,6 +42,11 @@
* 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

View File

@ -51,6 +51,11 @@
* 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

View File

@ -56,6 +56,11 @@
* 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

View File

@ -51,6 +51,11 @@
* 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

View File

@ -206,7 +206,7 @@ EXPAND_ONLY_PREDEF = NO
SEARCH_INCLUDES = YES
INCLUDE_PATH =
INCLUDE_FILE_PATTERNS =
PREDEFINED = __DOXYGEN__ CH_USE_WAITEXIT CH_USE_SEMAPHORES CH_USE_SEMSW CH_USE_SEMAPHORES_TIMEOUT CH_USE_MUTEXES CH_USE_CONDVARS CH_USE_CONDVARS_TIMEOUT CH_USE_EVENTS CH_USE_EVENTS_TIMEOUT CH_USE_EXIT_EVENT CH_USE_QUEUES CH_USE_QUEUES_TIMEOUT CH_USE_QUEUES_HALFDUPLEX CH_USE_SERIAL_FULLDUPLEX CH_USE_SERIAL_HALFDUPLEX CH_USE_HEAP CH_USE_MEMPOOLS CH_USE_MESSAGES CH_USE_MESSAGES_EVENT CH_USE_MESSAGES_PRIORITY CH_USE_DEBUG CH_USE_TRACE CH_USE_DYNAMIC CH_USE_ROUNDROBIN
PREDEFINED = __DOXYGEN__ CH_USE_WAITEXIT CH_USE_SEMAPHORES CH_USE_SEMSW CH_USE_SEMAPHORES_TIMEOUT CH_USE_MUTEXES CH_USE_CONDVARS CH_USE_CONDVARS_TIMEOUT CH_USE_EVENTS CH_USE_EVENTS_TIMEOUT CH_USE_EXIT_EVENT CH_USE_QUEUES CH_USE_QUEUES_TIMEOUT CH_USE_QUEUES_HALFDUPLEX CH_USE_SERIAL_FULLDUPLEX CH_USE_SERIAL_HALFDUPLEX CH_USE_HEAP CH_USE_MEMPOOLS CH_USE_MESSAGES CH_USE_MESSAGES_EVENT CH_USE_DEBUG CH_USE_TRACE CH_USE_DYNAMIC CH_USE_ROUNDROBIN
EXPAND_AS_DEFINED =
SKIP_FUNCTION_MACROS = YES
#---------------------------------------------------------------------------

View File

@ -81,10 +81,18 @@ Win32-MinGW - ChibiOS/RT simulator and demo into a WIN32 process,
handled in a very similar way in every architecture. See the "Concepts"
section and the "Writing interrupt handlers under ChibiOS/RT" article in the
documentation.
- NEW: Added the chEvtSignal() and chEvtSignalI() APIs that allows direct
thread signaling, much more efficient that chEvtBroadcast() when the target
is a known single thread.
- NEW: Added a configuration option that enables the priority enqueuing on
semaphores. It is defaulted to off because usually semaphores are used for
I/O related tasks without hard realtime requirements.
- OPT: Improved ARM7 thumb port code, thanks to some GCC tricks involving
registers usage now the kernel is much smaller, faster and most OS APIs
use less RAM in stack frames (note, this is an ARM7 thumb mode specific
optimization).
- CHANGE: Modified the signature of the chMsgSendWithEvent() API, it now uses
a more efficient event signaling method.
- CHANGE: Removed the field p_tid from the Thread structure and the related
code, this improved the thread creation scores (~2%) and saves some RAM.
The trace buffer field cse_tid is now populated with a simple hash of the

View File

@ -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;
}
}

View File

@ -24,24 +24,27 @@
#include <ch.h>
#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.

View File

@ -25,6 +25,13 @@
#include <ch.h>
#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;

View File

@ -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);

View File

@ -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
}

View File

@ -56,6 +56,11 @@
* 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