From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS22989 209.51.188.0/24 X-Spam-Status: No, score=-5.3 required=3.0 tests=AWL,BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id B01831F5A2 for ; Mon, 10 Feb 2020 14:54:32 +0000 (UTC) Received: from localhost ([::1]:34694 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j1ASF-0002YR-Sz for normalperson@yhbt.net; Mon, 10 Feb 2020 09:54:31 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:40356) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j188q-0002Lh-TD for bug-gnulib@gnu.org; Mon, 10 Feb 2020 07:26:21 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j188p-0004j8-Rk for bug-gnulib@gnu.org; Mon, 10 Feb 2020 07:26:20 -0500 Received: from mail-wm1-f68.google.com ([209.85.128.68]:35784) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1j188p-0004ii-Lu for bug-gnulib@gnu.org; Mon, 10 Feb 2020 07:26:19 -0500 Received: by mail-wm1-f68.google.com with SMTP id b17so64048wmb.0 for ; Mon, 10 Feb 2020 04:26:19 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=irO3n8litJ714e1bGiul1wfvNkH85htKswQwiU9FtVs=; b=D6FW+t3F0Dx7EoOGwk8NVsGuYOmTjNg8jTYv9Hcn4FZsV48o1e+UzmLIojAjmXssPi 2ag5wYPCoX435MNus5WnQJVtMRU9EjFfL1EhdpqxzsBFCuPKk2ypeMOPLEmPuMWLBDLh ExqopmMBDbuZupheSx+LieDfP7TXGSF0Xa2vIZ7+dJcvcclNO0DioV66MZNHp8jJKsSO oGZcE6Zhz7wutOtrDobRJ+kSZrzx2pX2ReFBXYK8Ppp/70J6w0va1Jea2/W1SfE78lcH Zg91dYuuOZjErHknlY89MBYE8XTH4oi0wRxAf1t6xqY9R7OaU4jIoGIcY9fkgEx0itUD nCLQ== X-Gm-Message-State: APjAAAWk7AOUxx85efcpX2VZJGOf6m1dskOvfI1Qq9Kpl/o+HqDe+URi IT7XiC+KfmHFNinhlcnpq/9ekel84a0= X-Google-Smtp-Source: APXvYqyo+ht3LwUMVjR8goDx4OFeqBBPk1bc3yDqmfEoJ3ORGK1FZfFBpiU+QOX7MIx+eEGKVAxZpw== X-Received: by 2002:a05:600c:285:: with SMTP id 5mr15106016wmk.120.1581337578410; Mon, 10 Feb 2020 04:26:18 -0800 (PST) Received: from home.thecybershadow.net ([89.28.117.31]) by smtp.gmail.com with ESMTPSA id b18sm360740wru.50.2020.02.10.04.26.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Feb 2020 04:26:17 -0800 (PST) From: Vladimir Panteleev To: bug-gnulib@gnu.org Subject: [PATCH] xnanosleep: Use pause for infinite duration. Date: Mon, 10 Feb 2020 12:26:13 +0000 Message-Id: <20200210122613.397937-2-git@thecybershadow.net> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200210122613.397937-1-git@thecybershadow.net> References: <20200210122613.397937-1-git@thecybershadow.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.85.128.68 X-Mailman-Approved-At: Mon, 10 Feb 2020 09:53:43 -0500 X-BeenThere: bug-gnulib@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Gnulib discussion list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Vladimir Panteleev Errors-To: bug-gnulib-bounces+normalperson=yhbt.net@gnu.org Sender: "bug-gnulib" * lib/xnanosleep.c (xnanosleep): When the duration is the positive infinity, use pause instead of nanosleep. --- lib/xnanosleep.c | 42 ++++++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/lib/xnanosleep.c b/lib/xnanosleep.c index 5774f75f3..58a2f5254 100644 --- a/lib/xnanosleep.c +++ b/lib/xnanosleep.c @@ -25,7 +25,9 @@ #include #include +#include #include +#include /* Sleep until the time (call it WAKE_UP_TIME) specified as SECONDS seconds after the time this function is called. @@ -37,21 +39,33 @@ int xnanosleep (double seconds) { - struct timespec ts_sleep = dtotimespec (seconds); - - for (;;) + if (!isfinite(seconds) && seconds > 0) + { + for (;;) + { + pause(); + if (errno != EINTR) + return -1; + } + } + else { - /* Linux-2.6.8.1's nanosleep returns -1, but doesn't set errno - when resumed after being suspended. Earlier versions would - set errno to EINTR. nanosleep from linux-2.6.10, as well as - implementations by (all?) other vendors, doesn't return -1 - in that case; either it continues sleeping (if time remains) - or it returns zero (if the wake-up time has passed). */ - errno = 0; - if (nanosleep (&ts_sleep, NULL) == 0) - break; - if (errno != EINTR && errno != 0) - return -1; + struct timespec ts_sleep = dtotimespec (seconds); + + for (;;) + { + /* Linux-2.6.8.1's nanosleep returns -1, but doesn't set errno + when resumed after being suspended. Earlier versions would + set errno to EINTR. nanosleep from linux-2.6.10, as well as + implementations by (all?) other vendors, doesn't return -1 + in that case; either it continues sleeping (if time remains) + or it returns zero (if the wake-up time has passed). */ + errno = 0; + if (nanosleep (&ts_sleep, NULL) == 0) + break; + if (errno != EINTR && errno != 0) + return -1; + } } return 0; -- 2.25.0