home *** CD-ROM | disk | FTP | other *** search
- /**
- *
- * Name utsleep -- Suspend processing
- *
- * Synopsis rdur = utsleep(period);
- *
- * unsigned rdur The number of timer ticks the process
- * was actually suspended.
- * unsigned period The number of timer ticks the process
- * is to be suspended.
- *
- * Description UTSLEEP suspends processing for at least the number of
- * ticks requested, and returns the actual number as the
- * functional value. Because the function checks the
- * system clock to determine if the period has transpired,
- * it is possible that the actual duration is longer than
- * requested.
- *
- * On standard IBM PCs, timer ticks occur 1193180/65536
- * (about 18.2) times per second.
- *
- * This function temporarily enables hardware interrupts
- * but restores the state of the interrupt flag before it
- * returns.
- *
- * Returns rdur The number of timer ticks the
- * process actually slept.
- *
- * Version 3.0 (C)Copyright Blaise Computing Inc. 1984, 1986
- *
- * Version 3.02 March 20, 1987
- * Corrected handling of midnight rollover.
- *
- **/
-
- #include <butility.h>
-
- unsigned utsleep(period)
- unsigned period;
- {
- long initclk; /* Initial clock count */
- long nowclk; /* Moving clock count */
- unsigned elpticks; /* Elapsed tick count */
- int ints_were_on; /* Whether interrupts were */
- /* already on */
-
- /* Find out the current clock count and wait until period counts */
- /* have passed. */
-
- ints_were_on = utinton();
- utgetclk(&initclk);
-
- for (elpticks = 0;
- elpticks < period;
- elpticks = (unsigned) (nowclk - initclk))
- {
- utgetclk(&nowclk);
- if (nowclk < initclk) /* Must have wrapped past */
- nowclk += 0x1800b0L; /* midnight. */
- }
-
- if (!ints_were_on)
- utintoff();
-
- return(elpticks);
- }