home *** CD-ROM | disk | FTP | other *** search
- /**
- *
- * Name UTSLEEP -- Suspend processing for some duration.
- *
- * 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 6.00 (C)Copyright Blaise Computing Inc. 1984,1987,1989
- *
- **/
-
-
- #include <butil.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 on */
- /* already. */
-
- /* 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 midnight. */
- nowclk += 0x1800b0L;
- }
-
- if (!ints_were_on)
- utintoff();
-
- return(elpticks);
- }