aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDmitry Antipov2014-08-01 10:52:02 +0400
committerDmitry Antipov2014-08-01 10:52:02 +0400
commit11804a04ada37cbf33576a5a69189bd43b3d66dd (patch)
tree2821b4e9dc8e5af953dae668d1229ab080e1dbab /src
parentbc1ce1df863ffd32d1290b448591f8897029b10b (diff)
downloademacs-11804a04ada37cbf33576a5a69189bd43b3d66dd.tar.gz
emacs-11804a04ada37cbf33576a5a69189bd43b3d66dd.zip
* 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.
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog8
-rw-r--r--src/atimer.c27
2 files changed, 29 insertions, 6 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 9dbd7c97a53..a0ac451f35b 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,11 @@
12014-08-01 Dmitry Antipov <dmantipov@yandex.ru>
2
3 * atimer.c (toplevel) [HAVE_TIMERFD]: Include errno.h.
4 (timerfd_callback): Ignore weird events with no data. Add tight
5 assertions and comments.
6 (init_atimer) [HAVE_TIMERFD]: Add environment variable to optionally
7 disable timerfd-based timer. Use TFD_NONBLOCK for timer descriptor.
8
12014-08-01 Paul Eggert <eggert@cs.ucla.edu> 92014-08-01 Paul Eggert <eggert@cs.ucla.edu>
2 10
3 * frame.c (x_set_frame_parameters): Fix typo in previous patch. 11 * frame.c (x_set_frame_parameters): Fix typo in previous patch.
diff --git a/src/atimer.c b/src/atimer.c
index daac32f19b4..ce782f6adb6 100644
--- a/src/atimer.c
+++ b/src/atimer.c
@@ -27,6 +27,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
27#include <unistd.h> 27#include <unistd.h>
28 28
29#ifdef HAVE_TIMERFD 29#ifdef HAVE_TIMERFD
30#include <errno.h>
30# include <sys/timerfd.h> 31# include <sys/timerfd.h>
31#endif 32#endif
32 33
@@ -399,14 +400,26 @@ handle_alarm_signal (int sig)
399void 400void
400timerfd_callback (int fd, void *arg) 401timerfd_callback (int fd, void *arg)
401{ 402{
402 char buf[8];
403 ptrdiff_t nbytes; 403 ptrdiff_t nbytes;
404 uint64_t expirations;
404 405
405 eassert (fd == timerfd); 406 eassert (fd == timerfd);
406 nbytes = emacs_read (fd, buf, sizeof (buf)); 407 nbytes = emacs_read (fd, &expirations, sizeof (expirations));
407 /* Just discard an expiration count for now. */ 408
408 eassert (nbytes == sizeof (buf)); 409 if (nbytes == sizeof (expirations))
409 do_pending_atimers (); 410 {
411 /* Timer should expire just once. */
412 eassert (expirations == 1);
413 do_pending_atimers ();
414 }
415 else if (nbytes < 0)
416 /* For some not yet known reason, we may get weird event and no
417 data on timer descriptor. This can break Gnus at least, see:
418 http://lists.gnu.org/archive/html/emacs-devel/2014-07/msg00503.html. */
419 eassert (errno == EAGAIN);
420 else
421 /* I don't know what else can happen with this descriptor. */
422 emacs_abort ();
410} 423}
411 424
412#endif /* HAVE_TIMERFD */ 425#endif /* HAVE_TIMERFD */
@@ -528,7 +541,9 @@ init_atimer (void)
528{ 541{
529#ifdef HAVE_ITIMERSPEC 542#ifdef HAVE_ITIMERSPEC
530# ifdef HAVE_TIMERFD 543# ifdef HAVE_TIMERFD
531 timerfd = timerfd_create (CLOCK_REALTIME, TFD_CLOEXEC); 544 /* Until this feature is considered stable, you can ask to not use it. */
545 timerfd = (egetenv ("EMACS_IGNORE_TIMERFD") ? -1 :
546 timerfd_create (CLOCK_REALTIME, TFD_NONBLOCK | TFD_CLOEXEC));
532# endif 547# endif
533 if (timerfd < 0) 548 if (timerfd < 0)
534 { 549 {