home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_08_11 / 8n11110b < prev    next >
Text File  |  1990-09-20  |  1KB  |  39 lines

  1.  
  2.  
  3. /* subtract time from all timers, enabling any that run out along the way */
  4. void
  5. timers_update(time)
  6. TIME time;
  7. {
  8.         static struct timer timer_last = {
  9.                 FALSE                   /* in use */,
  10.                 VERY_LONG_TIME          /* time */,
  11.                 NULL                    /* event pointer */
  12.         };
  13.  
  14.         struct timer *t;
  15.  
  16.         timer_next = &timer_last;
  17.  
  18.         for (t=timers;t<&timers[MAX_TIMERS];t++) {
  19.                 if (t->inuse) {
  20.                         if (time < t->time) { /* unexpired */
  21.                                 t->time -= time;
  22.                                 if (t->time < timer_next->time)
  23.                                         timer_next = t;
  24.                         } else { /* expired */
  25.                                 /* tell scheduler */
  26.                                 *t->event = TRUE;
  27.                                 t->inuse = 0;   /* remove timer */
  28.                         }
  29.                 }
  30.         }
  31.  
  32.         /* reset timer_next if no timers found */
  33.         if (!timer_next->inuse) timer_next = 0;
  34. }
  35.  
  36. listing 4
  37.  
  38.  
  39.