/** * @brief Time management handler. * @note This handler has to be invoked by a periodic ISR in order to * reschedule the waiting threads. * * @iclass */ void nilSysTimerHandlerI(void) { #if NIL_CFG_TIMEDELTA == 0 thread_ref_t tr = &nil.threads[0]; nil.systime++; do { /* Is the thread in a wait state with timeout?.*/ if (tr->timeout > 0) { nilDbgAssert(!NIL_THD_IS_READY(tr), "nilSysTimerHandlerI(), #1", "is ready"); /* Did the timer reach zero?*/ if (--tr->timeout == 0) { /* Timeout on semaphores requires a special handling because the semaphore counter must be incremented.*/ if (NIL_THD_IS_WTSEM(tr)) tr->u1.semp->cnt++; else if (NIL_THD_IS_SUSP(tr)) tr->u1.trp = NULL; nilSchReadyI(tr, NIL_MSG_TMO); } } /* Lock released in order to give a preemption chance on those architectures supporting IRQ preemption.*/ nilSysUnlockFromISR(); tr++; nilSysLockFromISR(); #if WHG_MOD } while (tr < nil.idlep); #else /* WHG_MOD */ } while (tr < &nil.threads[NIL_CFG_NUM_THREADS]);
/** * @brief Time management handler. * @note This handler has to be invoked by a periodic ISR in order to * reschedule the waiting threads. * * @special */ void nilSysTimerHandler(void) { Thread *tp; systime_t time; time = ++nil.systime; tp = &nil.threads[0]; do { nilSysLockFromIsr(); if (tp->timeout && (tp->wakeup.time == time)) { #if WHG_PATCH nilDbgAssert(tp->waitobj.p != NULL, "nilSysTimerHandler(), #1", ""); /* Could add a field to Thread structure to indicate waitobj type. */ if (tp->waitobj.thdp < nil.threads || tp->waitobj.thdp > nil.idlep) { /* Handle nilSemWaitTimeout. */ tp->wakeup.msg = NIL_MSG_TMO; tp->waitobj.semp->cnt++; } else { /* Do nothing for nilThdSleep */ } #else /* WHG_PATCH */ nilDbgAssert(tp->waitobj.p == NULL, "nilSysTimerHandlerI(), #1", ""); #endif /* WHG_PATCH */ nilSchReadyI(tp); } nilSysUnlockFromIsr(); tp++; #if WHG_MOD } while (tp < nil.idlep); #else /* WHG_MOD */ } while (tp < &nil.threads[NIL_CFG_NUM_THREADS]);