unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#10404: [PATCH] Power: sleep longer than two seconds at a time
@ 2011-12-29 23:40 Daniel Colascione
  2013-06-12 17:25 ` Glenn Morris
  0 siblings, 1 reply; 8+ messages in thread
From: Daniel Colascione @ 2011-12-29 23:40 UTC (permalink / raw)
  To: 10404

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






^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2019-06-27 15:46 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-12-29 23:40 bug#10404: [PATCH] Power: sleep longer than two seconds at a time Daniel Colascione
2013-06-12 17:25 ` Glenn Morris
2013-06-12 18:14   ` Eli Zaretskii
2013-07-20 19:46     ` Glenn Morris
2016-02-25  6:20       ` Lars Ingebrigtsen
2016-12-13  1:18         ` Glenn Morris
2016-12-13 23:43           ` Lars Ingebrigtsen
2019-06-27 15:46             ` Lars Ingebrigtsen

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).