Events subsystem optimizations.

git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1538 35acf78f-673a-0410-8e92-d51de3d6d3f4
This commit is contained in:
gdisirio 2010-01-21 19:57:30 +00:00
parent ea02b6612f
commit 11a6a2bf64
2 changed files with 29 additions and 22 deletions

View File

@ -217,17 +217,18 @@ void chEvtDispatch(const evhandler_t handlers[], eventmask_t mask) {
* an higher priority. * an higher priority.
*/ */
eventmask_t chEvtWaitOne(eventmask_t ewmask) { eventmask_t chEvtWaitOne(eventmask_t ewmask) {
Thread *ctp = currp;
eventmask_t m; eventmask_t m;
chSysLock(); chSysLock();
if ((m = (currp->p_epending & ewmask)) == 0) { if ((m = (ctp->p_epending & ewmask)) == 0) {
currp->p_u.ewmask = ewmask; ctp->p_u.ewmask = ewmask;
chSchGoSleepS(THD_STATE_WTOREVT); chSchGoSleepS(THD_STATE_WTOREVT);
m = currp->p_epending & ewmask; m = ctp->p_epending & ewmask;
} }
m &= -m; m &= -m;
currp->p_epending &= ~m; ctp->p_epending &= ~m;
chSysUnlock(); chSysUnlock();
return m; return m;
@ -243,16 +244,17 @@ eventmask_t chEvtWaitOne(eventmask_t ewmask) {
* @return The mask of the served and cleared events. * @return The mask of the served and cleared events.
*/ */
eventmask_t chEvtWaitAny(eventmask_t ewmask) { eventmask_t chEvtWaitAny(eventmask_t ewmask) {
Thread *ctp = currp;
eventmask_t m; eventmask_t m;
chSysLock(); chSysLock();
if ((m = (currp->p_epending & ewmask)) == 0) { if ((m = (ctp->p_epending & ewmask)) == 0) {
currp->p_u.ewmask = ewmask; ctp->p_u.ewmask = ewmask;
chSchGoSleepS(THD_STATE_WTOREVT); chSchGoSleepS(THD_STATE_WTOREVT);
m = currp->p_epending & ewmask; m = ctp->p_epending & ewmask;
} }
currp->p_epending &= ~m; ctp->p_epending &= ~m;
chSysUnlock(); chSysUnlock();
return m; return m;
@ -267,14 +269,15 @@ eventmask_t chEvtWaitAny(eventmask_t ewmask) {
* @return The mask of the served and cleared events. * @return The mask of the served and cleared events.
*/ */
eventmask_t chEvtWaitAll(eventmask_t ewmask) { eventmask_t chEvtWaitAll(eventmask_t ewmask) {
Thread *ctp = currp;
chSysLock(); chSysLock();
if ((currp->p_epending & ewmask) != ewmask) { if ((ctp->p_epending & ewmask) != ewmask) {
currp->p_u.ewmask = ewmask; ctp->p_u.ewmask = ewmask;
chSchGoSleepS(THD_STATE_WTANDEVT); chSchGoSleepS(THD_STATE_WTANDEVT);
} }
currp->p_epending &= ~ewmask; ctp->p_epending &= ~ewmask;
chSysUnlock(); chSysUnlock();
return ewmask; return ewmask;
@ -303,20 +306,21 @@ eventmask_t chEvtWaitAll(eventmask_t ewmask) {
* an higher priority. * an higher priority.
*/ */
eventmask_t chEvtWaitOneTimeout(eventmask_t ewmask, systime_t time) { eventmask_t chEvtWaitOneTimeout(eventmask_t ewmask, systime_t time) {
Thread *ctp = currp;
eventmask_t m; eventmask_t m;
chSysLock(); chSysLock();
if ((m = (currp->p_epending & ewmask)) == 0) { if ((m = (ctp->p_epending & ewmask)) == 0) {
if (TIME_IMMEDIATE == time) if (TIME_IMMEDIATE == time)
return (eventmask_t)0; return (eventmask_t)0;
currp->p_u.ewmask = ewmask; ctp->p_u.ewmask = ewmask;
if (chSchGoSleepTimeoutS(THD_STATE_WTOREVT, time) < RDY_OK) if (chSchGoSleepTimeoutS(THD_STATE_WTOREVT, time) < RDY_OK)
return (eventmask_t)0; return (eventmask_t)0;
m = currp->p_epending & ewmask; m = ctp->p_epending & ewmask;
} }
m &= -m; m &= -m;
currp->p_epending &= ~m; ctp->p_epending &= ~m;
chSysUnlock(); chSysUnlock();
return m; return m;
@ -339,19 +343,20 @@ eventmask_t chEvtWaitOneTimeout(eventmask_t ewmask, systime_t time) {
* @retval 0 if the specified timeout expired. * @retval 0 if the specified timeout expired.
*/ */
eventmask_t chEvtWaitAnyTimeout(eventmask_t ewmask, systime_t time) { eventmask_t chEvtWaitAnyTimeout(eventmask_t ewmask, systime_t time) {
Thread *ctp = currp;
eventmask_t m; eventmask_t m;
chSysLock(); chSysLock();
if ((m = (currp->p_epending & ewmask)) == 0) { if ((m = (ctp->p_epending & ewmask)) == 0) {
if (TIME_IMMEDIATE == time) if (TIME_IMMEDIATE == time)
return (eventmask_t)0; return (eventmask_t)0;
currp->p_u.ewmask = ewmask; ctp->p_u.ewmask = ewmask;
if (chSchGoSleepTimeoutS(THD_STATE_WTOREVT, time) < RDY_OK) if (chSchGoSleepTimeoutS(THD_STATE_WTOREVT, time) < RDY_OK)
return (eventmask_t)0; return (eventmask_t)0;
m = currp->p_epending & ewmask; m = ctp->p_epending & ewmask;
} }
currp->p_epending &= ~m; ctp->p_epending &= ~m;
chSysUnlock(); chSysUnlock();
return m; return m;
@ -372,17 +377,18 @@ eventmask_t chEvtWaitAnyTimeout(eventmask_t ewmask, systime_t time) {
* @retval 0 if the specified timeout expired. * @retval 0 if the specified timeout expired.
*/ */
eventmask_t chEvtWaitAllTimeout(eventmask_t ewmask, systime_t time) { eventmask_t chEvtWaitAllTimeout(eventmask_t ewmask, systime_t time) {
Thread *ctp = currp;
chSysLock(); chSysLock();
if ((currp->p_epending & ewmask) != ewmask) { if ((ctp->p_epending & ewmask) != ewmask) {
if (TIME_IMMEDIATE == time) if (TIME_IMMEDIATE == time)
return (eventmask_t)0; return (eventmask_t)0;
currp->p_u.ewmask = ewmask; ctp->p_u.ewmask = ewmask;
if (chSchGoSleepTimeoutS(THD_STATE_WTANDEVT, time) < RDY_OK) if (chSchGoSleepTimeoutS(THD_STATE_WTANDEVT, time) < RDY_OK)
return (eventmask_t)0; return (eventmask_t)0;
} }
currp->p_epending &= ~ewmask; ctp->p_epending &= ~ewmask;
chSysUnlock(); chSysUnlock();
return ewmask; return ewmask;

View File

@ -59,6 +59,7 @@
- CHANGE: Removed the unnamed union from the Thread structure some compilers - CHANGE: Removed the unnamed union from the Thread structure some compilers
do not support this non standard construct. do not support this non standard construct.
- CHANGE: Modified the thread-related constant macros to have a THD_ prefix. - CHANGE: Modified the thread-related constant macros to have a THD_ prefix.
- OPT: Speed/size optimization to the events subsystem.
- OPT: Speed/size optimization to the mutexes subsystem. - OPT: Speed/size optimization to the mutexes subsystem.
- OPT: Speed/size optimization to the condvars subsystem. - OPT: Speed/size optimization to the condvars subsystem.
- OPT: Speed/size optimization to the synchronous messages subsystem. - OPT: Speed/size optimization to the synchronous messages subsystem.