diff --git a/os/rt/include/chbsem.h b/os/rt/include/chbsem.h index 46c27483f..ca79665ba 100644 --- a/os/rt/include/chbsem.h +++ b/os/rt/include/chbsem.h @@ -267,8 +267,9 @@ static inline void chBSemSignalI(binary_semaphore_t *bsp) { chDbgCheckClassI(); - if (bsp->bs_sem.s_cnt < 1) + if (bsp->bs_sem.s_cnt < 1) { chSemSignalI(&bsp->bs_sem); + } } /** diff --git a/os/rt/include/chdebug.h b/os/rt/include/chdebug.h index 91ca172a9..728d9bf35 100644 --- a/os/rt/include/chdebug.h +++ b/os/rt/include/chdebug.h @@ -165,8 +165,9 @@ typedef struct { */ #if !defined(chDbgCheck) #define chDbgCheck(c) do { \ - if (CH_DBG_ENABLE_CHECKS && !(c)) \ + if (CH_DBG_ENABLE_CHECKS && !(c)) { \ chSysHalt(__func__); \ + } \ } while (0) #endif /* !defined(chDbgCheck) */ @@ -186,8 +187,9 @@ typedef struct { */ #if !defined(chDbgAssert) #define chDbgAssert(c, r) do { \ - if (CH_DBG_ENABLE_ASSERTS && !(c)) \ + if (CH_DBG_ENABLE_ASSERTS && !(c)) { \ chSysHalt(__func__); \ + } \ } while (0) #endif /* !defined(chDbgAssert) */ /** @} */ diff --git a/os/rt/include/chdynamic.h b/os/rt/include/chdynamic.h index 8a9e05d1e..7a2e0c581 100644 --- a/os/rt/include/chdynamic.h +++ b/os/rt/include/chdynamic.h @@ -48,6 +48,7 @@ #if CH_CFG_USE_DYNAMIC && !CH_CFG_USE_WAITEXIT #error "CH_CFG_USE_DYNAMIC requires CH_CFG_USE_WAITEXIT" #endif + #if CH_CFG_USE_DYNAMIC && !CH_CFG_USE_HEAP && !CH_CFG_USE_MEMPOOLS #error "CH_CFG_USE_DYNAMIC requires CH_CFG_USE_HEAP and/or CH_CFG_USE_MEMPOOLS" #endif diff --git a/os/rt/include/chschd.h b/os/rt/include/chschd.h index b477f23e2..0679cadd5 100644 --- a/os/rt/include/chschd.h +++ b/os/rt/include/chschd.h @@ -613,6 +613,7 @@ static inline thread_t *list_remove(threads_list_t *tlp) { thread_t *tp = tlp->p_next; tlp->p_next = tp->p_next; + return tp; } @@ -638,6 +639,7 @@ static inline thread_t *queue_fifo_remove(threads_queue_t *tqp) { thread_t *tp = tqp->p_next; (tqp->p_next = tp->p_next)->p_prev = (thread_t *)tqp; + return tp; } @@ -645,6 +647,7 @@ static inline thread_t *queue_lifo_remove(threads_queue_t *tqp) { thread_t *tp = tqp->p_prev; (tqp->p_prev = tp->p_prev)->p_next = (thread_t *)tqp; + return tp; } @@ -652,6 +655,7 @@ static inline thread_t *queue_dequeue(thread_t *tp) { tp->p_prev->p_next = tp->p_next; tp->p_next->p_prev = tp->p_prev; + return tp; } #endif /* CH_CFG_OPTIMIZE_SPEED */ @@ -703,8 +707,9 @@ static inline void chSchDoYieldS(void) { chDbgCheckClassS(); - if (chSchCanYieldS()) + if (chSchCanYieldS()) { chSchDoRescheduleBehind(); + } } /** @@ -720,16 +725,19 @@ static inline void chSchPreemption(void) { #if CH_CFG_TIME_QUANTUM > 0 if (currp->p_preempt) { - if (p1 > p2) + if (p1 > p2) { chSchDoRescheduleAhead(); + } } else { - if (p1 >= p2) + if (p1 >= p2) { chSchDoRescheduleBehind(); + } } #else /* CH_CFG_TIME_QUANTUM == 0 */ - if (p1 >= p2) + if (p1 >= p2) { chSchDoRescheduleAhead(); + } #endif /* CH_CFG_TIME_QUANTUM == 0 */ } diff --git a/os/rt/include/chsys.h b/os/rt/include/chsys.h index 12423b998..ce3ae530e 100644 --- a/os/rt/include/chsys.h +++ b/os/rt/include/chsys.h @@ -369,8 +369,9 @@ static inline void chSysUnlockFromISR(void) { */ static inline void chSysUnconditionalLock(void) { - if (port_irq_enabled(port_get_irq_status())) + if (port_irq_enabled(port_get_irq_status())) { chSysLock(); + } } /** @@ -382,8 +383,9 @@ static inline void chSysUnconditionalLock(void) { */ static inline void chSysUnconditionalUnlock(void) { - if (!port_irq_enabled(port_get_irq_status())) + if (!port_irq_enabled(port_get_irq_status())) { chSysUnlock(); + } } #if !CH_CFG_NO_IDLE_THREAD || defined(__DOXYGEN__) diff --git a/os/rt/include/chvt.h b/os/rt/include/chvt.h index 7c6aff6cc..0a4b3a94c 100644 --- a/os/rt/include/chvt.h +++ b/os/rt/include/chvt.h @@ -248,6 +248,7 @@ static inline systime_t chVTGetSystemTime(void) { chSysLock(); systime = chVTGetSystemTimeX(); chSysUnlock(); + return systime; } @@ -350,8 +351,9 @@ static inline bool chVTIsArmedI(virtual_timer_t *vtp) { */ static inline void chVTResetI(virtual_timer_t *vtp) { - if (chVTIsArmedI(vtp)) + if (chVTIsArmedI(vtp)) { chVTDoResetI(vtp); + } } /** @@ -474,8 +476,9 @@ static inline void chVTDoTickI(void) { /* The next element is outside the current time window, the loop is stopped here.*/ - if ((vtp = ch.vtlist.vt_next)->vt_delta > delta) + if ((vtp = ch.vtlist.vt_next)->vt_delta > delta) { break; + } /* The "last time" becomes this timer's expiration time.*/ delta -= vtp->vt_delta; @@ -500,10 +503,12 @@ static inline void chVTDoTickI(void) { else { /* Updating the alarm to the next deadline, deadline that must not be closer in time than the minimum time delta.*/ - if (vtp->vt_delta >= CH_CFG_ST_TIMEDELTA) + if (vtp->vt_delta >= CH_CFG_ST_TIMEDELTA) { port_timer_set_alarm(now + vtp->vt_delta); - else + } + else { port_timer_set_alarm(now + CH_CFG_ST_TIMEDELTA); + } } #endif /* CH_CFG_ST_TIMEDELTA > 0 */ } diff --git a/os/rt/src/chcond.c b/os/rt/src/chcond.c index 355ad2b37..d4234d6b6 100644 --- a/os/rt/src/chcond.c +++ b/os/rt/src/chcond.c @@ -91,8 +91,9 @@ void chCondSignal(condition_variable_t *cp) { chDbgCheck(cp != NULL); chSysLock(); - if (queue_notempty(&cp->c_queue)) + if (queue_notempty(&cp->c_queue)) { chSchWakeupS(queue_fifo_remove(&cp->c_queue), MSG_OK); + } chSysUnlock(); } @@ -153,8 +154,9 @@ void chCondBroadcastI(condition_variable_t *cp) { /* Empties the condition variable queue and inserts all the threads into the ready list in FIFO order. The wakeup message is set to @p MSG_RESET in order to make a chCondBroadcast() detectable from a chCondSignal().*/ - while (cp->c_queue.p_next != (void *)&cp->c_queue) + while (cp->c_queue.p_next != (void *)&cp->c_queue) { chSchReadyI(queue_fifo_remove(&cp->c_queue))->p_u.rdymsg = MSG_RESET; + } } /** @@ -209,13 +211,18 @@ msg_t chCondWaitS(condition_variable_t *cp) { chDbgCheck(cp != NULL); chDbgAssert(ctp->p_mtxlist != NULL, "not owning a mutex"); + /* Getting "current" mutex and releasing it.*/ mp = chMtxGetNextMutexS(); chMtxUnlockS(mp); + + /* Start waiting on the condition variable, on exit the mutex is taken + again.*/ ctp->p_u.wtobjp = cp; queue_prio_insert(ctp, &cp->c_queue); chSchGoSleepS(CH_STATE_WTCOND); msg = ctp->p_u.rdymsg; chMtxLockS(mp); + return msg; } @@ -254,6 +261,7 @@ msg_t chCondWaitTimeout(condition_variable_t *cp, systime_t time) { chSysLock(); msg = chCondWaitTimeoutS(cp, time); chSysUnlock(); + return msg; } @@ -293,13 +301,19 @@ msg_t chCondWaitTimeoutS(condition_variable_t *cp, systime_t time) { chDbgCheck((cp != NULL) && (time != TIME_IMMEDIATE)); chDbgAssert(currp->p_mtxlist != NULL, "not owning a mutex"); + /* Getting "current" mutex and releasing it.*/ mp = chMtxGetNextMutexS(); chMtxUnlockS(mp); + + /* Start waiting on the condition variable, on exit the mutex is taken + again.*/ currp->p_u.wtobjp = cp; queue_prio_insert(currp, &cp->c_queue); msg = chSchGoSleepTimeoutS(CH_STATE_WTCOND, time); - if (msg != MSG_TIMEOUT) + if (msg != MSG_TIMEOUT) { chMtxLockS(mp); + } + return msg; } #endif /* CH_CFG_USE_CONDVARS_TIMEOUT */ diff --git a/os/rt/src/chdebug.c b/os/rt/src/chdebug.c index d749e996a..eef4128d0 100644 --- a/os/rt/src/chdebug.c +++ b/os/rt/src/chdebug.c @@ -113,8 +113,9 @@ */ void _dbg_check_disable(void) { - if ((ch.dbg.isr_cnt != 0) || (ch.dbg.lock_cnt != 0)) + if ((ch.dbg.isr_cnt != 0) || (ch.dbg.lock_cnt != 0)) { chSysHalt("SV#1"); + } } /** @@ -124,8 +125,9 @@ void _dbg_check_disable(void) { */ void _dbg_check_suspend(void) { - if ((ch.dbg.isr_cnt != 0) || (ch.dbg.lock_cnt != 0)) + if ((ch.dbg.isr_cnt != 0) || (ch.dbg.lock_cnt != 0)) { chSysHalt("SV#2"); + } } /** @@ -135,8 +137,9 @@ void _dbg_check_suspend(void) { */ void _dbg_check_enable(void) { - if ((ch.dbg.isr_cnt != 0) || (ch.dbg.lock_cnt != 0)) + if ((ch.dbg.isr_cnt != 0) || (ch.dbg.lock_cnt != 0)) { chSysHalt("SV#3"); + } } /** @@ -146,8 +149,9 @@ void _dbg_check_enable(void) { */ void _dbg_check_lock(void) { - if ((ch.dbg.isr_cnt != 0) || (ch.dbg.lock_cnt != 0)) + if ((ch.dbg.isr_cnt != 0) || (ch.dbg.lock_cnt != 0)) { chSysHalt("SV#4"); + } _dbg_enter_lock(); } @@ -158,8 +162,9 @@ void _dbg_check_lock(void) { */ void _dbg_check_unlock(void) { - if ((ch.dbg.isr_cnt != 0) || (ch.dbg.lock_cnt <= 0)) + if ((ch.dbg.isr_cnt != 0) || (ch.dbg.lock_cnt <= 0)) { chSysHalt("SV#5"); + } _dbg_leave_lock(); } @@ -170,8 +175,9 @@ void _dbg_check_unlock(void) { */ void _dbg_check_lock_from_isr(void) { - if ((ch.dbg.isr_cnt <= 0) || (ch.dbg.lock_cnt != 0)) + if ((ch.dbg.isr_cnt <= 0) || (ch.dbg.lock_cnt != 0)) { chSysHalt("SV#6"); + } _dbg_enter_lock(); } @@ -182,8 +188,9 @@ void _dbg_check_lock_from_isr(void) { */ void _dbg_check_unlock_from_isr(void) { - if ((ch.dbg.isr_cnt <= 0) || (ch.dbg.lock_cnt <= 0)) + if ((ch.dbg.isr_cnt <= 0) || (ch.dbg.lock_cnt <= 0)) { chSysHalt("SV#7"); + } _dbg_leave_lock(); } @@ -195,8 +202,9 @@ void _dbg_check_unlock_from_isr(void) { void _dbg_check_enter_isr(void) { port_lock_from_isr(); - if ((ch.dbg.isr_cnt < 0) || (ch.dbg.lock_cnt != 0)) + if ((ch.dbg.isr_cnt < 0) || (ch.dbg.lock_cnt != 0)) { chSysHalt("SV#8"); + } ch.dbg.isr_cnt++; port_unlock_from_isr(); } @@ -209,8 +217,9 @@ void _dbg_check_enter_isr(void) { void _dbg_check_leave_isr(void) { port_lock_from_isr(); - if ((ch.dbg.isr_cnt <= 0) || (ch.dbg.lock_cnt != 0)) + if ((ch.dbg.isr_cnt <= 0) || (ch.dbg.lock_cnt != 0)) { chSysHalt("SV#9"); + } ch.dbg.isr_cnt--; port_unlock_from_isr(); } @@ -225,8 +234,9 @@ void _dbg_check_leave_isr(void) { */ void chDbgCheckClassI(void) { - if ((ch.dbg.isr_cnt < 0) || (ch.dbg.lock_cnt <= 0)) + if ((ch.dbg.isr_cnt < 0) || (ch.dbg.lock_cnt <= 0)) { chSysHalt("SV#10"); + } } /** @@ -239,8 +249,9 @@ void chDbgCheckClassI(void) { */ void chDbgCheckClassS(void) { - if ((ch.dbg.isr_cnt != 0) || (ch.dbg.lock_cnt <= 0)) + if ((ch.dbg.isr_cnt != 0) || (ch.dbg.lock_cnt <= 0)) { chSysHalt("SV#11"); + } } #endif /* CH_DBG_SYSTEM_STATE_CHECK */ @@ -270,8 +281,9 @@ void _dbg_trace(thread_t *otp) { ch.dbg.trace_buffer.tb_ptr->se_wtobjp = otp->p_u.wtobjp; ch.dbg.trace_buffer.tb_ptr->se_state = (uint8_t)otp->p_state; if (++ch.dbg.trace_buffer.tb_ptr >= - &ch.dbg.trace_buffer.tb_buffer[CH_DBG_TRACE_BUFFER_SIZE]) + &ch.dbg.trace_buffer.tb_buffer[CH_DBG_TRACE_BUFFER_SIZE]) { ch.dbg.trace_buffer.tb_ptr = &ch.dbg.trace_buffer.tb_buffer[0]; + } } #endif /* CH_DBG_ENABLE_TRACE */ diff --git a/os/rt/src/chdynamic.c b/os/rt/src/chdynamic.c index c98dd6030..78a667966 100644 --- a/os/rt/src/chdynamic.c +++ b/os/rt/src/chdynamic.c @@ -149,8 +149,9 @@ thread_t *chThdCreateFromHeap(memory_heap_t *heapp, size_t size, thread_t *tp; wsp = chHeapAlloc(heapp, size); - if (wsp == NULL) + if (wsp == NULL) { return NULL; + } #if CH_DBG_FILL_THREADS _thread_memfill((uint8_t *)wsp, @@ -166,6 +167,7 @@ thread_t *chThdCreateFromHeap(memory_heap_t *heapp, size_t size, tp->p_flags = CH_FLAG_MODE_HEAP; chSchWakeupS(tp, MSG_OK); chSysUnlock(); + return tp; } #endif /* CH_CFG_USE_HEAP */ @@ -201,8 +203,9 @@ thread_t *chThdCreateFromMemoryPool(memory_pool_t *mp, tprio_t prio, chDbgCheck(mp != NULL); wsp = chPoolAlloc(mp); - if (wsp == NULL) + if (wsp == NULL) { return NULL; + } #if CH_DBG_FILL_THREADS _thread_memfill((uint8_t *)wsp, @@ -219,6 +222,7 @@ thread_t *chThdCreateFromMemoryPool(memory_pool_t *mp, tprio_t prio, tp->p_mpool = mp; chSchWakeupS(tp, MSG_OK); chSysUnlock(); + return tp; } #endif /* CH_CFG_USE_MEMPOOLS */ diff --git a/os/rt/src/chevents.c b/os/rt/src/chevents.c index 31841add0..dfd1171bd 100644 --- a/os/rt/src/chevents.c +++ b/os/rt/src/chevents.c @@ -159,11 +159,10 @@ eventmask_t chEvtGetAndClearEvents(eventmask_t events) { eventmask_t m; chSysLock(); - m = currp->p_epending & events; currp->p_epending &= ~events; - chSysUnlock(); + return m; } @@ -179,10 +178,9 @@ eventmask_t chEvtGetAndClearEvents(eventmask_t events) { eventmask_t chEvtAddEvents(eventmask_t events) { chSysLock(); - events = (currp->p_epending |= events); - chSysUnlock(); + return events; } @@ -214,8 +212,9 @@ void chEvtBroadcastFlagsI(event_source_t *esp, eventflags_t flags) { elp->el_flags |= flags; /* When flags == 0 the thread will always be signaled because the source does not emit any flag.*/ - if ((flags == 0) || ((elp->el_flags & elp->el_wflags) != 0)) + if ((flags == 0) || ((elp->el_flags & elp->el_wflags) != 0)) { chEvtSignalI(elp->el_listener, elp->el_events); + } elp = elp->el_next; } } @@ -235,11 +234,10 @@ eventflags_t chEvtGetAndClearFlags(event_listener_t *elp) { eventflags_t flags; chSysLock(); - flags = elp->el_flags; elp->el_flags = 0; - chSysUnlock(); + return flags; } @@ -377,7 +375,6 @@ eventmask_t chEvtWaitOne(eventmask_t events) { eventmask_t m; chSysLock(); - if ((m = (ctp->p_epending & events)) == 0) { ctp->p_u.ewmask = events; chSchGoSleepS(CH_STATE_WTOREVT); @@ -385,8 +382,8 @@ eventmask_t chEvtWaitOne(eventmask_t events) { } m ^= m & (m - 1); ctp->p_epending &= ~m; - chSysUnlock(); + return m; } @@ -407,15 +404,14 @@ eventmask_t chEvtWaitAny(eventmask_t events) { eventmask_t m; chSysLock(); - if ((m = (ctp->p_epending & events)) == 0) { ctp->p_u.ewmask = events; chSchGoSleepS(CH_STATE_WTOREVT); m = ctp->p_epending & events; } ctp->p_epending &= ~m; - chSysUnlock(); + return m; } @@ -434,14 +430,13 @@ eventmask_t chEvtWaitAll(eventmask_t events) { thread_t *ctp = currp; chSysLock(); - if ((ctp->p_epending & events) != events) { ctp->p_u.ewmask = events; chSchGoSleepS(CH_STATE_WTANDEVT); } ctp->p_epending &= ~events; - chSysUnlock(); + return events; } #endif /* CH_CFG_OPTIMIZE_SPEED || !CH_CFG_USE_EVENTS_TIMEOUT */ @@ -474,7 +469,6 @@ eventmask_t chEvtWaitOneTimeout(eventmask_t events, systime_t time) { eventmask_t m; chSysLock(); - if ((m = (ctp->p_epending & events)) == 0) { if (TIME_IMMEDIATE == time) { chSysUnlock(); @@ -489,8 +483,8 @@ eventmask_t chEvtWaitOneTimeout(eventmask_t events, systime_t time) { } m ^= m & (m - 1); ctp->p_epending &= ~m; - chSysUnlock(); + return m; } @@ -517,7 +511,6 @@ eventmask_t chEvtWaitAnyTimeout(eventmask_t events, systime_t time) { eventmask_t m; chSysLock(); - if ((m = (ctp->p_epending & events)) == 0) { if (TIME_IMMEDIATE == time) { chSysUnlock(); @@ -531,8 +524,8 @@ eventmask_t chEvtWaitAnyTimeout(eventmask_t events, systime_t time) { m = ctp->p_epending & events; } ctp->p_epending &= ~m; - chSysUnlock(); + return m; } @@ -557,7 +550,6 @@ eventmask_t chEvtWaitAllTimeout(eventmask_t events, systime_t time) { thread_t *ctp = currp; chSysLock(); - if ((ctp->p_epending & events) != events) { if (TIME_IMMEDIATE == time) { chSysUnlock(); @@ -570,8 +562,8 @@ eventmask_t chEvtWaitAllTimeout(eventmask_t events, systime_t time) { } } ctp->p_epending &= ~events; - chSysUnlock(); + return events; } #endif /* CH_CFG_USE_EVENTS_TIMEOUT */ diff --git a/os/rt/src/chheap.c b/os/rt/src/chheap.c index 9e39951ab..305b88795 100644 --- a/os/rt/src/chheap.c +++ b/os/rt/src/chheap.c @@ -83,6 +83,7 @@ static memory_heap_t default_heap; * @notapi */ void _heap_init(void) { + default_heap.h_provider = chCoreAlloc; default_heap.h_free.h.u.next = (union heap_header *)NULL; default_heap.h_free.h.size = 0; @@ -145,8 +146,8 @@ void *chHeapAlloc(memory_heap_t *heapp, size_t size) { size = MEM_ALIGN_NEXT(size); qp = &heapp->h_free; - H_LOCK(heapp); + H_LOCK(heapp); while (qp->h.u.next != NULL) { hp = qp->h.u.next; if (hp->h.size >= size) { @@ -165,13 +166,12 @@ void *chHeapAlloc(memory_heap_t *heapp, size_t size) { hp->h.size = size; } hp->h.u.heap = heapp; - H_UNLOCK(heapp); + return (void *)(hp + 1); } qp = hp; } - H_UNLOCK(heapp); /* More memory is required, tries to get it from the associated provider @@ -182,9 +182,11 @@ void *chHeapAlloc(memory_heap_t *heapp, size_t size) { hp->h.u.heap = heapp; hp->h.size = size; hp++; + return (void *)hp; } } + return NULL; } @@ -208,8 +210,8 @@ void chHeapFree(void *p) { hp = (union heap_header *)p - 1; heapp = hp->h.u.heap; qp = &heapp->h_free; - H_LOCK(heapp); + H_LOCK(heapp); while (true) { chDbgAssert((hp < qp) || (hp >= LIMIT(qp)), "within free block"); @@ -233,8 +235,8 @@ void chHeapFree(void *p) { } qp = qp->h.u.next; } - H_UNLOCK(heapp); + return; } @@ -255,18 +257,20 @@ size_t chHeapStatus(memory_heap_t *heapp, size_t *sizep) { union heap_header *qp; size_t n, sz; - if (heapp == NULL) + if (heapp == NULL) { heapp = &default_heap; + } H_LOCK(heapp); - sz = 0; - for (n = 0, qp = &heapp->h_free; qp->h.u.next; n++, qp = qp->h.u.next) + for (n = 0, qp = &heapp->h_free; qp->h.u.next; n++, qp = qp->h.u.next) { sz += qp->h.u.next->h.size; - if (sizep) + } + if (sizep) { *sizep = sz; - + } H_UNLOCK(heapp); + return n; } diff --git a/os/rt/src/chmboxes.c b/os/rt/src/chmboxes.c index ace84c625..32d0f35ea 100644 --- a/os/rt/src/chmboxes.c +++ b/os/rt/src/chmboxes.c @@ -154,6 +154,7 @@ msg_t chMBPost(mailbox_t *mbp, msg_t msg, systime_t time) { chSysLock(); rdymsg = chMBPostS(mbp, msg, time); chSysUnlock(); + return rdymsg; } @@ -185,11 +186,13 @@ msg_t chMBPostS(mailbox_t *mbp, msg_t msg, systime_t time) { rdymsg = chSemWaitTimeoutS(&mbp->mb_emptysem, time); if (rdymsg == MSG_OK) { *mbp->mb_wrptr++ = msg; - if (mbp->mb_wrptr >= mbp->mb_top) + if (mbp->mb_wrptr >= mbp->mb_top) { mbp->mb_wrptr = mbp->mb_buffer; + } chSemSignalI(&mbp->mb_fullsem); chSchRescheduleS(); } + return rdymsg; } @@ -212,13 +215,17 @@ msg_t chMBPostI(mailbox_t *mbp, msg_t msg) { chDbgCheckClassI(); chDbgCheck(mbp != NULL); - if (chSemGetCounterI(&mbp->mb_emptysem) <= 0) + if (chSemGetCounterI(&mbp->mb_emptysem) <= 0) { return MSG_TIMEOUT; + } + chSemFastWaitI(&mbp->mb_emptysem); *mbp->mb_wrptr++ = msg; - if (mbp->mb_wrptr >= mbp->mb_top) + if (mbp->mb_wrptr >= mbp->mb_top) { mbp->mb_wrptr = mbp->mb_buffer; + } chSemSignalI(&mbp->mb_fullsem); + return MSG_OK; } @@ -247,6 +254,7 @@ msg_t chMBPostAhead(mailbox_t *mbp, msg_t msg, systime_t time) { chSysLock(); rdymsg = chMBPostAheadS(mbp, msg, time); chSysUnlock(); + return rdymsg; } @@ -277,12 +285,14 @@ msg_t chMBPostAheadS(mailbox_t *mbp, msg_t msg, systime_t time) { rdymsg = chSemWaitTimeoutS(&mbp->mb_emptysem, time); if (rdymsg == MSG_OK) { - if (--mbp->mb_rdptr < mbp->mb_buffer) + if (--mbp->mb_rdptr < mbp->mb_buffer) { mbp->mb_rdptr = mbp->mb_top - 1; + } *mbp->mb_rdptr = msg; chSemSignalI(&mbp->mb_fullsem); chSchRescheduleS(); } + return rdymsg; } @@ -305,13 +315,16 @@ msg_t chMBPostAheadI(mailbox_t *mbp, msg_t msg) { chDbgCheckClassI(); chDbgCheck(mbp != NULL); - if (chSemGetCounterI(&mbp->mb_emptysem) <= 0) + if (chSemGetCounterI(&mbp->mb_emptysem) <= 0) { return MSG_TIMEOUT; + } chSemFastWaitI(&mbp->mb_emptysem); - if (--mbp->mb_rdptr < mbp->mb_buffer) + if (--mbp->mb_rdptr < mbp->mb_buffer) { mbp->mb_rdptr = mbp->mb_top - 1; + } *mbp->mb_rdptr = msg; chSemSignalI(&mbp->mb_fullsem); + return MSG_OK; } @@ -340,6 +353,7 @@ msg_t chMBFetch(mailbox_t *mbp, msg_t *msgp, systime_t time) { chSysLock(); rdymsg = chMBFetchS(mbp, msgp, time); chSysUnlock(); + return rdymsg; } @@ -371,11 +385,13 @@ msg_t chMBFetchS(mailbox_t *mbp, msg_t *msgp, systime_t time) { rdymsg = chSemWaitTimeoutS(&mbp->mb_fullsem, time); if (rdymsg == MSG_OK) { *msgp = *mbp->mb_rdptr++; - if (mbp->mb_rdptr >= mbp->mb_top) + if (mbp->mb_rdptr >= mbp->mb_top) { mbp->mb_rdptr = mbp->mb_buffer; + } chSemSignalI(&mbp->mb_emptysem); chSchRescheduleS(); } + return rdymsg; } @@ -398,13 +414,16 @@ msg_t chMBFetchI(mailbox_t *mbp, msg_t *msgp) { chDbgCheckClassI(); chDbgCheck((mbp != NULL) && (msgp != NULL)); - if (chSemGetCounterI(&mbp->mb_fullsem) <= 0) + if (chSemGetCounterI(&mbp->mb_fullsem) <= 0) { return MSG_TIMEOUT; + } chSemFastWaitI(&mbp->mb_fullsem); *msgp = *mbp->mb_rdptr++; - if (mbp->mb_rdptr >= mbp->mb_top) + if (mbp->mb_rdptr >= mbp->mb_top) { mbp->mb_rdptr = mbp->mb_buffer; + } chSemSignalI(&mbp->mb_emptysem); + return MSG_OK; } #endif /* CH_CFG_USE_MAILBOXES */ diff --git a/os/rt/src/chmemcore.c b/os/rt/src/chmemcore.c index fd35fac86..95c8d2682 100644 --- a/os/rt/src/chmemcore.c +++ b/os/rt/src/chmemcore.c @@ -108,6 +108,7 @@ void *chCoreAlloc(size_t size) { chSysLock(); p = chCoreAllocI(size); chSysUnlock(); + return p; } @@ -129,10 +130,12 @@ void *chCoreAllocI(size_t size) { chDbgCheckClassI(); size = MEM_ALIGN_NEXT(size); - if ((size_t)(endmem - nextmem) < size) + if ((size_t)(endmem - nextmem) < size) { return NULL; + } p = nextmem; nextmem += size; + return p; } diff --git a/os/rt/src/chmempools.c b/os/rt/src/chmempools.c index 7afd5525f..43b4268b8 100644 --- a/os/rt/src/chmempools.c +++ b/os/rt/src/chmempools.c @@ -121,10 +121,13 @@ void *chPoolAllocI(memory_pool_t *mp) { chDbgCheckClassI(); chDbgCheck(mp != NULL); - if ((objp = mp->mp_next) != NULL) + if ((objp = mp->mp_next) != NULL) { mp->mp_next = mp->mp_next->ph_next; - else if (mp->mp_provider != NULL) + } + else if (mp->mp_provider != NULL) { objp = mp->mp_provider(mp->mp_object_size); + } + return objp; } @@ -144,6 +147,7 @@ void *chPoolAlloc(memory_pool_t *mp) { chSysLock(); objp = chPoolAllocI(mp); chSysUnlock(); + return objp; } diff --git a/os/rt/src/chmsg.c b/os/rt/src/chmsg.c index 72f662341..d757efd77 100644 --- a/os/rt/src/chmsg.c +++ b/os/rt/src/chmsg.c @@ -93,11 +93,13 @@ msg_t chMsgSend(thread_t *tp, msg_t msg) { ctp->p_msg = msg; ctp->p_u.wtobjp = &tp->p_msgqueue; msg_insert(ctp, &tp->p_msgqueue); - if (tp->p_state == CH_STATE_WTMSG) + if (tp->p_state == CH_STATE_WTMSG) { chSchReadyI(tp); + } chSchGoSleepS(CH_STATE_SNDMSGQ); msg = ctp->p_u.rdymsg; chSysUnlock(); + return msg; } @@ -119,11 +121,13 @@ thread_t *chMsgWait(void) { thread_t *tp; chSysLock(); - if (!chMsgIsPendingI(currp)) + if (!chMsgIsPendingI(currp)) { chSchGoSleepS(CH_STATE_WTMSG); + } tp = queue_fifo_remove(&currp->p_msgqueue); tp->p_state = CH_STATE_SNDMSG; chSysUnlock(); + return tp; } diff --git a/os/rt/src/chmtx.c b/os/rt/src/chmtx.c index d6af29d0e..e31fbe558 100644 --- a/os/rt/src/chmtx.c +++ b/os/rt/src/chmtx.c @@ -123,9 +123,7 @@ void chMtxObjectInit(mutex_t *mp) { void chMtxLock(mutex_t *mp) { chSysLock(); - chMtxLockS(mp); - chSysUnlock(); } @@ -152,8 +150,9 @@ void chMtxLockS(mutex_t *mp) { /* If the mutex is already owned by this thread, the counter is increased and there is no need of more actions.*/ - if (mp->m_owner == ctp) + if (mp->m_owner == ctp) { mp->m_cnt++; + } else { #endif /* Priority inheritance protocol; explores the thread-mutex dependencies @@ -252,10 +251,9 @@ bool chMtxTryLock(mutex_t *mp) { bool b; chSysLock(); - b = chMtxTryLockS(mp); - chSysUnlock(); + return b; } @@ -352,8 +350,10 @@ void chMtxUnlock(mutex_t *mp) { /* If the highest priority thread waiting in the mutexes list has a greater priority than the current thread base priority then the final priority will have at least that priority.*/ - if (chMtxQueueNotEmptyS(lmp) && (lmp->m_queue.p_next->p_prio > newprio)) + if (chMtxQueueNotEmptyS(lmp) && + (lmp->m_queue.p_next->p_prio > newprio)) { newprio = lmp->m_queue.p_next->p_prio; + } lmp = lmp->m_next; } @@ -372,8 +372,9 @@ void chMtxUnlock(mutex_t *mp) { tp->p_mtxlist = mp; chSchWakeupS(tp, MSG_OK); } - else + else { mp->m_owner = NULL; + } #if CH_CFG_USE_MUTEXES_RECURSIVE } #endif @@ -429,8 +430,10 @@ void chMtxUnlockS(mutex_t *mp) { /* If the highest priority thread waiting in the mutexes list has a greater priority than the current thread base priority then the final priority will have at least that priority.*/ - if (chMtxQueueNotEmptyS(lmp) && (lmp->m_queue.p_next->p_prio > newprio)) + if (chMtxQueueNotEmptyS(lmp) && + (lmp->m_queue.p_next->p_prio > newprio)) { newprio = lmp->m_queue.p_next->p_prio; + } lmp = lmp->m_next; } @@ -449,8 +452,9 @@ void chMtxUnlockS(mutex_t *mp) { tp->p_mtxlist = mp; chSchReadyI(tp); } - else + else { mp->m_owner = NULL; + } #if CH_CFG_USE_MUTEXES_RECURSIVE } #endif diff --git a/os/rt/src/chqueues.c b/os/rt/src/chqueues.c index 28eb7e7f6..07f1ca230 100644 --- a/os/rt/src/chqueues.c +++ b/os/rt/src/chqueues.c @@ -132,13 +132,15 @@ msg_t chIQPutI(input_queue_t *iqp, uint8_t b) { chDbgCheckClassI(); - if (chIQIsFullI(iqp)) + if (chIQIsFullI(iqp)) { return Q_FULL; + } iqp->q_counter++; *iqp->q_wrptr++ = b; - if (iqp->q_wrptr >= iqp->q_top) + if (iqp->q_wrptr >= iqp->q_top) { iqp->q_wrptr = iqp->q_buffer; + } chThdDequeueNextI(&iqp->q_waiting, Q_OK); @@ -169,8 +171,9 @@ msg_t chIQGetTimeout(input_queue_t *iqp, systime_t time) { uint8_t b; chSysLock(); - if (iqp->q_notify) + if (iqp->q_notify) { iqp->q_notify(iqp); + } while (chIQIsEmptyI(iqp)) { msg_t msg; @@ -182,10 +185,11 @@ msg_t chIQGetTimeout(input_queue_t *iqp, systime_t time) { iqp->q_counter--; b = *iqp->q_rdptr++; - if (iqp->q_rdptr >= iqp->q_top) + if (iqp->q_rdptr >= iqp->q_top) { iqp->q_rdptr = iqp->q_buffer; - + } chSysUnlock(); + return b; } @@ -222,8 +226,9 @@ size_t chIQReadTimeout(input_queue_t *iqp, uint8_t *bp, chSysLock(); while (true) { - if (nfy) + if (nfy) { nfy(iqp); + } while (chIQIsEmptyI(iqp)) { if (chThdEnqueueTimeoutS(&iqp->q_waiting, time) != Q_OK) { @@ -239,8 +244,9 @@ size_t chIQReadTimeout(input_queue_t *iqp, uint8_t *bp, chSysUnlock(); /* Gives a preemption chance in a controlled point.*/ r++; - if (--n == 0) + if (--n == 0) { return r; + } chSysLock(); } @@ -329,13 +335,15 @@ msg_t chOQPutTimeout(output_queue_t *oqp, uint8_t b, systime_t time) { oqp->q_counter--; *oqp->q_wrptr++ = b; - if (oqp->q_wrptr >= oqp->q_top) + if (oqp->q_wrptr >= oqp->q_top) { oqp->q_wrptr = oqp->q_buffer; + } - if (oqp->q_notify) + if (oqp->q_notify) { oqp->q_notify(oqp); - + } chSysUnlock(); + return Q_OK; } @@ -354,13 +362,15 @@ msg_t chOQGetI(output_queue_t *oqp) { chDbgCheckClassI(); - if (chOQIsEmptyI(oqp)) + if (chOQIsEmptyI(oqp)) { return Q_EMPTY; + } oqp->q_counter++; b = *oqp->q_rdptr++; - if (oqp->q_rdptr >= oqp->q_top) + if (oqp->q_rdptr >= oqp->q_top) { oqp->q_rdptr = oqp->q_buffer; + } chThdDequeueNextI(&oqp->q_waiting, Q_OK); @@ -408,16 +418,19 @@ size_t chOQWriteTimeout(output_queue_t *oqp, const uint8_t *bp, } oqp->q_counter--; *oqp->q_wrptr++ = *bp++; - if (oqp->q_wrptr >= oqp->q_top) + if (oqp->q_wrptr >= oqp->q_top) { oqp->q_wrptr = oqp->q_buffer; + } - if (nfy) + if (nfy) { nfy(oqp); + } chSysUnlock(); /* Gives a preemption chance in a controlled point.*/ w++; - if (--n == 0) + if (--n == 0) { return w; + } chSysLock(); } } diff --git a/os/rt/src/chregistry.c b/os/rt/src/chregistry.c index a9646f478..043fb1516 100644 --- a/os/rt/src/chregistry.c +++ b/os/rt/src/chregistry.c @@ -134,6 +134,7 @@ thread_t *chRegFirstThread(void) { tp->p_refs++; #endif chSysUnlock(); + return tp; } @@ -153,8 +154,9 @@ thread_t *chRegNextThread(thread_t *tp) { chSysLock(); ntp = tp->p_newer; - if (ntp == (thread_t *)&ch.rlist) + if (ntp == (thread_t *)&ch.rlist) { ntp = NULL; + } #if CH_CFG_USE_DYNAMIC else { chDbgAssert(ntp->p_refs < 255, "too many references"); @@ -165,6 +167,7 @@ thread_t *chRegNextThread(thread_t *tp) { #if CH_CFG_USE_DYNAMIC chThdRelease(tp); #endif + return ntp; } diff --git a/os/rt/src/chschd.c b/os/rt/src/chschd.c index afc843983..2640f25e9 100644 --- a/os/rt/src/chschd.c +++ b/os/rt/src/chschd.c @@ -126,6 +126,7 @@ thread_t *queue_fifo_remove(threads_queue_t *tqp) { thread_t *tp = tqp->p_next; (tqp->p_next = tp->p_next)->p_prev = (thread_t *)tqp; + return tp; } @@ -143,6 +144,7 @@ thread_t *queue_lifo_remove(threads_queue_t *tqp) { thread_t *tp = tqp->p_prev; (tqp->p_prev = tp->p_prev)->p_next = (thread_t *)tqp; + return tp; } @@ -160,6 +162,7 @@ thread_t *queue_dequeue(thread_t *tp) { tp->p_prev->p_next = tp->p_next; tp->p_next->p_prev = tp->p_prev; + return tp; } @@ -190,6 +193,7 @@ thread_t *list_remove(threads_list_t *tlp) { thread_t *tp = tlp->p_next; tlp->p_next = tp->p_next; + return tp; } #endif /* CH_CFG_OPTIMIZE_SPEED */ @@ -228,6 +232,7 @@ thread_t *chSchReadyI(thread_t *tp) { tp->p_next = cp; tp->p_prev = cp->p_prev; tp->p_prev->p_next = cp->p_prev = tp; + return tp; } @@ -327,8 +332,10 @@ msg_t chSchGoSleepTimeoutS(tstate_t newstate, systime_t time) { if (chVTIsArmedI(&vt)) chVTDoResetI(&vt); } - else + else { chSchGoSleepS(newstate); + } + return currp->p_u.rdymsg; } @@ -388,8 +395,9 @@ void chSchRescheduleS(void) { chDbgCheckClassS(); - if (chSchIsRescRequiredI()) + if (chSchIsRescRequiredI()) { chSchDoRescheduleAhead(); + } } /** @@ -408,6 +416,7 @@ void chSchRescheduleS(void) { bool chSchIsPreemptionRequired(void) { tprio_t p1 = firstprio(&ch.rlist.r_queue); tprio_t p2 = currp->p_prio; + #if CH_CFG_TIME_QUANTUM > 0 /* If the running thread has not reached its time quantum, reschedule only if the first thread on the ready queue has a higher priority. diff --git a/os/rt/src/chsem.c b/os/rt/src/chsem.c index 4f9a278c6..36fa8a445 100644 --- a/os/rt/src/chsem.c +++ b/os/rt/src/chsem.c @@ -155,8 +155,9 @@ void chSemResetI(semaphore_t *sp, cnt_t n) { cnt = sp->s_cnt; sp->s_cnt = n; - while (++cnt <= 0) + while (++cnt <= 0) { chSchReadyI(queue_lifo_remove(&sp->s_queue))->p_u.rdymsg = MSG_RESET; + } } /** @@ -177,6 +178,7 @@ msg_t chSemWait(semaphore_t *sp) { chSysLock(); msg = chSemWaitS(sp); chSysUnlock(); + return msg; } @@ -204,8 +206,10 @@ msg_t chSemWaitS(semaphore_t *sp) { currp->p_u.wtobjp = sp; sem_insert(currp, &sp->s_queue); chSchGoSleepS(CH_STATE_WTSEM); + return currp->p_u.rdymsg; } + return MSG_OK; } @@ -234,6 +238,7 @@ msg_t chSemWaitTimeout(semaphore_t *sp, systime_t time) { chSysLock(); msg = chSemWaitTimeoutS(sp, time); chSysUnlock(); + return msg; } @@ -267,12 +272,15 @@ msg_t chSemWaitTimeoutS(semaphore_t *sp, systime_t time) { if (--sp->s_cnt < 0) { if (TIME_IMMEDIATE == time) { sp->s_cnt++; + return MSG_TIMEOUT; } currp->p_u.wtobjp = sp; sem_insert(currp, &sp->s_queue); + return chSchGoSleepTimeoutS(CH_STATE_WTSEM, time); } + return MSG_OK; } @@ -291,8 +299,9 @@ void chSemSignal(semaphore_t *sp) { "inconsistent semaphore"); chSysLock(); - if (++sp->s_cnt <= 0) + if (++sp->s_cnt <= 0) { chSchWakeupS(queue_fifo_remove(&sp->s_queue), MSG_OK); + } chSysUnlock(); } @@ -346,8 +355,9 @@ void chSemAddCounterI(semaphore_t *sp, cnt_t n) { "inconsistent semaphore"); while (n > 0) { - if (++sp->s_cnt <= 0) + if (++sp->s_cnt <= 0) { chSchReadyI(queue_fifo_remove(&sp->s_queue))->p_u.rdymsg = MSG_OK; + } n--; } } @@ -377,8 +387,9 @@ msg_t chSemSignalWait(semaphore_t *sps, semaphore_t *spw) { "inconsistent semaphore"); chSysLock(); - if (++sps->s_cnt <= 0) + if (++sps->s_cnt <= 0) { chSchReadyI(queue_fifo_remove(&sps->s_queue))->p_u.rdymsg = MSG_OK; + } if (--spw->s_cnt < 0) { thread_t *ctp = currp; sem_insert(ctp, &spw->s_queue); @@ -391,6 +402,7 @@ msg_t chSemSignalWait(semaphore_t *sps, semaphore_t *spw) { msg = MSG_OK; } chSysUnlock(); + return msg; } diff --git a/os/rt/src/chsys.c b/os/rt/src/chsys.c index 9bc5f00e4..7823409f3 100644 --- a/os/rt/src/chsys.c +++ b/os/rt/src/chsys.c @@ -164,8 +164,8 @@ void chSysHalt(const char *reason) { ch.dbg.panic_msg = reason; /* Harmless infinite loop.*/ - while (true) - ; + while (true) { + } } /** @@ -215,10 +215,12 @@ syssts_t chSysGetStatusAndLockX(void) { syssts_t sts = port_get_irq_status(); if (port_irq_enabled(sts)) { - if (port_is_isr_context()) + if (port_is_isr_context()) { chSysLockFromISR(); - else + } + else { chSysLock(); + } } return sts; } @@ -235,8 +237,9 @@ syssts_t chSysGetStatusAndLockX(void) { void chSysRestoreStatusX(syssts_t sts) { if (port_irq_enabled(sts)) { - if (port_is_isr_context()) + if (port_is_isr_context()) { chSysUnlockFromISR(); + } else { chSchRescheduleS(); chSysUnlock(); @@ -283,8 +286,9 @@ bool chSysIsCounterWithinX(rtcnt_t cnt, rtcnt_t start, rtcnt_t end) { void chSysPolledDelayX(rtcnt_t cycles) { rtcnt_t start = chSysGetRealtimeCounterX(); rtcnt_t end = start + cycles; - while (chSysIsCounterWithinX(chSysGetRealtimeCounterX(), start, end)) - ; + + while (chSysIsCounterWithinX(chSysGetRealtimeCounterX(), start, end)) { + } } #endif /* PORT_SUPPORTS_RT */ diff --git a/os/rt/src/chthreads.c b/os/rt/src/chthreads.c index 50cf48a79..12d045a84 100644 --- a/os/rt/src/chthreads.c +++ b/os/rt/src/chthreads.c @@ -144,8 +144,9 @@ thread_t *_thread_init(thread_t *tp, tprio_t prio) { */ void _thread_memfill(uint8_t *startp, uint8_t *endp, uint8_t v) { - while (startp < endp) + while (startp < endp) { *startp++ = v; + } } #endif /* CH_DBG_FILL_THREADS */ @@ -184,6 +185,7 @@ thread_t *chThdCreateI(void *wsp, size_t size, (prio <= HIGHPRIO) && (pf != NULL)); PORT_SETUP_CONTEXT(tp, wsp, size, pf, arg); + return _thread_init(tp, prio); } @@ -215,9 +217,11 @@ thread_t *chThdCreateStatic(void *wsp, size_t size, (uint8_t *)wsp + size, CH_DBG_STACK_FILL_VALUE); #endif + chSysLock(); chSchWakeupS(tp = chThdCreateI(wsp, size, prio, pf, arg), MSG_OK); chSysUnlock(); + return tp; } @@ -235,6 +239,7 @@ thread_t *chThdStart(thread_t *tp) { chSysLock(); tp = chThdStartI(tp); chSysUnlock(); + return tp; } @@ -258,8 +263,9 @@ tprio_t chThdSetPriority(tprio_t newprio) { chSysLock(); #if CH_CFG_USE_MUTEXES oldprio = currp->p_realprio; - if ((currp->p_prio == currp->p_realprio) || (newprio > currp->p_prio)) + if ((currp->p_prio == currp->p_realprio) || (newprio > currp->p_prio)) { currp->p_prio = newprio; + } currp->p_realprio = newprio; #else oldprio = currp->p_prio; @@ -267,6 +273,7 @@ tprio_t chThdSetPriority(tprio_t newprio) { #endif chSchRescheduleS(); chSysUnlock(); + return oldprio; } @@ -324,8 +331,9 @@ void chThdSleep(systime_t time) { void chThdSleepUntil(systime_t time) { chSysLock(); - if ((time -= chVTGetSystemTimeX()) > 0) + if ((time -= chVTGetSystemTimeX()) > 0) { chThdSleepS(time); + } chSysUnlock(); } @@ -348,9 +356,11 @@ systime_t chThdSleepUntilWindowed(systime_t prev, systime_t next) { chSysLock(); time = chVTGetSystemTimeX(); - if (chVTIsTimeWithinX(time, prev, next)) + if (chVTIsTimeWithinX(time, prev, next)) { chThdSleepS(next - time); + } chSysUnlock(); + return next; } @@ -411,16 +421,19 @@ void chThdExitS(msg_t msg) { CH_CFG_THREAD_EXIT_HOOK(tp); #endif #if CH_CFG_USE_WAITEXIT - while (list_notempty(&tp->p_waiting)) + while (list_notempty(&tp->p_waiting)) { chSchReadyI(list_remove(&tp->p_waiting)); + } #endif #if CH_CFG_USE_REGISTRY /* Static threads are immediately removed from the registry because there is no memory to recover.*/ - if ((tp->p_flags & CH_FLAG_MODE_MASK) == CH_FLAG_MODE_STATIC) + if ((tp->p_flags & CH_FLAG_MODE_MASK) == CH_FLAG_MODE_STATIC) { REG_REMOVE(tp); + } #endif chSchGoSleepS(CH_STATE_FINAL); + /* The thread never returns here.*/ chDbgAssert(false, "zombies apocalypse"); } @@ -473,9 +486,11 @@ msg_t chThdWait(thread_t *tp) { } msg = tp->p_u.exitcode; chSysUnlock(); + #if CH_CFG_USE_DYNAMIC chThdRelease(tp); #endif + return msg; } #endif /* CH_CFG_USE_WAITEXIT */ @@ -498,6 +513,7 @@ msg_t chThdSuspendS(thread_reference_t *trp) { *trp = tp; tp->p_u.wtobjp = &trp; chSchGoSleepS(CH_STATE_SUSPENDED); + return chThdGetSelfX()->p_u.rdymsg; } @@ -525,11 +541,13 @@ msg_t chThdSuspendTimeoutS(thread_reference_t *trp, systime_t timeout) { chDbgAssert(*trp == NULL, "not NULL"); - if (TIME_IMMEDIATE == timeout) + if (TIME_IMMEDIATE == timeout) { return MSG_TIMEOUT; + } *trp = tp; tp->p_u.wtobjp = &trp; + return chSchGoSleepTimeoutS(CH_STATE_SUSPENDED, timeout); } @@ -622,10 +640,12 @@ void chThdResume(thread_reference_t *trp, msg_t msg) { */ msg_t chThdEnqueueTimeoutS(threads_queue_t *tqp, systime_t timeout) { - if (TIME_IMMEDIATE == timeout) + if (TIME_IMMEDIATE == timeout) { return MSG_TIMEOUT; + } queue_insert(currp, tqp); + return chSchGoSleepTimeoutS(CH_STATE_QUEUED, timeout); } @@ -640,8 +660,9 @@ msg_t chThdEnqueueTimeoutS(threads_queue_t *tqp, systime_t timeout) { */ void chThdDequeueNextI(threads_queue_t *tqp, msg_t msg) { - if (queue_notempty(tqp)) + if (queue_notempty(tqp)) { chThdDoDequeueNextI(tqp, msg); + } } /** @@ -654,8 +675,9 @@ void chThdDequeueNextI(threads_queue_t *tqp, msg_t msg) { */ void chThdDequeueAllI(threads_queue_t *tqp, msg_t msg) { - while (queue_notempty(tqp)) + while (queue_notempty(tqp)) { chThdDoDequeueNextI(tqp, msg); + } } /** @} */ diff --git a/os/rt/src/chtm.c b/os/rt/src/chtm.c index 5ea31c231..9d95bd987 100644 --- a/os/rt/src/chtm.c +++ b/os/rt/src/chtm.c @@ -57,10 +57,12 @@ static inline void tm_stop(time_measurement_t *tmp, tmp->n++; tmp->last = now - tmp->last - offset; tmp->cumulative += (rttime_t)tmp->last; - if (tmp->last > tmp->worst) + if (tmp->last > tmp->worst) { tmp->worst = tmp->last; - else if (tmp->last < tmp->best) + } + else if (tmp->last < tmp->best) { tmp->best = tmp->last; + } } /*===========================================================================*/ diff --git a/os/rt/src/chvt.c b/os/rt/src/chvt.c index 1186cf06f..68ef9b861 100644 --- a/os/rt/src/chvt.c +++ b/os/rt/src/chvt.c @@ -108,8 +108,9 @@ void chVTDoSetI(virtual_timer_t *vtp, systime_t delay, /* If the requested delay is lower than the minimum safe delta then it is raised to the minimum safe value.*/ - if (delay < CH_CFG_ST_TIMEDELTA) + if (delay < CH_CFG_ST_TIMEDELTA) { delay = CH_CFG_ST_TIMEDELTA; + } if (&ch.vtlist == (virtual_timers_list_t *)p) { /* The delta list is empty, the current time becomes the new @@ -124,8 +125,9 @@ void chVTDoSetI(virtual_timer_t *vtp, systime_t delay, /* If the specified delay is closer in time than the first element in the delta list then it becomes the next alarm event in time.*/ - if (delay < p->vt_delta) + if (delay < p->vt_delta) { port_timer_set_alarm(ch.vtlist.vt_lasttime + delay); + } } } #endif /* CH_CFG_ST_TIMEDELTA > 0 */ @@ -181,12 +183,14 @@ void chVTDoResetI(virtual_timer_t *vtp) { else { /* Updating the alarm to the next deadline, deadline that must not be closer in time than the minimum time delta.*/ - if (ch.vtlist.vt_next->vt_delta >= CH_CFG_ST_TIMEDELTA) + if (ch.vtlist.vt_next->vt_delta >= CH_CFG_ST_TIMEDELTA) { port_timer_set_alarm(ch.vtlist.vt_lasttime + ch.vtlist.vt_next->vt_delta); - else + } + else { port_timer_set_alarm(ch.vtlist.vt_lasttime + CH_CFG_ST_TIMEDELTA); + } } } #endif /* CH_CFG_ST_TIMEDELTA > 0 */