2 % (c) The AQUA Project, Glasgow University, 1995
4 %************************************************************************
6 \section[Itimer.lc]{Interval Timer}
8 %************************************************************************
10 The interval timer is used for profiling and for context switching in the
11 threaded build. Though POSIX 1003.4 includes a standard interface for
12 such things, no one really seems to be implementing them yet. Even
13 Solaris 2.3 only seems to provide support for @CLOCK_REAL@, whereas we're
14 keen on getting access to @CLOCK_VIRTUAL@.
16 Hence, we use the old-fashioned @setitimer@ that just about everyone seems
17 to support. So much for standards.
21 #if defined(PROFILING) || defined(CONCURRENT)
23 # include "platform.h"
25 # define NON_POSIX_SOURCE
29 /* As recommended in the autoconf manual */
30 # ifdef TIME_WITH_SYS_TIME
31 # include <sys/time.h>
34 # ifdef HAVE_SYS_TIME_H
35 # include <sys/time.h>
42 initialize_virtual_timer(ms)
45 # ifndef HAVE_SETITIMER
46 fprintf(stderr, "No virtual timer on this system\n");
51 it.it_value.tv_sec = ms / 1000;
52 it.it_value.tv_usec = 1000 * (ms - (1000 * it.it_value.tv_sec));
53 it.it_interval = it.it_value;
54 return (setitimer(ITIMER_VIRTUAL, &it, NULL));
59 /* This is a potential POSIX version */
61 initialize_virtual_timer(ms)
68 se.sigev_notify = SIGEV_SIGNAL;
69 se.sigev_signo = SIGVTALRM;
70 se.sigev_value.sival_int = SIGVTALRM;
71 if (timer_create(CLOCK_VIRTUAL, &se, &tid)) {
72 fprintf(stderr, "Can't create virtual timer.\n");
75 it.it_value.tv_sec = ms / 1000;
76 it.it_value.tv_nsec = 1000000 * (ms - 1000 * it.it_value.tv_sec);
77 it.it_interval = it.it_value;
78 timer_settime(tid, TIMER_RELTIME, &it, NULL);
82 #endif /* PROFILING || CONCURRENT */