VM: full munmap
[minix.git] / lib / libsys / tickdelay.c
blobd7f98450df6eafd96f343ceb9bf2d47c69089f85
1 #include "sysutil.h"
2 #include <timers.h>
4 /*===========================================================================*
5 * tickdelay *
6 *===========================================================================*/
7 int tickdelay(ticks)
8 long ticks; /* number of ticks to wait */
10 /* This function uses the synchronous alarm to delay for a while. This works
11 * even if a previous synchronous alarm was scheduled, because the remaining
12 * tick of the previous alarm are returned so that it can be rescheduled.
13 * Note however that a long tick_delay (longer than the remaining time of the
14 * previous) alarm will also delay the previous alarm.
16 message m, m_alarm;
17 int s;
19 if (ticks <= 0) return OK; /* check for robustness */
21 m.ALRM_EXP_TIME = ticks; /* request message after ticks */
22 m.ALRM_ABS_TIME = 0; /* ticks are relative to now */
23 s = _kernel_call(SYS_SETALARM, &m);
24 if (s != OK) return(s);
26 sef_receive(CLOCK,&m_alarm); /* await synchronous alarm */
28 /* Check if we must reschedule the current alarm. */
29 if (m.ALRM_TIME_LEFT > 0 && m.ALRM_TIME_LEFT != TMR_NEVER) {
30 m.ALRM_EXP_TIME = m.ALRM_TIME_LEFT - ticks;
31 if (m.ALRM_EXP_TIME <= 0)
32 m.ALRM_EXP_TIME = 1;
33 s = _kernel_call(SYS_SETALARM, &m);
36 return(s);