- it.it_value.tv_sec = ms / 1000;
- it.it_value.tv_usec = 1000 * (ms - (1000 * it.it_value.tv_sec));
- it.it_interval = it.it_value;
- return (setitimer(ITIMER_FLAVOUR, &it, NULL));
-# endif
-}
-
-int
-stopTicker()
-{
-# ifndef HAVE_SETITIMER
- /* debugBelch("No virtual timer on this system\n"); */
- return -1;
-# else
- struct itimerval it;
-
- it.it_value.tv_sec = 0;
- it.it_value.tv_usec = 0;
- it.it_interval = it.it_value;
- return (setitimer(ITIMER_FLAVOUR, &it, NULL));
-# endif
-}
-
-# if 0
-/* This is a potential POSIX version */
-int
-startTicker(nat ms)
-{
- struct sigevent se;
- struct itimerspec it;
- timer_t tid;
-
-#if !defined(THREADED_RTS)
- timestamp = getourtimeofday();
-#endif
-
- se.sigev_notify = SIGEV_SIGNAL;
- se.sigev_signo = ITIMER_SIGNAL;
- se.sigev_value.sival_int = ITIMER_SIGNAL;
- if (timer_create(CLOCK_VIRTUAL, &se, &tid)) {
- barf("can't create virtual timer");
+#if defined(USE_TIMER_CREATE)
+ {
+ struct itimerspec it;
+ struct sigevent ev;
+
+ ev.sigev_notify = SIGEV_SIGNAL;
+ ev.sigev_signo = ITIMER_SIGNAL;
+
+ it.it_value.tv_sec = ms / 1000;
+ it.it_value.tv_nsec = (ms % 1000) * 1000000;
+ it.it_interval = it.it_value;
+
+ if (timer_create(TIMER_FLAVOUR, &ev, &timer) != 0) {
+ sysErrorBelch("timer_create");
+ stg_exit(EXIT_FAILURE);
+ }
+
+ if (timer_settime(timer, 0, &it, NULL) != 0) {
+ sysErrorBelch("timer_settime");
+ stg_exit(EXIT_FAILURE);
+ }