aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPaul Eggert2012-10-03 17:10:47 -0700
committerPaul Eggert2012-10-03 17:10:47 -0700
commit2b794d6940aa7dc58e297b3649b7799190d71f64 (patch)
treed0ec1a7864e6198e0c7ea764e8477cd0e48d12c7 /src
parenta1a9f411ab644cb191442ea1de4bc1370341cc88 (diff)
downloademacs-2b794d6940aa7dc58e297b3649b7799190d71f64.tar.gz
emacs-2b794d6940aa7dc58e297b3649b7799190d71f64.zip
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')
-rw-r--r--src/atimer.c6
-rw-r--r--src/profiler.c22
-rw-r--r--src/syssignal.h8
3 files changed, 23 insertions, 13 deletions
diff --git a/src/atimer.c b/src/atimer.c
index 048c62798ef..5752192be76 100644
--- a/src/atimer.c
+++ b/src/atimer.c
@@ -42,7 +42,7 @@ static struct atimer *atimers;
42 42
43/* The alarm timer and whether it was properly initialized, if 43/* The alarm timer and whether it was properly initialized, if
44 POSIX timers are available. */ 44 POSIX timers are available. */
45#ifdef HAVE_TIMER_SETTIME 45#ifdef HAVE_ITIMERSPEC
46static timer_t alarm_timer; 46static timer_t alarm_timer;
47static bool alarm_timer_ok; 47static bool alarm_timer_ok;
48#endif 48#endif
@@ -296,7 +296,7 @@ set_alarm (void)
296#endif 296#endif
297 EMACS_TIME now, interval; 297 EMACS_TIME now, interval;
298 298
299#ifdef HAVE_TIMER_SETTIME 299#ifdef HAVE_ITIMERSPEC
300 if (alarm_timer_ok) 300 if (alarm_timer_ok)
301 { 301 {
302 struct itimerspec ispec; 302 struct itimerspec ispec;
@@ -416,7 +416,7 @@ void
416init_atimer (void) 416init_atimer (void)
417{ 417{
418 struct sigaction action; 418 struct sigaction action;
419#ifdef HAVE_TIMER_SETTIME 419#ifdef HAVE_ITIMERSPEC
420 struct sigevent sigev; 420 struct sigevent sigev;
421 sigev.sigev_notify = SIGEV_SIGNAL; 421 sigev.sigev_notify = SIGEV_SIGNAL;
422 sigev.sigev_signo = SIGALRM; 422 sigev.sigev_signo = SIGALRM;
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)
204 204
205/* The profiler timer and whether it was properly initialized, if 205/* The profiler timer and whether it was properly initialized, if
206 POSIX timers are available. */ 206 POSIX timers are available. */
207#ifdef HAVE_TIMER_SETTIME 207#ifdef HAVE_ITIMERSPEC
208static timer_t profiler_timer; 208static timer_t profiler_timer;
209static bool profiler_timer_ok; 209static bool profiler_timer_ok;
210#endif 210#endif
@@ -240,7 +240,7 @@ handle_profiler_signal (int signal)
240 { 240 {
241 Lisp_Object oquit; 241 Lisp_Object oquit;
242 EMACS_INT count = 1; 242 EMACS_INT count = 1;
243#ifdef HAVE_TIMER_SETTIME 243#ifdef HAVE_ITIMERSPEC
244 if (profiler_timer_ok) 244 if (profiler_timer_ok)
245 { 245 {
246 int overruns = timer_getoverrun (profiler_timer); 246 int overruns = timer_getoverrun (profiler_timer);
@@ -288,7 +288,7 @@ setup_cpu_timer (Lisp_Object sampling_interval)
288 emacs_sigaction_init (&action, deliver_profiler_signal); 288 emacs_sigaction_init (&action, deliver_profiler_signal);
289 sigaction (SIGPROF, &action, 0); 289 sigaction (SIGPROF, &action, 0);
290 290
291#ifdef HAVE_TIMER_SETTIME 291#ifdef HAVE_ITIMERSPEC
292 if (! profiler_timer_ok) 292 if (! profiler_timer_ok)
293 { 293 {
294 /* System clocks to try, in decreasing order of desirability. */ 294 /* System clocks to try, in decreasing order of desirability. */
@@ -322,14 +322,18 @@ setup_cpu_timer (Lisp_Object sampling_interval)
322 { 322 {
323 struct itimerspec ispec; 323 struct itimerspec ispec;
324 ispec.it_value = ispec.it_interval = interval; 324 ispec.it_value = ispec.it_interval = interval;
325 timer_settime (profiler_timer, 0, &ispec, 0); 325 if (timer_settime (profiler_timer, 0, &ispec, 0) == 0)
326 return TIMER_SETTIME_RUNNING; 326 return TIMER_SETTIME_RUNNING;
327 } 327 }
328#endif 328#endif
329 329
330#ifdef HAVE_SETITIMER
330 timer.it_value = timer.it_interval = make_timeval (interval); 331 timer.it_value = timer.it_interval = make_timeval (interval);
331 setitimer (ITIMER_PROF, &timer, 0); 332 if (setitimer (ITIMER_PROF, &timer, 0) == 0)
332 return SETITIMER_RUNNING; 333 return SETITIMER_RUNNING;
334#endif
335
336 return NOT_RUNNING;
333} 337}
334 338
335DEFUN ("profiler-cpu-start", Fprofiler_cpu_start, Sprofiler_cpu_start, 339DEFUN ("profiler-cpu-start", Fprofiler_cpu_start, Sprofiler_cpu_start,
@@ -367,7 +371,7 @@ Return non-nil if the profiler was running. */)
367 case NOT_RUNNING: 371 case NOT_RUNNING:
368 return Qnil; 372 return Qnil;
369 373
370#ifdef HAVE_TIMER_SETTIME 374#ifdef HAVE_ITIMERSPEC
371 case TIMER_SETTIME_RUNNING: 375 case TIMER_SETTIME_RUNNING:
372 { 376 {
373 struct itimerspec disable; 377 struct itimerspec disable;
@@ -377,6 +381,7 @@ Return non-nil if the profiler was running. */)
377 break; 381 break;
378#endif 382#endif
379 383
384#ifdef HAVE_SETITIMER
380 case SETITIMER_RUNNING: 385 case SETITIMER_RUNNING:
381 { 386 {
382 struct itimerval disable; 387 struct itimerval disable;
@@ -384,6 +389,7 @@ Return non-nil if the profiler was running. */)
384 setitimer (ITIMER_PROF, &disable, 0); 389 setitimer (ITIMER_PROF, &disable, 0);
385 } 390 }
386 break; 391 break;
392#endif
387 } 393 }
388 394
389 signal (SIGPROF, SIG_IGN); 395 signal (SIGPROF, SIG_IGN);
diff --git a/src/syssignal.h b/src/syssignal.h
index 66538aad100..83ab19698dd 100644
--- a/src/syssignal.h
+++ b/src/syssignal.h
@@ -29,8 +29,12 @@ extern void init_signals (bool);
29#define FORWARD_SIGNAL_TO_MAIN_THREAD 29#define FORWARD_SIGNAL_TO_MAIN_THREAD
30#endif 30#endif
31 31
32#if (defined SIGPROF && (defined HAVE_TIMER_SETTIME || defined HAVE_SETITIMER) \ 32#if defined HAVE_TIMER_SETTIME && defined SIGEV_SIGNAL
33 && !defined PROFILING) 33# define HAVE_ITIMERSPEC
34#endif
35
36#if (defined SIGPROF && !defined PROFILING \
37 && (defined HAVE_SETITIMER || defined HAVE_ITIMERSPEC))
34# define PROFILER_CPU_SUPPORT 38# define PROFILER_CPU_SUPPORT
35#endif 39#endif
36 40