summaryrefslogtreecommitdiff
path: root/src/profiler.c
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2012-10-03 17:10:47 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2012-10-03 17:10:47 -0700
commit2b794d6940aa7dc58e297b3649b7799190d71f64 (patch)
treed0ec1a7864e6198e0c7ea764e8477cd0e48d12c7 /src/profiler.c
parenta1a9f411ab644cb191442ea1de4bc1370341cc88 (diff)
downloademacs-2b794d6940aa7dc58e297b3649b7799190d71f64.tar.gz
Port timers to OpenBSD, plus check for timer failures.
OpenBSD problem reported by Han Boetes. * profiler.c (setup_cpu_timer): Check for failure of timer_settime and/or setitimer. (Fprofiler_cpu_stop): Don't assume HAVE_SETITIMER. * syssignal.h (HAVE_ITIMERSPEC): New macro. This is for platforms like OpenBSD, which has timer_settime but does not declare it. OpenBSD does not define SIGEV_SIGNAL, so use that when deciding whether to use itimerspec-related primitives. All uses of HAVE_TIMER_SETTIME replaced with HAVE_ITIMERSPEC.
Diffstat (limited to 'src/profiler.c')
-rw-r--r--src/profiler.c22
1 files changed, 14 insertions, 8 deletions
diff --git a/src/profiler.c b/src/profiler.c
index 7b4ffc7f7bf..461aae3e09f 100644
--- a/src/profiler.c
+++ b/src/profiler.c
@@ -204,7 +204,7 @@ record_backtrace (log_t *log, EMACS_INT count)
/* The profiler timer and whether it was properly initialized, if
POSIX timers are available. */
-#ifdef HAVE_TIMER_SETTIME
+#ifdef HAVE_ITIMERSPEC
static timer_t profiler_timer;
static bool profiler_timer_ok;
#endif
@@ -240,7 +240,7 @@ handle_profiler_signal (int signal)
{
Lisp_Object oquit;
EMACS_INT count = 1;
-#ifdef HAVE_TIMER_SETTIME
+#ifdef HAVE_ITIMERSPEC
if (profiler_timer_ok)
{
int overruns = timer_getoverrun (profiler_timer);
@@ -288,7 +288,7 @@ setup_cpu_timer (Lisp_Object sampling_interval)
emacs_sigaction_init (&action, deliver_profiler_signal);
sigaction (SIGPROF, &action, 0);
-#ifdef HAVE_TIMER_SETTIME
+#ifdef HAVE_ITIMERSPEC
if (! profiler_timer_ok)
{
/* System clocks to try, in decreasing order of desirability. */
@@ -322,14 +322,18 @@ setup_cpu_timer (Lisp_Object sampling_interval)
{
struct itimerspec ispec;
ispec.it_value = ispec.it_interval = interval;
- timer_settime (profiler_timer, 0, &ispec, 0);
- return TIMER_SETTIME_RUNNING;
+ if (timer_settime (profiler_timer, 0, &ispec, 0) == 0)
+ return TIMER_SETTIME_RUNNING;
}
#endif
+#ifdef HAVE_SETITIMER
timer.it_value = timer.it_interval = make_timeval (interval);
- setitimer (ITIMER_PROF, &timer, 0);
- return SETITIMER_RUNNING;
+ if (setitimer (ITIMER_PROF, &timer, 0) == 0)
+ return SETITIMER_RUNNING;
+#endif
+
+ return NOT_RUNNING;
}
DEFUN ("profiler-cpu-start", Fprofiler_cpu_start, Sprofiler_cpu_start,
@@ -367,7 +371,7 @@ Return non-nil if the profiler was running. */)
case NOT_RUNNING:
return Qnil;
-#ifdef HAVE_TIMER_SETTIME
+#ifdef HAVE_ITIMERSPEC
case TIMER_SETTIME_RUNNING:
{
struct itimerspec disable;
@@ -377,6 +381,7 @@ Return non-nil if the profiler was running. */)
break;
#endif
+#ifdef HAVE_SETITIMER
case SETITIMER_RUNNING:
{
struct itimerval disable;
@@ -384,6 +389,7 @@ Return non-nil if the profiler was running. */)
setitimer (ITIMER_PROF, &disable, 0);
}
break;
+#endif
}
signal (SIGPROF, SIG_IGN);