From 4107549a614a9977cdec4cb7a1d5eaec72a3380f Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Wed, 27 Oct 2021 14:58:08 +0200 Subject: Always start the SIGALRM atimers * src/atimer.c (init_atimer): Always start the SIGALRM alarms, even if we're using timerfd (bug#19776). See long, long discussion in the bug report for why this is necessary. --- src/atimer.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'src/atimer.c') diff --git a/src/atimer.c b/src/atimer.c index 9b198675ab4..802f3c6a596 100644 --- a/src/atimer.c +++ b/src/atimer.c @@ -583,15 +583,16 @@ init_atimer (void) timerfd = (egetenv ("EMACS_IGNORE_TIMERFD") || have_buggy_timerfd () ? -1 : timerfd_create (CLOCK_REALTIME, TFD_NONBLOCK | TFD_CLOEXEC)); # endif - if (timerfd < 0) - { - 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; - } + /* We're starting the alarms even if we have timerfd, because + timerfd events do not fired while Emacs Lisp is busy. This might + or might not mean that the timerfd code doesn't really give us + anything and should be removed, see discussion in bug#19776. */ + 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; -- cgit v1.2.3 From 65cd2d90b7a894c184f45bfff52b7c6200ebc639 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Wed, 27 Oct 2021 16:14:55 +0300 Subject: ; * src/atimer.c (init_atimer): Fix a typo in a comment. --- src/atimer.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/atimer.c') diff --git a/src/atimer.c b/src/atimer.c index 802f3c6a596..ab47bbf9688 100644 --- a/src/atimer.c +++ b/src/atimer.c @@ -584,9 +584,10 @@ init_atimer (void) timerfd_create (CLOCK_REALTIME, TFD_NONBLOCK | TFD_CLOEXEC)); # endif /* We're starting the alarms even if we have timerfd, because - timerfd events do not fired while Emacs Lisp is busy. This might - or might not mean that the timerfd code doesn't really give us - anything and should be removed, see discussion in bug#19776. */ + timerfd events do not fire while Emacs Lisp is busy and doesn't + call thread_select. This might or might not mean that the + timerfd code doesn't really give us anything and should be + removed, see discussion in bug#19776. */ struct sigevent sigev; sigev.sigev_notify = SIGEV_SIGNAL; sigev.sigev_signo = SIGALRM; -- cgit v1.2.3 From 858868e36dbb8fe30fb5ae6a59ebb2fd123e307d Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Sun, 7 Nov 2021 04:55:02 +0100 Subject: Actually start the alarms in atimer * src/atimer.c (set_alarm): Actually start both timerfd and alarms (attempted in 4107549a). --- src/atimer.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src/atimer.c') diff --git a/src/atimer.c b/src/atimer.c index ab47bbf9688..490c21bff16 100644 --- a/src/atimer.c +++ b/src/atimer.c @@ -305,6 +305,7 @@ set_alarm (void) #ifdef HAVE_ITIMERSPEC if (0 <= timerfd || alarm_timer_ok) { + bool exit = false; struct itimerspec ispec; ispec.it_value = atimers->expiration; ispec.it_interval.tv_sec = ispec.it_interval.tv_nsec = 0; @@ -312,11 +313,14 @@ set_alarm (void) if (timerfd_settime (timerfd, TFD_TIMER_ABSTIME, &ispec, 0) == 0) { add_timer_wait_descriptor (timerfd); - return; + exit = true; } # endif if (alarm_timer_ok && timer_settime (alarm_timer, TIMER_ABSTIME, &ispec, 0) == 0) + exit = true; + + if (exit) return; } #endif @@ -333,9 +337,8 @@ set_alarm (void) memset (&it, 0, sizeof it); it.it_value = make_timeval (interval); setitimer (ITIMER_REAL, &it, 0); -#else /* not HAVE_SETITIMER */ - alarm (max (interval.tv_sec, 1)); #endif /* not HAVE_SETITIMER */ + alarm (max (interval.tv_sec, 1)); } } -- cgit v1.2.3