emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] trunk r117621: * atimer.c (toplevel) [HAVE_TIMERFD]: Inclu


From: Dmitry Antipov
Subject: [Emacs-diffs] trunk r117621: * atimer.c (toplevel) [HAVE_TIMERFD]: Include errno.h.
Date: Fri, 01 Aug 2014 06:52:41 +0000
User-agent: Bazaar (2.6b2)

------------------------------------------------------------
revno: 117621
revision-id: address@hidden
parent: address@hidden
committer: Dmitry Antipov <address@hidden>
branch nick: trunk
timestamp: Fri 2014-08-01 10:52:02 +0400
message:
  * atimer.c (toplevel) [HAVE_TIMERFD]: Include errno.h.
  (timerfd_callback): Ignore weird events with no data.  Add tight
  assertions and comments.
  (init_atimer) [HAVE_TIMERFD]: Add environment variable to optionally
  disabletimerfd-based timer.  Use TFD_NONBLOCK for timer descriptor.
modified:
  src/ChangeLog                  changelog-20091113204419-o5vbwnq5f7feedwu-1438
  src/atimer.c                   atimer.c-20091113204419-o5vbwnq5f7feedwu-1759
=== modified file 'src/ChangeLog'
--- a/src/ChangeLog     2014-08-01 00:01:44 +0000
+++ b/src/ChangeLog     2014-08-01 06:52:02 +0000
@@ -1,3 +1,11 @@
+2014-08-01  Dmitry Antipov  <address@hidden>
+
+       * atimer.c (toplevel) [HAVE_TIMERFD]: Include errno.h.
+       (timerfd_callback): Ignore weird events with no data.  Add tight
+       assertions and comments.
+       (init_atimer) [HAVE_TIMERFD]: Add environment variable to optionally
+       disable timerfd-based timer.  Use TFD_NONBLOCK for timer descriptor.
+
 2014-08-01  Paul Eggert  <address@hidden>
 
        * frame.c (x_set_frame_parameters): Fix typo in previous patch.

=== modified file 'src/atimer.c'
--- a/src/atimer.c      2014-07-31 20:17:01 +0000
+++ b/src/atimer.c      2014-08-01 06:52:02 +0000
@@ -27,6 +27,7 @@
 #include <unistd.h>
 
 #ifdef HAVE_TIMERFD
+#include <errno.h>
 # include <sys/timerfd.h>
 #endif
 
@@ -399,14 +400,26 @@
 void
 timerfd_callback (int fd, void *arg)
 {
-  char buf[8];
   ptrdiff_t nbytes;
+  uint64_t expirations;
 
   eassert (fd == timerfd);
-  nbytes = emacs_read (fd, buf, sizeof (buf));
-  /* Just discard an expiration count for now.  */
-  eassert (nbytes == sizeof (buf));
-  do_pending_atimers ();
+  nbytes = emacs_read (fd, &expirations, sizeof (expirations));
+
+  if (nbytes == sizeof (expirations))
+    {
+      /* Timer should expire just once.  */
+      eassert (expirations == 1);
+      do_pending_atimers ();
+    }
+  else if (nbytes < 0)
+    /* For some not yet known reason, we may get weird event and no
+       data on timer descriptor.  This can break Gnus at least, see:
+       http://lists.gnu.org/archive/html/emacs-devel/2014-07/msg00503.html.  */
+    eassert (errno == EAGAIN);
+  else
+    /* I don't know what else can happen with this descriptor.  */
+    emacs_abort ();
 }
 
 #endif /* HAVE_TIMERFD */
@@ -528,7 +541,9 @@
 {
 #ifdef HAVE_ITIMERSPEC
 # ifdef HAVE_TIMERFD
-  timerfd = timerfd_create (CLOCK_REALTIME, TFD_CLOEXEC);
+  /* Until this feature is considered stable, you can ask to not use it.  */
+  timerfd = (egetenv ("EMACS_IGNORE_TIMERFD") ? -1 :
+            timerfd_create (CLOCK_REALTIME, TFD_NONBLOCK | TFD_CLOEXEC));
 # endif
   if (timerfd < 0)
     {


reply via email to

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