From 014976ee109e90dec11591118a4ab0d88c00118f Mon Sep 17 00:00:00 2001 From: Giovanni Di Sirio Date: Tue, 10 Mar 2015 10:24:19 +0000 Subject: Added strong type checks to the code rules. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@7746 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/rt/src/chdynamic.c | 10 ++++----- os/rt/src/chevents.c | 29 +++++++++++++------------- os/rt/src/chmboxes.c | 12 +++++------ os/rt/src/chregistry.c | 2 +- os/rt/src/chschd.c | 8 ++++---- os/rt/src/chsem.c | 56 +++++++++++++++++++++++++------------------------- os/rt/src/chsys.c | 2 +- os/rt/src/chthreads.c | 12 +++++------ os/rt/src/chvt.c | 4 ++-- 9 files changed, 68 insertions(+), 67 deletions(-) (limited to 'os/rt/src') diff --git a/os/rt/src/chdynamic.c b/os/rt/src/chdynamic.c index 05cb3a265..ac4db6ba4 100644 --- a/os/rt/src/chdynamic.c +++ b/os/rt/src/chdynamic.c @@ -68,7 +68,7 @@ thread_t *chThdAddRef(thread_t *tp) { chSysLock(); - chDbgAssert(tp->p_refs < 255U, "too many references"); + chDbgAssert(tp->p_refs < (trefs_t)255, "too many references"); tp->p_refs++; chSysUnlock(); @@ -92,7 +92,7 @@ void chThdRelease(thread_t *tp) { trefs_t refs; chSysLock(); - chDbgAssert(tp->p_refs > 0U, "not referenced"); + chDbgAssert(tp->p_refs > (trefs_t)0, "not referenced"); tp->p_refs--; refs = tp->p_refs; chSysUnlock(); @@ -100,7 +100,7 @@ void chThdRelease(thread_t *tp) { /* If the references counter reaches zero and the thread is in its terminated state then the memory can be returned to the proper allocator. Of course static threads are not affected.*/ - if ((refs == 0U) && (tp->p_state == CH_STATE_FINAL)) { + if ((refs == (trefs_t)0) && (tp->p_state == CH_STATE_FINAL)) { switch (tp->p_flags & CH_FLAG_MODE_MASK) { #if CH_CFG_USE_HEAP == TRUE case CH_FLAG_MODE_HEAP: @@ -111,7 +111,7 @@ void chThdRelease(thread_t *tp) { break; #endif #if CH_CFG_USE_MEMPOOLS == TRUE - case CH_FLAG_MODE_MEMPOOL: + case CH_FLAG_MODE_MPOOL: #if CH_CFG_USE_REGISTRY == TRUE REG_REMOVE(tp); #endif @@ -224,7 +224,7 @@ thread_t *chThdCreateFromMemoryPool(memory_pool_t *mp, tprio_t prio, chSysLock(); tp = chThdCreateI(wsp, mp->mp_object_size, prio, pf, arg); - tp->p_flags = CH_FLAG_MODE_MEMPOOL; + tp->p_flags = CH_FLAG_MODE_MPOOL; tp->p_mpool = mp; chSchWakeupS(tp, MSG_OK); chSysUnlock(); diff --git a/os/rt/src/chevents.c b/os/rt/src/chevents.c index df5e4bfaa..96c1594d8 100644 --- a/os/rt/src/chevents.c +++ b/os/rt/src/chevents.c @@ -112,7 +112,7 @@ void chEvtRegisterMaskWithFlags(event_source_t *esp, esp->es_next = elp; elp->el_listener = currp; elp->el_events = events; - elp->el_flags = 0; + elp->el_flags = (eventflags_t)0; elp->el_wflags = wflags; chSysUnlock(); } @@ -219,7 +219,8 @@ 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 == 0U) || ((elp->el_flags & elp->el_wflags) != 0U)) { + if ((flags == (eventflags_t)0) || + ((elp->el_flags & elp->el_wflags) != (eventflags_t)0)) { chEvtSignalI(elp->el_listener, elp->el_events); } elp = elp->el_next; @@ -242,7 +243,7 @@ eventflags_t chEvtGetAndClearFlags(event_listener_t *elp) { chSysLock(); flags = elp->el_flags; - elp->el_flags = 0; + elp->el_flags = (eventflags_t)0; chSysUnlock(); return flags; @@ -286,7 +287,7 @@ void chEvtSignalI(thread_t *tp, eventmask_t events) { tp->p_epending |= events; /* Test on the AND/OR conditions wait states.*/ if (((tp->p_state == CH_STATE_WTOREVT) && - ((tp->p_epending & tp->p_u.ewmask) != 0U)) || + ((tp->p_epending & tp->p_u.ewmask) != (eventmask_t)0)) || ((tp->p_state == CH_STATE_WTANDEVT) && ((tp->p_epending & tp->p_u.ewmask) == tp->p_u.ewmask))) { tp->p_u.rdymsg = MSG_OK; @@ -330,7 +331,7 @@ eventflags_t chEvtGetAndClearFlagsI(event_listener_t *elp) { eventflags_t flags; flags = elp->el_flags; - elp->el_flags = 0; + elp->el_flags = (eventflags_t)0; return flags; } @@ -349,9 +350,9 @@ void chEvtDispatch(const evhandler_t *handlers, eventmask_t events) { chDbgCheck(handlers != NULL); - eid = 0; - while (events != 0U) { - if ((events & EVENT_MASK(eid)) != 0U) { + eid = (eventid_t)0; + while (events != (eventmask_t)0) { + if ((events & EVENT_MASK(eid)) != (eventmask_t)0) { chDbgAssert(handlers[eid] != NULL, "null handler"); events &= ~EVENT_MASK(eid); handlers[eid](eid); @@ -385,12 +386,12 @@ eventmask_t chEvtWaitOne(eventmask_t events) { chSysLock(); m = ctp->p_epending & events; - if (m == 0U) { + if (m == (eventmask_t)0) { ctp->p_u.ewmask = events; chSchGoSleepS(CH_STATE_WTOREVT); m = ctp->p_epending & events; } - m ^= m & (m - 1U); + m ^= m & (m - (eventmask_t)1); ctp->p_epending &= ~m; chSysUnlock(); @@ -415,7 +416,7 @@ eventmask_t chEvtWaitAny(eventmask_t events) { chSysLock(); m = ctp->p_epending & events; - if (m == 0U) { + if (m == (eventmask_t)0) { ctp->p_u.ewmask = events; chSchGoSleepS(CH_STATE_WTOREVT); m = ctp->p_epending & events; @@ -481,7 +482,7 @@ eventmask_t chEvtWaitOneTimeout(eventmask_t events, systime_t time) { chSysLock(); m = ctp->p_epending & events; - if (m == 0U) { + if (m == (eventmask_t)0) { if (TIME_IMMEDIATE == time) { chSysUnlock(); return (eventmask_t)0; @@ -493,7 +494,7 @@ eventmask_t chEvtWaitOneTimeout(eventmask_t events, systime_t time) { } m = ctp->p_epending & events; } - m ^= m & (m - 1U); + m ^= m & (m - (eventmask_t)1); ctp->p_epending &= ~m; chSysUnlock(); @@ -524,7 +525,7 @@ eventmask_t chEvtWaitAnyTimeout(eventmask_t events, systime_t time) { chSysLock(); m = ctp->p_epending & events; - if (m == 0U) { + if (m == (eventmask_t)0) { if (TIME_IMMEDIATE == time) { chSysUnlock(); return (eventmask_t)0; diff --git a/os/rt/src/chmboxes.c b/os/rt/src/chmboxes.c index 6c518676b..21f8ce55e 100644 --- a/os/rt/src/chmboxes.c +++ b/os/rt/src/chmboxes.c @@ -85,14 +85,14 @@ */ void chMBObjectInit(mailbox_t *mbp, msg_t *buf, cnt_t n) { - chDbgCheck((mbp != NULL) && (buf != NULL) && (n > 0)); + chDbgCheck((mbp != NULL) && (buf != NULL) && (n > (cnt_t)0)); mbp->mb_buffer = buf; mbp->mb_rdptr = buf; mbp->mb_wrptr = buf; mbp->mb_top = &buf[n]; chSemObjectInit(&mbp->mb_emptysem, n); - chSemObjectInit(&mbp->mb_fullsem, 0); + chSemObjectInit(&mbp->mb_fullsem, (cnt_t)0); } /** @@ -129,7 +129,7 @@ void chMBResetI(mailbox_t *mbp) { mbp->mb_wrptr = mbp->mb_buffer; mbp->mb_rdptr = mbp->mb_buffer; chSemResetI(&mbp->mb_emptysem, (cnt_t)(mbp->mb_top - mbp->mb_buffer)); - chSemResetI(&mbp->mb_fullsem, 0); + chSemResetI(&mbp->mb_fullsem, (cnt_t)0); } /** @@ -218,7 +218,7 @@ msg_t chMBPostI(mailbox_t *mbp, msg_t msg) { chDbgCheckClassI(); chDbgCheck(mbp != NULL); - if (chSemGetCounterI(&mbp->mb_emptysem) <= 0) { + if (chSemGetCounterI(&mbp->mb_emptysem) <= (cnt_t)0) { return MSG_TIMEOUT; } @@ -318,7 +318,7 @@ msg_t chMBPostAheadI(mailbox_t *mbp, msg_t msg) { chDbgCheckClassI(); chDbgCheck(mbp != NULL); - if (chSemGetCounterI(&mbp->mb_emptysem) <= 0) { + if (chSemGetCounterI(&mbp->mb_emptysem) <= (cnt_t)0) { return MSG_TIMEOUT; } chSemFastWaitI(&mbp->mb_emptysem); @@ -417,7 +417,7 @@ 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) <= (cnt_t)0) { return MSG_TIMEOUT; } chSemFastWaitI(&mbp->mb_fullsem); diff --git a/os/rt/src/chregistry.c b/os/rt/src/chregistry.c index 162d69bf2..aacadf22c 100644 --- a/os/rt/src/chregistry.c +++ b/os/rt/src/chregistry.c @@ -164,7 +164,7 @@ thread_t *chRegNextThread(thread_t *tp) { } #if CH_CFG_USE_DYNAMIC == TRUE else { - chDbgAssert(ntp->p_refs < 255U, "too many references"); + chDbgAssert(ntp->p_refs < (trefs_t)255, "too many references"); ntp->p_refs++; } #endif diff --git a/os/rt/src/chschd.c b/os/rt/src/chschd.c index 91b982b0c..e53384b3d 100644 --- a/os/rt/src/chschd.c +++ b/os/rt/src/chschd.c @@ -257,7 +257,7 @@ void chSchGoSleepS(tstate_t newstate) { #if CH_CFG_TIME_QUANTUM > 0 /* The thread is renouncing its remaining time slices so it will have a new time quantum when it will wakeup.*/ - otp->p_preempt = CH_CFG_TIME_QUANTUM; + otp->p_preempt = (tslices_t)CH_CFG_TIME_QUANTUM; #endif setcurrp(queue_fifo_remove(&ch.rlist.r_queue)); #if defined(CH_CFG_IDLE_ENTER_HOOK) @@ -430,7 +430,7 @@ bool chSchIsPreemptionRequired(void) { if the first thread on the ready queue has a higher priority. Otherwise, if the running thread has used up its time quantum, reschedule if the first thread on the ready queue has equal or higher priority.*/ - return (currp->p_preempt > 0U) ? (p1 > p2) : (p1 >= p2); + return (currp->p_preempt > (tslices_t)0) ? (p1 > p2) : (p1 >= p2); #else /* If the round robin preemption feature is not enabled then performs a simpler comparison.*/ @@ -461,7 +461,7 @@ void chSchDoRescheduleBehind(void) { #endif currp->p_state = CH_STATE_CURRENT; #if CH_CFG_TIME_QUANTUM > 0 - otp->p_preempt = CH_CFG_TIME_QUANTUM; + otp->p_preempt = (tslices_t)CH_CFG_TIME_QUANTUM; #endif (void) chSchReadyI(otp); chSysSwitch(currp, otp); @@ -518,7 +518,7 @@ void chSchDoReschedule(void) { #if CH_CFG_TIME_QUANTUM > 0 /* If CH_CFG_TIME_QUANTUM is enabled then there are two different scenarios to handle on preemption: time quantum elapsed or not.*/ - if (currp->p_preempt == 0U) { + if (currp->p_preempt == (tslices_t)0) { /* The thread consumed its time quantum so it is enqueued behind threads with same priority level, however, it acquires a new time quantum.*/ chSchDoRescheduleBehind(); diff --git a/os/rt/src/chsem.c b/os/rt/src/chsem.c index 30a68e035..4a891b521 100644 --- a/os/rt/src/chsem.c +++ b/os/rt/src/chsem.c @@ -96,7 +96,7 @@ */ void chSemObjectInit(semaphore_t *sp, cnt_t n) { - chDbgCheck((sp != NULL) && (n >= 0)); + chDbgCheck((sp != NULL) && (n >= (cnt_t)0)); queue_init(&sp->s_queue); sp->s_cnt = n; @@ -148,14 +148,14 @@ void chSemResetI(semaphore_t *sp, cnt_t n) { cnt_t cnt; chDbgCheckClassI(); - chDbgCheck((sp != NULL) && (n >= 0)); - chDbgAssert(((sp->s_cnt >= 0) && queue_isempty(&sp->s_queue)) || - ((sp->s_cnt < 0) && queue_notempty(&sp->s_queue)), + chDbgCheck((sp != NULL) && (n >= (cnt_t)0)); + chDbgAssert(((sp->s_cnt >= (cnt_t)0) && queue_isempty(&sp->s_queue)) || + ((sp->s_cnt < (cnt_t)0) && queue_notempty(&sp->s_queue)), "inconsistent semaphore"); cnt = sp->s_cnt; sp->s_cnt = n; - while (++cnt <= 0) { + while (++cnt <= (cnt_t)0) { chSchReadyI(queue_lifo_remove(&sp->s_queue))->p_u.rdymsg = MSG_RESET; } } @@ -198,11 +198,11 @@ msg_t chSemWaitS(semaphore_t *sp) { chDbgCheckClassS(); chDbgCheck(sp != NULL); - chDbgAssert(((sp->s_cnt >= 0) && queue_isempty(&sp->s_queue)) || - ((sp->s_cnt < 0) && queue_notempty(&sp->s_queue)), + chDbgAssert(((sp->s_cnt >= (cnt_t)0) && queue_isempty(&sp->s_queue)) || + ((sp->s_cnt < (cnt_t)0) && queue_notempty(&sp->s_queue)), "inconsistent semaphore"); - if (--sp->s_cnt < 0) { + if (--sp->s_cnt < (cnt_t)0) { currp->p_u.wtsemp = sp; sem_insert(currp, &sp->s_queue); chSchGoSleepS(CH_STATE_WTSEM); @@ -265,11 +265,11 @@ msg_t chSemWaitTimeoutS(semaphore_t *sp, systime_t time) { chDbgCheckClassS(); chDbgCheck(sp != NULL); - chDbgAssert(((sp->s_cnt >= 0) && queue_isempty(&sp->s_queue)) || - ((sp->s_cnt < 0) && queue_notempty(&sp->s_queue)), + chDbgAssert(((sp->s_cnt >= (cnt_t)0) && queue_isempty(&sp->s_queue)) || + ((sp->s_cnt < (cnt_t)0) && queue_notempty(&sp->s_queue)), "inconsistent semaphore"); - if (--sp->s_cnt < 0) { + if (--sp->s_cnt < (cnt_t)0) { if (TIME_IMMEDIATE == time) { sp->s_cnt++; @@ -294,12 +294,12 @@ msg_t chSemWaitTimeoutS(semaphore_t *sp, systime_t time) { void chSemSignal(semaphore_t *sp) { chDbgCheck(sp != NULL); - chDbgAssert(((sp->s_cnt >= 0) && queue_isempty(&sp->s_queue)) || - ((sp->s_cnt < 0) && queue_notempty(&sp->s_queue)), + chDbgAssert(((sp->s_cnt >= (cnt_t)0) && queue_isempty(&sp->s_queue)) || + ((sp->s_cnt < (cnt_t)0) && queue_notempty(&sp->s_queue)), "inconsistent semaphore"); chSysLock(); - if (++sp->s_cnt <= 0) { + if (++sp->s_cnt <= (cnt_t)0) { chSchWakeupS(queue_fifo_remove(&sp->s_queue), MSG_OK); } chSysUnlock(); @@ -320,11 +320,11 @@ void chSemSignalI(semaphore_t *sp) { chDbgCheckClassI(); chDbgCheck(sp != NULL); - chDbgAssert(((sp->s_cnt >= 0) && queue_isempty(&sp->s_queue)) || - ((sp->s_cnt < 0) && queue_notempty(&sp->s_queue)), + chDbgAssert(((sp->s_cnt >= (cnt_t)0) && queue_isempty(&sp->s_queue)) || + ((sp->s_cnt < (cnt_t)0) && queue_notempty(&sp->s_queue)), "inconsistent semaphore"); - if (++sp->s_cnt <= 0) { + if (++sp->s_cnt <= (cnt_t)0) { /* Note, it is done this way in order to allow a tail call on chSchReadyI().*/ thread_t *tp = queue_fifo_remove(&sp->s_queue); @@ -349,13 +349,13 @@ void chSemSignalI(semaphore_t *sp) { void chSemAddCounterI(semaphore_t *sp, cnt_t n) { chDbgCheckClassI(); - chDbgCheck((sp != NULL) && (n > 0)); - chDbgAssert(((sp->s_cnt >= 0) && queue_isempty(&sp->s_queue)) || - ((sp->s_cnt < 0) && queue_notempty(&sp->s_queue)), + chDbgCheck((sp != NULL) && (n > (cnt_t)0)); + chDbgAssert(((sp->s_cnt >= (cnt_t)0) && queue_isempty(&sp->s_queue)) || + ((sp->s_cnt < (cnt_t)0) && queue_notempty(&sp->s_queue)), "inconsistent semaphore"); - while (n > 0) { - if (++sp->s_cnt <= 0) { + while (n > (cnt_t)0) { + if (++sp->s_cnt <= (cnt_t)0) { chSchReadyI(queue_fifo_remove(&sp->s_queue))->p_u.rdymsg = MSG_OK; } n--; @@ -379,18 +379,18 @@ msg_t chSemSignalWait(semaphore_t *sps, semaphore_t *spw) { msg_t msg; chDbgCheck((sps != NULL) && (spw != NULL)); - chDbgAssert(((sps->s_cnt >= 0) && queue_isempty(&sps->s_queue)) || - ((sps->s_cnt < 0) && queue_notempty(&sps->s_queue)), + chDbgAssert(((sps->s_cnt >= (cnt_t)0) && queue_isempty(&sps->s_queue)) || + ((sps->s_cnt < (cnt_t)0) && queue_notempty(&sps->s_queue)), "inconsistent semaphore"); - chDbgAssert(((spw->s_cnt >= 0) && queue_isempty(&spw->s_queue)) || - ((spw->s_cnt < 0) && queue_notempty(&spw->s_queue)), + chDbgAssert(((spw->s_cnt >= (cnt_t)0) && queue_isempty(&spw->s_queue)) || + ((spw->s_cnt < (cnt_t)0) && queue_notempty(&spw->s_queue)), "inconsistent semaphore"); chSysLock(); - if (++sps->s_cnt <= 0) { + if (++sps->s_cnt <= (cnt_t)0) { chSchReadyI(queue_fifo_remove(&sps->s_queue))->p_u.rdymsg = MSG_OK; } - if (--spw->s_cnt < 0) { + if (--spw->s_cnt < (cnt_t)0) { thread_t *ctp = currp; sem_insert(ctp, &spw->s_queue); ctp->p_u.wtsemp = spw; diff --git a/os/rt/src/chsys.c b/os/rt/src/chsys.c index 44c4fc567..a9fd3aa53 100644 --- a/os/rt/src/chsys.c +++ b/os/rt/src/chsys.c @@ -188,7 +188,7 @@ void chSysTimerHandlerI(void) { #if CH_CFG_TIME_QUANTUM > 0 /* Running thread has not used up quantum yet? */ - if (currp->p_preempt > 0U) { + if (currp->p_preempt > (tslices_t)0) { /* Decrement remaining quantum.*/ currp->p_preempt--; } diff --git a/os/rt/src/chthreads.c b/os/rt/src/chthreads.c index 491f416d5..9c18788c0 100644 --- a/os/rt/src/chthreads.c +++ b/os/rt/src/chthreads.c @@ -94,20 +94,20 @@ thread_t *_thread_init(thread_t *tp, tprio_t prio) { tp->p_state = CH_STATE_WTSTART; tp->p_flags = CH_FLAG_MODE_STATIC; #if CH_CFG_TIME_QUANTUM > 0 - tp->p_preempt = CH_CFG_TIME_QUANTUM; + tp->p_preempt = (tslices_t)CH_CFG_TIME_QUANTUM; #endif #if CH_CFG_USE_MUTEXES == TRUE tp->p_realprio = prio; tp->p_mtxlist = NULL; #endif #if CH_CFG_USE_EVENTS == TRUE - tp->p_epending = 0; + tp->p_epending = (eventmask_t)0; #endif #if CH_DBG_THREADS_PROFILING == TRUE - tp->p_time = 0; + tp->p_time = (systime_t)0; #endif #if CH_CFG_USE_DYNAMIC == TRUE - tp->p_refs = 1; + tp->p_refs = (trefs_t)1; #endif #if CH_CFG_USE_REGISTRY == TRUE tp->p_name = NULL; @@ -333,7 +333,7 @@ void chThdSleepUntil(systime_t time) { chSysLock(); time -= chVTGetSystemTimeX(); - if (time > 0U) { + if (time > (systime_t)0) { chThdSleepS(time); } chSysUnlock(); @@ -480,7 +480,7 @@ msg_t chThdWait(thread_t *tp) { chSysLock(); chDbgAssert(tp != currp, "waiting self"); #if CH_CFG_USE_DYNAMIC == TRUE - chDbgAssert(tp->p_refs > 0U, "not referenced"); + chDbgAssert(tp->p_refs > (trefs_t)0, "not referenced"); #endif if (tp->p_state != CH_STATE_FINAL) { list_insert(currp, &tp->p_waiting); diff --git a/os/rt/src/chvt.c b/os/rt/src/chvt.c index d802bc0c3..61fa7e056 100644 --- a/os/rt/src/chvt.c +++ b/os/rt/src/chvt.c @@ -64,9 +64,9 @@ void _vt_init(void) { ch.vtlist.vt_prev = (virtual_timer_t *)&ch.vtlist; ch.vtlist.vt_delta = (systime_t)-1; #if CH_CFG_ST_TIMEDELTA == 0 - ch.vtlist.vt_systime = 0; + ch.vtlist.vt_systime = (systime_t)0; #else /* CH_CFG_ST_TIMEDELTA > 0 */ - ch.vtlist.vt_lasttime = 0; + ch.vtlist.vt_lasttime = (systime_t)0; #endif /* CH_CFG_ST_TIMEDELTA > 0 */ } -- cgit v1.2.3