emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] /srv/bzr/emacs/trunk r110197: Prefer POSIX timers if avail


From: Paul Eggert
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r110197: Prefer POSIX timers if available.
Date: Tue, 25 Sep 2012 12:18:05 -0700
User-agent: Bazaar (2.5.0)

------------------------------------------------------------
revno: 110197
committer: Paul Eggert <address@hidden>
branch nick: trunk
timestamp: Tue 2012-09-25 12:18:05 -0700
message:
  Prefer POSIX timers if available.
  
  They avoid a race if the timer is too close to the current time.
  * atimer.c (alarm_timer, alarm_timer_ok) [SIGEV_SIGNAL]: New static vars.
  (set_alarm) [SIGEV_SIGNAL]: Use POSIX timers if available.
  (init_atimer) [SIGEV_SIGAL]: Initialize them.
modified:
  src/ChangeLog
  src/atimer.c
=== modified file 'src/ChangeLog'
--- a/src/ChangeLog     2012-09-25 12:44:13 +0000
+++ b/src/ChangeLog     2012-09-25 19:18:05 +0000
@@ -1,3 +1,11 @@
+2012-09-25  Paul Eggert  <address@hidden>
+
+       Prefer POSIX timers if available.
+       They avoid a race if the timer is too close to the current time.
+       * atimer.c (alarm_timer, alarm_timer_ok) [SIGEV_SIGNAL]: New static 
vars.
+       (set_alarm) [SIGEV_SIGNAL]: Use POSIX timers if available.
+       (init_atimer) [SIGEV_SIGAL]: Initialize them.
+
 2012-09-25  Eli Zaretskii  <address@hidden>
 
        * coding.c (CHAR_STRING_ADVANCE_NO_UNIFY): Make it an alias of

=== modified file 'src/atimer.c'
--- a/src/atimer.c      2012-09-23 08:44:20 +0000
+++ b/src/atimer.c      2012-09-25 19:18:05 +0000
@@ -40,6 +40,13 @@
 
 static struct atimer *atimers;
 
+/* The alarm timer and whether it was properly initialized, if
+   POSIX timers are available.  */
+#ifdef SIGEV_SIGNAL
+static timer_t alarm_timer;
+static bool alarm_timer_ok;
+#endif
+
 /* Block/unblock SIGALRM.  */
 
 static void
@@ -287,14 +294,25 @@
 #ifdef HAVE_SETITIMER
       struct itimerval it;
 #endif
-
-      /* Determine s/us till the next timer is ripe.  */
-      EMACS_TIME now = current_emacs_time ();
-
-      /* Don't set the interval to 0; this disables the timer.  */
-      EMACS_TIME interval = (EMACS_TIME_LE (atimers->expiration, now)
-                            ? make_emacs_time (0, 1000 * 1000)
-                            : sub_emacs_time (atimers->expiration, now));
+      EMACS_TIME now, interval;
+
+#ifdef SIGEV_SIGNAL
+      if (alarm_timer_ok)
+       {
+         struct itimerspec ispec;
+         ispec.it_value = atimers->expiration;
+         ispec.it_interval.tv_sec = ispec.it_interval.tv_nsec = 0;
+         if (timer_settime (alarm_timer, 0, &ispec, 0) == 0)
+           return;
+       }
+#endif
+
+      /* Determine interval till the next timer is ripe.
+        Don't set the interval to 0; this disables the timer.  */
+      now = current_emacs_time ();
+      interval = (EMACS_TIME_LE (atimers->expiration, now)
+                 ? make_emacs_time (0, 1000 * 1000)
+                 : sub_emacs_time (atimers->expiration, now));
 
 #ifdef HAVE_SETITIMER
 
@@ -398,6 +416,13 @@
 init_atimer (void)
 {
   struct sigaction action;
+#ifdef SIGEV_SIGNAL
+  struct sigevent sigev;
+  sigev.sigev_notify = SIGEV_SIGNAL;
+  sigev.sigev_signo = SIGALRM;
+  sigev.sigev_value.sival_ptr = &alarm_timer;
+  alarm_timer_ok = timer_create (CLOCK_REALTIME, &sigev, &alarm_timer) == 0;
+#endif
   free_atimers = stopped_atimers = atimers = NULL;
   /* pending_signals is initialized in init_keyboard.*/
   emacs_sigaction_init (&action, handle_alarm_signal);


reply via email to

[Prev in Thread] Current Thread [Next in Thread]