diff options
author | Ben Gamari <bgamari.foss@gmail.com> | 2016-05-01 13:39:23 +0200 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2016-05-01 23:29:49 +0200 |
commit | 65e13f66c595ad75bd6e9a55496f1372ead2731d (patch) | |
tree | 91155c792ab9eda72f24c712e6c4e2641514451f /rts/posix/itimer/Setitimer.c | |
parent | 16a51a6c2f265f8670355be03d42b773d93e0684 (diff) | |
download | haskell-65e13f66c595ad75bd6e9a55496f1372ead2731d.tar.gz |
rts: Split up Itimer.c
This shouldn't have any functional changes. It merely splits up what are
essentially three distinct codepaths which are melding together with
CPP.
At the moment I merely #include the implementation to use with CPP
although this really feels very yucky.
Reviewers: erikd, austin, simonmar
Reviewed By: simonmar
Subscribers: thomie
Differential Revision: https://phabricator.haskell.org/D2130
Diffstat (limited to 'rts/posix/itimer/Setitimer.c')
-rw-r--r-- | rts/posix/itimer/Setitimer.c | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/rts/posix/itimer/Setitimer.c b/rts/posix/itimer/Setitimer.c new file mode 100644 index 0000000000..c44e8d8c22 --- /dev/null +++ b/rts/posix/itimer/Setitimer.c @@ -0,0 +1,88 @@ +/* ----------------------------------------------------------------------------- + * + * (c) The GHC Team, 1995-2007 + * + * Interval timer for profiling and pre-emptive scheduling. + * + * ---------------------------------------------------------------------------*/ + +#include "PosixSource.h" +#include "Rts.h" + +#include "Ticker.h" +#include "posix/Itimer.h" +#include "Proftimer.h" +#include "Schedule.h" +#include "posix/Clock.h" +#include "posix/Signals.h" + +/* As recommended in the autoconf manual */ +# ifdef TIME_WITH_SYS_TIME +# include <sys/time.h> +# include <time.h> +# else +# ifdef HAVE_SYS_TIME_H +# include <sys/time.h> +# else +# include <time.h> +# endif +# endif + +#ifdef HAVE_SIGNAL_H +# include <signal.h> +#endif + +#include <string.h> + +static Time itimer_interval = DEFAULT_TICK_INTERVAL; + +void +initTicker (Time interval, TickProc handle_tick) +{ + itimer_interval = interval; + install_vtalrm_handler(SIGALRM, handle_tick); +} + +void +startTicker(void) +{ + struct itimerval it; + + it.it_value.tv_sec = TimeToSeconds(itimer_interval); + it.it_value.tv_usec = TimeToUS(itimer_interval) % 1000000; + it.it_interval = it.it_value; + + if (setitimer(ITIMER_REAL, &it, NULL) != 0) { + sysErrorBelch("setitimer"); + stg_exit(EXIT_FAILURE); + } +} + +void +stopTicker(void) +{ + struct itimerval it; + + it.it_value.tv_sec = 0; + it.it_value.tv_usec = 0; + it.it_interval = it.it_value; + + if (setitimer(ITIMER_REAL, &it, NULL) != 0) { + sysErrorBelch("setitimer"); + stg_exit(EXIT_FAILURE); + } +} + +void +exitTicker (rtsBool wait STG_UNUSED) +{ + return; +} + +int +rtsTimerSignal(void) +{ + return SIGALRM; + // Using SIGALRM can leads to problems, see #850. But we have no + // option if timer_create() is not available. +} |