]> code.delx.au - gnu-emacs/blobdiff - src/profiler.c
Port documentation to Texinfo 5.0.
[gnu-emacs] / src / profiler.c
index 7b4ffc7f7bf2f9de46510f93ad74ef4ddd021099..b9035c34210315253e5cc1ea76315079cb358a6d 100644 (file)
@@ -1,6 +1,6 @@
 /* Profiler implementation.
 
-Copyright (C) 2012 Free Software Foundation, Inc.
+Copyright (C) 2012-2013 Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
@@ -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
@@ -239,8 +239,9 @@ handle_profiler_signal (int signal)
   else
     {
       Lisp_Object oquit;
+      bool saved_pending_signals;
       EMACS_INT count = 1;
-#ifdef HAVE_TIMER_SETTIME
+#ifdef HAVE_ITIMERSPEC
       if (profiler_timer_ok)
        {
          int overruns = timer_getoverrun (profiler_timer);
@@ -252,12 +253,15 @@ handle_profiler_signal (int signal)
         uses QUIT, which can call malloc, which can cause disaster in
         a signal handler.  So inhibit QUIT.  */
       oquit = Vinhibit_quit;
+      saved_pending_signals = pending_signals;
       Vinhibit_quit = Qt;
+      pending_signals = 0;
 
       eassert (HASH_TABLE_P (cpu_log));
       record_backtrace (XHASH_TABLE (cpu_log), count);
 
       Vinhibit_quit = oquit;
+      pending_signals = saved_pending_signals;
     }
 }
 
@@ -288,7 +292,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 +326,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 +375,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 +385,7 @@ Return non-nil if the profiler was running.  */)
       break;
 #endif
 
+#ifdef HAVE_SETITIMER
     case SETITIMER_RUNNING:
       {
        struct itimerval disable;
@@ -384,6 +393,7 @@ Return non-nil if the profiler was running.  */)
        setitimer (ITIMER_PROF, &disable, 0);
       }
       break;
+#endif
     }
 
   signal (SIGPROF, SIG_IGN);