home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_08_04 / 8n04114a < prev    next >
Text File  |  1990-03-20  |  2KB  |  92 lines

  1. ****************
  2. ** Listing 1  **
  3. ****************
  4.  
  5. /*
  6.  
  7.   timer_int()    -- Timer interrupt routine
  8.  
  9.   This routine handle the incoming timer interrupt.  The
  10.   interrupt is acknowledged and cleared.  Then the alarm()
  11.   routine is forked to handle the rest of the timer stuff.
  12.  
  13. */
  14.  
  15. void timer_int()
  16.   {
  17.   while (1)
  18.     {
  19.     /* Clear timer interrupt here. */
  20.     outp(0x20, 0x20);
  21.  
  22.     /* Fork the processing routine. */
  23.     fork_driver(alarm);
  24.     }
  25.   }
  26.  
  27.  
  28.  
  29.  
  30. /* 
  31.  
  32.   alarm()    -- Timer Alarm routine
  33.  
  34.   This routine is the fork routine of the system timer
  35.   device.
  36.  
  37.   It will alert any tasks that have expiring system
  38.   timers this tick.
  39.  
  40. */
  41.  
  42. void alarm(dummy, tcb)
  43. unsigned long dummy;
  44. TSS *tcb;
  45.   {
  46.  
  47. /* Time slice -- Significant event */
  48.  
  49.   significant_event = 1;
  50.  
  51. /* One more tick... */
  52.  
  53.   ++timer_interrupts;
  54.  
  55. /* For each item on the queue (which is in least to
  56.    most time to wait order), see if the top of the
  57.    queue is ready to alert.
  58.  
  59.   Alerting consists of setting the target task's event
  60.   flags and delivering any required Asynchronous
  61.   Traps (ASTs).                        */
  62.  
  63.   while (timer_waiting)
  64.     {
  65.     /* Change to proper LDT of next task. */
  66.     set_ldt(timer_waiting_ldt, tcb);
  67.  
  68.     /* Check to see if timer has expired for this task. */
  69.     if ((long) (timer_interrupts - 
  70.                 ((P_TIMER *) timer_waiting -> pblock) ->
  71.                 wakeup) >= 0)
  72.       {
  73.       /* Timer has expired.  Set appropriate event. */
  74.       set_event(timer_waiting -> my_handle.t,
  75.                 timer_waiting -> ef_cluster,
  76.         timer_waiting -> ef_mask);
  77.  
  78.       /* Deliver AST as required. */
  79.       deliver_ast(timer_waiting -> my_handle.t,
  80.                   timer_waiting -> ast_addr);
  81.  
  82.       /* Remove from timer list and continue. */
  83.       timer_waiting_ldt = timer_waiting -> link_ldt;
  84.       timer_waiting = timer_waiting -> link;
  85.       }
  86.     else
  87.       /* Timer hasn't expired.  Don't check any more
  88.          since the tasks are sorted in ascending order. */
  89.       break;
  90.     }
  91.   }
  92.