From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Daniel Colascione Newsgroups: gmane.emacs.bugs Subject: bug#10404: [PATCH] Power: sleep longer than two seconds at a time Date: Thu, 29 Dec 2011 15:40:09 -0800 Message-ID: NNTP-Posting-Host: lo.gmane.org X-Trace: dough.gmane.org 1325202081 4750 80.91.229.12 (29 Dec 2011 23:41:21 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Thu, 29 Dec 2011 23:41:21 +0000 (UTC) To: 10404@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Fri Dec 30 00:41:16 2011 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([140.186.70.17]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1RgPb1-0002Cm-He for geb-bug-gnu-emacs@m.gmane.org; Fri, 30 Dec 2011 00:41:15 +0100 Original-Received: from localhost ([::1]:47903 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RgPb1-0003lI-2u for geb-bug-gnu-emacs@m.gmane.org; Thu, 29 Dec 2011 18:41:15 -0500 Original-Received: from eggs.gnu.org ([140.186.70.92]:43649) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RgPay-0003lD-56 for bug-gnu-emacs@gnu.org; Thu, 29 Dec 2011 18:41:13 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RgPax-0007Ab-4R for bug-gnu-emacs@gnu.org; Thu, 29 Dec 2011 18:41:12 -0500 Original-Received: from debbugs.gnu.org ([140.186.70.43]:58102) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RgPax-0007AU-1X for bug-gnu-emacs@gnu.org; Thu, 29 Dec 2011 18:41:11 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.69) (envelope-from ) id 1RgPdi-00089u-VD for bug-gnu-emacs@gnu.org; Thu, 29 Dec 2011 18:44:03 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Daniel Colascione Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 29 Dec 2011 23:44:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 10404 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.132520219331298 (code B ref -1); Thu, 29 Dec 2011 23:44:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 29 Dec 2011 23:43:13 +0000 Original-Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1RgPct-00088i-R2 for submit@debbugs.gnu.org; Thu, 29 Dec 2011 18:43:13 -0500 Original-Received: from eggs.gnu.org ([140.186.70.92]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1RgPco-00088T-91 for submit@debbugs.gnu.org; Thu, 29 Dec 2011 18:43:08 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RgPa0-00074Y-Tq for submit@debbugs.gnu.org; Thu, 29 Dec 2011 18:40:13 -0500 Original-Received: from lists.gnu.org ([140.186.70.17]:48394) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RgPa0-00074U-SK for submit@debbugs.gnu.org; Thu, 29 Dec 2011 18:40:12 -0500 Original-Received: from eggs.gnu.org ([140.186.70.92]:43538) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RgPZz-0003k8-TL for bug-gnu-emacs@gnu.org; Thu, 29 Dec 2011 18:40:12 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RgPZy-00074B-MZ for bug-gnu-emacs@gnu.org; Thu, 29 Dec 2011 18:40:11 -0500 Original-Received: from dancol.org ([96.126.100.184]:34802) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RgPZy-00073o-Ef for bug-gnu-emacs@gnu.org; Thu, 29 Dec 2011 18:40:10 -0500 Original-Received: from dancol by dancol.org with local (Exim 4.72) (envelope-from ) id 1RgPZx-0008S8-CU for bug-gnu-emacs@gnu.org; Thu, 29 Dec 2011 15:40:09 -0800 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list Resent-Date: Thu, 29 Dec 2011 18:44:02 -0500 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) 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:55290 Archived-At: 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