unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Daniel Colascione <dancol@dancol.org>
To: 10404@debbugs.gnu.org
Subject: bug#10404: [PATCH] Power: sleep longer than two seconds at a time
Date: Thu, 29 Dec 2011 15:40:09 -0800	[thread overview]
Message-ID: <E1RgPZx-0008S8-CU@dancol.org> (raw)

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	other threads:[~2011-12-29 23:40 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-29 23:40 Daniel Colascione [this message]
2013-06-12 17:25 ` bug#10404: [PATCH] Power: sleep longer than two seconds at a time 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=E1RgPZx-0008S8-CU@dancol.org \
    --to=dancol@dancol.org \
    --cc=10404@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).