bug-gnu-emacs
[Top][All Lists]
Advanced

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

bug#10404: [PATCH] Power: sleep longer than two seconds at a time


From: Daniel Colascione
Subject: bug#10404: [PATCH] Power: sleep longer than two seconds at a time
Date: Thu, 29 Dec 2011 15:40:09 -0800

Emacs uses an atimer to poll for input every so often so it can detect
C-g presses while lisp code is running; atimer arranges for this polling
to be done by having a SIGALRM delivered every so often --- by default,
every two seconds.  But while lisp code is not running and emacs is
blocked in select() [or a platform-specific analogue], we want to
stop this polling to save power: we don't need it because the select
will return as soon as there's input.

Emacs has code that's meant to turn off atimers while we wait for
input --- wait_reading_process_output calls stop_polling and
turn_on_atimers (0).  But time ago, we started calling redisplay
code inside the select loop, and this select code turns atimers
back on.  The effect is that we don't sleep longer than two second
at a time.

This patch turns off SIGALRM delivery around select, making sure that
we stay asleep.  With this patch (and blink-cursor-mode off), Emacs
will process input, then sleep for 30 seconds, and if no input
arrives in that time, will sleep for several hours.  The patch
does not adversely any functionality.
---
 src/process.c |   16 ++++++++++++++++
 1 files changed, 16 insertions(+), 0 deletions(-)

diff --git a/src/process.c b/src/process.c
index 5c8eef7..f81a5c4 100644
--- a/src/process.c
+++ b/src/process.c
@@ -4304,6 +4304,10 @@ wait_reading_process_output (int time_limit, int 
microsecs, int read_kbd,
   int got_some_input = 0;
   int count = SPECPDL_INDEX ();
 
+#ifdef SIGALRM
+  SIGMASKTYPE mask;
+#endif /* SIGALRM */
+
   FD_ZERO (&Available);
   FD_ZERO (&Writeok);
 
@@ -4606,6 +4610,14 @@ wait_reading_process_output (int time_limit, int 
microsecs, int read_kbd,
            }
 #endif
 
+#ifdef SIGALRM
+          /* We don't want SIGALRM going off while we're blocked in
+             select.  If there any any pending timers, timeout has
+             been set appropriately already and we'll wake up
+             automatically.  */
+          mask = sigblock (sigmask (SIGALRM));
+#endif /* SIGALRM */
+
 #if defined (USE_GTK) || defined (HAVE_GCONF) || defined (HAVE_GSETTINGS)
           nfds = xg_select
 #elif defined (HAVE_NS)
@@ -4618,6 +4630,10 @@ wait_reading_process_output (int time_limit, int 
microsecs, int read_kbd,
              (check_write ? &Writeok : (SELECT_TYPE *)0),
              (SELECT_TYPE *)0, &timeout);
 
+#ifdef SIGALRM
+          sigsetmask (mask);
+#endif /* SIGALRM */
+
 #ifdef HAVE_GNUTLS
           /* GnuTLS buffers data internally.  In lowat mode it leaves
              some data in the TCP buffers so that select works, but
-- 
1.7.5.1






reply via email to

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