From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Ian Kelling Newsgroups: gmane.emacs.bugs Subject: bug#20978: [PATCH 5/7] : Refactor timeouts in wait_reading_process_output Date: Sat, 04 Jul 2015 05:45:41 -0700 Message-ID: <87zj3chz0q.fsf@iankelling.org> References: <87zj3ckso6.fsf@iankelling.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1436013983 10779 80.91.229.3 (4 Jul 2015 12:46:23 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 4 Jul 2015 12:46:23 +0000 (UTC) To: 20978@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sat Jul 04 14:46:13 2015 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 1ZBMpf-0007mz-Ip for geb-bug-gnu-emacs@m.gmane.org; Sat, 04 Jul 2015 14:46:11 +0200 Original-Received: from localhost ([::1]:44192 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZBMpe-0005Uz-Ss for geb-bug-gnu-emacs@m.gmane.org; Sat, 04 Jul 2015 08:46:10 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:34642) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZBMpb-0005UY-DV for bug-gnu-emacs@gnu.org; Sat, 04 Jul 2015 08:46:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZBMpW-0000jf-A7 for bug-gnu-emacs@gnu.org; Sat, 04 Jul 2015 08:46:07 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:37924) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZBMpW-0000jM-5n for bug-gnu-emacs@gnu.org; Sat, 04 Jul 2015 08:46:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1ZBMpV-0002KF-Re for bug-gnu-emacs@gnu.org; Sat, 04 Jul 2015 08:46:01 -0400 X-Loop: help-debbugs@gnu.org In-Reply-To: <87zj3ckso6.fsf@iankelling.org> Resent-From: Ian Kelling Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 04 Jul 2015 12:46:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 20978 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 20978-submit@debbugs.gnu.org id=B20978.14360139538915 (code B ref 20978); Sat, 04 Jul 2015 12:46:01 +0000 Original-Received: (at 20978) by debbugs.gnu.org; 4 Jul 2015 12:45:53 +0000 Original-Received: from localhost ([127.0.0.1]:39370 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZBMpL-0002Ji-Jd for submit@debbugs.gnu.org; Sat, 04 Jul 2015 08:45:52 -0400 Original-Received: from out5-smtp.messagingengine.com ([66.111.4.29]:59099) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZBMpH-0002JW-Uf for 20978@debbugs.gnu.org; Sat, 04 Jul 2015 08:45:49 -0400 Original-Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id 8EAA121162; Sat, 4 Jul 2015 08:45:47 -0400 (EDT) Original-Received: from frontend2 ([10.202.2.161]) by compute3.internal (MEProxy); Sat, 04 Jul 2015 08:45:47 -0400 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=iankelling.org; h= content-type:date:from:message-id:mime-version:subject:to :x-sasl-enc:x-sasl-enc; s=mesmtp; bh=S+fEN6nckhN0x+IXatjQCTdJSls =; b=CdY8LVNJjYF6/ISRO5ozpVBfgJjh/1JTkg3jIW88VBDNy8HXgy3Z6ZBN2wK nDWLavgxmUPTFwCuH3HyTzKYTt9MJkMn9fNh8FfkhQ0tecPQwedLO3il9GR6XyiK jvlGVcReqpLaqf+Ni9SAwQbO9BXeoDhymzPuynNUmEb49EDc= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=content-type:date:from:message-id :mime-version:subject:to:x-sasl-enc:x-sasl-enc; s=smtpout; bh=S+ fEN6nckhN0x+IXatjQCTdJSls=; b=Bbe22en0tMDZhV7GVH9AGJsRnGUrzGNO8a A12g5bhOXfKU/GuniOfsEd7R5FlXKrIcyF2SZan81KXrPrldmR6HwGTi3SYZuIvL TScN5Cr69HQhJj4Zu65JZkoqVd/uq8DBoCE4mlA6GB8Z/4XSTHP3g5GRTM+EzvqE jqBCRCNuQ= X-Sasl-enc: riZDJIcO6qqwFVLjLaDXqNGGhV9k2lNVqYm7d/Z/OCtM 1436013947 Original-Received: from treetowl.lan (c-73-53-70-213.hsd1.wa.comcast.net [73.53.70.213]) by mail.messagingengine.com (Postfix) with ESMTPA id 383B268014C for <20978@debbugs.gnu.org>; Sat, 4 Jul 2015 08:45:47 -0400 (EDT) Original-Received: by treetowl.lan (Postfix, from userid 1000) id 446381FE26; Sat, 4 Jul 2015 05:45:41 -0700 (PDT) User-Agent: Gnus/5.130012 (Ma Gnus v0.12) Emacs/25.0.50 (gnu/linux) 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 3.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:104687 Archived-At: * src/process.c (wait_reading_process_output): Simplify timeouts with an enum. Remove a redundant condition. diff --git a/src/process.c b/src/process.c index 68a815f..538455c 100644 --- a/src/process.c +++ b/src/process.c @@ -4586,6 +4586,7 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, int xerrno; Lisp_Object proc; struct timespec timeout, end_time; + enum { MINIMUM, TIMEOUT, INFINITY } wait; int got_some_output = -1; ptrdiff_t count = SPECPDL_INDEX (); @@ -4601,21 +4602,19 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, waiting_for_user_input_p); waiting_for_user_input_p = read_kbd; - if (time_limit < 0) - { - time_limit = 0; - nsecs = -1; - } - else if (TYPE_MAXIMUM (time_t) < time_limit) + if (TYPE_MAXIMUM (time_t) < time_limit) time_limit = TYPE_MAXIMUM (time_t); - /* Since we may need to wait several times, - compute the absolute time to return at. */ - if (time_limit || nsecs > 0) + if (time_limit < 0 || nsecs < 0) + wait = MINIMUM; + else if (time_limit > 0 || nsecs > 0) { - timeout = make_timespec (time_limit, nsecs); - end_time = timespec_add (current_timespec (), timeout); + wait = TIMEOUT; + end_time = timespec_add (current_timespec (), + make_timespec (time_limit, nsecs)); } + else + wait = INFINITY; while (1) { @@ -4635,19 +4634,15 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, /* After reading input, vacuum up any leftovers without waiting. */ if (0 <= got_some_output) - nsecs = -1; + wait = MINIMUM; /* Compute time from now till when time limit is up. */ /* Exit if already run out. */ - if (nsecs < 0) + if (wait == MINIMUM) { - /* A negative timeout means - gobble output available now - but don't wait at all. */ - - timeout = make_timespec (0, 0); + timeout = make_timespec (0, 0); } - else if (time_limit || nsecs > 0) + else if (wait == TIMEOUT) { struct timespec now = current_timespec (); if (timespec_cmp (end_time, now) <= 0) @@ -4698,24 +4693,20 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, && requeued_events_pending_p ()) break; - /* A negative timeout means do not wait at all. */ - if (nsecs >= 0) - { - if (timespec_valid_p (timer_delay)) - { - if (timespec_cmp (timer_delay, timeout) < 0) - { - timeout = timer_delay; - timeout_reduced_for_timers = true; - } - } - else - { - /* This is so a breakpoint can be put here. */ - wait_reading_process_output_1 (); - } - } - } + if (timespec_valid_p (timer_delay)) + { + if (timespec_cmp (timer_delay, timeout) < 0) + { + timeout = timer_delay; + timeout_reduced_for_timers = true; + } + } + else + { + /* This is so a breakpoint can be put here. */ + wait_reading_process_output_1 (); + } + } /* Cause C-g and alarm signals to take immediate action, and cause input available signals to zero out timeout. @@ -4964,7 +4955,7 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, /* If we woke up due to SIGWINCH, actually change size now. */ do_pending_window_change (0); - if ((time_limit || nsecs) && nfds == 0 && ! timeout_reduced_for_timers) + if (wait != INFINITY && nfds == 0 && ! timeout_reduced_for_timers) /* We waited the full specified time, so return now. */ break; if (nfds < 0) @@ -6953,21 +6944,21 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, { register int nfds; struct timespec end_time, timeout; + enum { MINIMUM, TIMEOUT, INFINITY } wait; - if (time_limit < 0) - { - time_limit = 0; - nsecs = -1; - } - else if (TYPE_MAXIMUM (time_t) < time_limit) + if (TYPE_MAXIMUM (time_t) < time_limit) time_limit = TYPE_MAXIMUM (time_t); - /* What does time_limit really mean? */ - if (time_limit || nsecs > 0) + if (time_limit < 0 || nsecs < 0) + wait = MINIMUM; + else if (time_limit > 0 || nsecs > 0) { - timeout = make_timespec (time_limit, nsecs); - end_time = timespec_add (current_timespec (), timeout); + wait = TIMEOUT; + end_time = timespec_add (current_timespec (), + make_timespec (time_limit, nsecs)); } + else + wait = INFINITY; /* Turn off periodic alarms (in case they are in use) and then turn off any other atimers, @@ -6993,15 +6984,11 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, /* Compute time from now till when time limit is up. */ /* Exit if already run out. */ - if (nsecs < 0) + if (wait == MINIMUM) { - /* A negative timeout means - gobble output available now - but don't wait at all. */ - - timeout = make_timespec (0, 0); + timeout = make_timespec (0, 0); } - else if (time_limit || nsecs > 0) + else if (wait == TIMEOUT) { struct timespec now = current_timespec (); if (timespec_cmp (end_time, now) <= 0) @@ -7039,7 +7026,7 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, && requeued_events_pending_p ()) break; - if (timespec_valid_p (timer_delay) && nsecs >= 0) + if (timespec_valid_p (timer_delay)) { if (timespec_cmp (timer_delay, timeout) < 0) { @@ -7083,7 +7070,7 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, /* If we woke up due to SIGWINCH, actually change size now. */ do_pending_window_change (0); - if ((time_limit || nsecs) && nfds == 0 && ! timeout_reduced_for_timers) + if (wait != INFINITY && nfds == 0 && ! timeout_reduced_for_timers) /* We waited the full specified time, so return now. */ break; -- 2.4.5