source: trunk/minix/lib/sysutil/tickdelay.c@ 9

Last change on this file since 9 was 9, checked in by Mattia Monga, 13 years ago

Minix 3.1.2a

File size: 1.4 KB
Line 
1#include "sysutil.h"
2#include <timers.h>
3
4/*===========================================================================*
5 * tickdelay *
6 *===========================================================================*/
7PUBLIC int tickdelay(ticks)
8long ticks; /* number of ticks to wait */
9{
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.
15 */
16 message m, m_alarm;
17 clock_t time_left;
18 int s;
19
20 if (ticks <= 0) return; /* check for robustness */
21
22 m.ALRM_ENDPT = SELF; /* SELF means this process nr */
23 m.ALRM_EXP_TIME = ticks; /* request message after ticks */
24 m.ALRM_ABS_TIME = 0; /* ticks are relative to now */
25 s = _taskcall(SYSTASK, SYS_SETALARM, &m);
26 if (s != OK) return(s);
27
28 receive(CLOCK,&m_alarm); /* await synchronous alarm */
29
30 /* Check if we must reschedule the current alarm. */
31 if (m.ALRM_TIME_LEFT > 0 && m.ALRM_TIME_LEFT != TMR_NEVER) {
32 m.ALRM_EXP_TIME = m.ALRM_TIME_LEFT - ticks;
33 if (m.ALRM_EXP_TIME <= 0)
34 m.ALRM_EXP_TIME = 1;
35 s = _taskcall(SYSTASK, SYS_SETALARM, &m);
36 }
37
38 return(s);
39}
40
41
42
43
44
Note: See TracBrowser for help on using the repository browser.