From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Glenn Morris Newsgroups: gmane.emacs.bugs Subject: bug#10404: [PATCH] Power: sleep longer than two seconds at a time Date: Wed, 12 Jun 2013 13:25:57 -0400 Message-ID: References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1371058032 11757 80.91.229.3 (12 Jun 2013 17:27:12 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 12 Jun 2013 17:27:12 +0000 (UTC) To: 10404@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed Jun 12 19:27:12 2013 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1UmopC-0003sY-Vy for geb-bug-gnu-emacs@m.gmane.org; Wed, 12 Jun 2013 19:27:11 +0200 Original-Received: from localhost ([::1]:50980 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UmopC-0007W4-JE for geb-bug-gnu-emacs@m.gmane.org; Wed, 12 Jun 2013 13:27:10 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:58918) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Umop7-0007UI-7o for bug-gnu-emacs@gnu.org; Wed, 12 Jun 2013 13:27:06 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Umop4-0000MP-QM for bug-gnu-emacs@gnu.org; Wed, 12 Jun 2013 13:27:05 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:54938) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Umop4-0000LM-Me for bug-gnu-emacs@gnu.org; Wed, 12 Jun 2013 13:27:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1Umop4-0008JW-Ce for bug-gnu-emacs@gnu.org; Wed, 12 Jun 2013 13:27:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Glenn Morris Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 12 Jun 2013 17:27:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 10404 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 10404-submit@debbugs.gnu.org id=B10404.137105796131848 (code B ref 10404); Wed, 12 Jun 2013 17:27:02 +0000 Original-Received: (at 10404) by debbugs.gnu.org; 12 Jun 2013 17:26:01 +0000 Original-Received: from localhost ([127.0.0.1]:59173 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Umoo5-0008HZ-4h for submit@debbugs.gnu.org; Wed, 12 Jun 2013 13:26:01 -0400 Original-Received: from fencepost.gnu.org ([208.118.235.10]:45901 ident=Debian-exim) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Umoo3-0008HN-Ej for 10404@debbugs.gnu.org; Wed, 12 Jun 2013 13:25:59 -0400 Original-Received: from rgm by fencepost.gnu.org with local (Exim 4.71) (envelope-from ) id 1Umoo2-0006eL-AJ; Wed, 12 Jun 2013 13:25:58 -0400 X-Spook: SWAT kibo target South Africa Craig Livingstone embassy X-Ran: k#Zb-(G)8[p),0V2~_Kt74&`u"}vh&daK?dN2Z}UW\`_[h{'m>YON%EB0SR:wPO<{pFBJB X-Hue: yellow X-Attribution: GM In-Reply-To: (Daniel Colascione's message of "Thu, 29 Dec 2011 15:40:09 -0800") User-Agent: Gnus (www.gnus.org), GNU Emacs (www.gnu.org/software/emacs/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:75016 Archived-At: This sounds like a good idea. Does anyone have any comments? Daniel Colascione wrote: > 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