kernel/proc/timer.c
/*
 * Arms a timer to expire at either a relative or absolute time specified
 * by tv_user.
 * Setting tv_user to NULL will cancel an existing armed timer.
 */
Arms a timer to expire at either a relative or absolute time specified
by tv_user.
Setting tv_user to NULL will cancel an existing armed timer.
Arms a timer to expire at either a relative or absolute time specified by tv_user . Setting tv_user to NULL will cancel an existing armed timer .
int SetTimeout(int milliseconds, void (*callback)(struct Timer *), void *arg) {
  struct Timer *timer;
  struct Process *current;
  int remaining = 0;
  current = GetCurrentProcess();
  timer = &current->timeout_timer;
  DisableInterrupts();
  if (timer->armed == TRUE) {
    remaining = hardclock_time - timer->expiration_time / JIFFIES_PER_SECOND;
    LIST_REM_ENTRY(&timing_wheel[timer->expiration_time % JIFFIES_PER_SECOND], timer, timer_entry);
    timer->armed = FALSE;
  }
  EnableInterrupts();
  if (milliseconds > 0) {
    SpinLock(&timer_slock);
    timer->expiration_time = hardclock_time + (milliseconds/(1000/JIFFIES_PER_SECOND)) + 1;
    SpinUnlock(&timer_slock);
    timer->process = current;    
    timer->callback = callback;
    timer->arg = arg;
    timer->armed = TRUE;
    LIST_ADD_TAIL(&timing_wheel[timer->expiration_time % JIFFIES_PER_SECOND], timer, timer_entry);
  }
  return remaining;  
}
int SetTimeout ( int milliseconds , void ( * callback ) ( struct Timer * ) , void * arg ) { struct Timer * timer ; struct Process * current ; int remaining = 0 ; current = GetCurrentProcess ( ) ; timer = & current -> timeout_timer ; DisableInterrupts ( ) ; if ( timer -> armed == TRUE ) { remaining = hardclock_time - timer -> expiration_time / JIFFIES_PER_SECOND ; LIST_REM_ENTRY ( & timing_wheel [ timer -> expiration_time % JIFFIES_PER_SECOND ] , timer , timer_entry ) ; timer -> armed = FALSE ; } EnableInterrupts ( ) ; if ( milliseconds > 0 ) { SpinLock ( & timer_slock ) ; timer -> expiration_time = hardclock_time + ( milliseconds / ( 1000 / JIFFIES_PER_SECOND ) ) + 1 ; SpinUnlock ( & timer_slock ) ; timer -> process = current ; timer -> callback = callback ; timer -> arg = arg ; timer -> armed = TRUE ; LIST_ADD_TAIL ( & timing_wheel [ timer -> expiration_time % JIFFIES_PER_SECOND ] , timer , timer_entry ) ; } return remaining ; }
Arms a timer to expire at either a relative or absolute time specified
 by tv_user.
Arms a timer to expire at either a relative or absolute time specified by tv_user .
// Calculate absolute time of expiry
