kernel/proc/timer.c
/*
 * Bottom half of timer handling.
 * 
 * Run this in a high-priority kernel thread.
 */
Bottom half of timer handling.

Run this in a high-priority kernel thread.
Bottom half of timer handling . Run this in a high - priority kernel thread .
void TimerBottomHalf(void) {
  struct Timer *timer, *next_timer;
  while (1)
  {
    KASSERT(bkl_locked == TRUE);
    KASSERT(bkl_owner == timer_process);
    TaskSleep (&timer_rendez);
    SpinLock(&timer_slock);
    while (softclock_time < hardclock_time) {
      SpinUnlock(&timer_slock);
      timer = LIST_HEAD(&timing_wheel[softclock_time % JIFFIES_PER_SECOND]);
      while (timer != NULL) {
        next_timer = LIST_NEXT(timer, timer_entry);
        if (timer->expiration_time <= softclock_time) {
          LIST_REM_ENTRY(&timing_wheel[softclock_time % JIFFIES_PER_SECOND], timer, timer_entry);
          timer->armed = FALSE;
          if (timer->callback != NULL) {
            timer->callback(timer);
          }
        }
        timer = next_timer;
      }
      softclock_time++;
      SpinLock(&timer_slock);
    }
    SpinUnlock(&timer_slock);
  }
}
void TimerBottomHalf ( void ) { struct Timer * timer , * next_timer ; while ( 1 ) { KASSERT ( bkl_locked == TRUE ) ; KASSERT ( bkl_owner == timer_process ) ; TaskSleep ( & timer_rendez ) ; SpinLock ( & timer_slock ) ; while ( softclock_time < hardclock_time ) { SpinUnlock ( & timer_slock ) ; timer = LIST_HEAD ( & timing_wheel [ softclock_time % JIFFIES_PER_SECOND ] ) ; while ( timer != NULL ) { next_timer = LIST_NEXT ( timer , timer_entry ) ; if ( timer -> expiration_time <= softclock_time ) { LIST_REM_ENTRY ( & timing_wheel [ softclock_time % JIFFIES_PER_SECOND ] , timer , timer_entry ) ; timer -> armed = FALSE ; if ( timer -> callback != NULL ) { timer -> callback ( timer ) ; } } timer = next_timer ; } softclock_time ++ ; SpinLock ( & timer_slock ) ; } SpinUnlock ( & timer_slock ) ; } }
Bottom half of timer handling.
Bottom half of timer handling .
// Timer task sleeps, leaving the kernel.
