[En-Nut-Discussion] timer problem in NutOS (Bug #2029411)

Harald Kipp harald.kipp at egnite.de
Sun Jul 27 19:59:36 CEST 2008


Harald Kipp wrote:
> 
> Issue 1 could be solved by moving NutTimerStop to a new function, which 
> is used internally only. The application callable API may mark the timer 
> only, final removal will be done during idle time only, using the 
> internal function. Something similar had been suggested by Erik Lindstein.

Finally I ended up with the following solution:


The part of NutTimerProcessElapsed(), which handles elapsed timers, will 
become more simple.

// elapsed
if (tn->tn_ticks_left == 0){

   // callback
   if (tn->tn_callback) {
     (*tn->tn_callback) (tn, (void *) tn->tn_arg);
   }
   // remove from list
   nutTimerList = nutTimerList->tn_next;
   if (nutTimerList) {
     nutTimerList->tn_prev = NULL;
   }
   if ((tn->tn_ticks_left = tn->tn_ticks) == 0) {
     NutHeapFree(tn);
   }
   else {
     // re-insert
     NutTimerInsert(tn);
   }
}

Instead of killing the timer, NutTimerStop will only expire it.

void NutTimerStop(HANDLE handle)
{
   NUTTIMERINFO *tn = (NUTTIMERINFO *)handle;

   /* Disable periodic operation and callback. */
   tn->tn_ticks = 0;
   tn->tn_callback = NULL;
   /* If not already elapsed, expire the timer. */
   if (tn->tn_ticks_left) {
     if (tn->tn_prev) {
       tn->tn_prev->tn_next = tn->tn_next;
     }
     else {
       nutTimerList = tn->tn_next;
     }
     if (tn->tn_next) {
       tn->tn_next->tn_prev = tn->tn_prev;
       tn->tn_next->tn_ticks_left += tn->tn_ticks_left;
     }
     tn->tn_ticks_left = 0;
     NutTimerInsert(tn);
   }
}

This routine requires some more processing. Here the problem may be, 
that NutMsgQStopTimer() calls NutTimerStop() from within a critical 
section. Is this really required?

Harald





More information about the En-Nut-Discussion mailing list