From patchwork Mon Jun 29 08:12:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Thibault X-Patchwork-Id: 39825 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id AA4EB388F07C; Mon, 29 Jun 2020 10:40:19 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from hera.aquilenet.fr (hera.aquilenet.fr [IPv6:2a0c:e300::1]) by sourceware.org (Postfix) with ESMTPS id 20212386EC42 for ; Mon, 29 Jun 2020 10:40:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 20212386EC42 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=ens-lyon.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=samuel.thibault@ens-lyon.org Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id 13BF61A3B; Mon, 29 Jun 2020 10:12:26 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at aquilenet.fr Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Prs4ohob4CQM; Mon, 29 Jun 2020 10:12:25 +0200 (CEST) Received: from function (lfbn-bor-1-797-11.w86-234.abo.wanadoo.fr [86.234.239.11]) by hera.aquilenet.fr (Postfix) with ESMTPSA id 3A1B517D3; Mon, 29 Jun 2020 10:12:25 +0200 (CEST) Received: from samy by function with local (Exim 4.94) (envelope-from ) id 1jpotr-003sSM-Hn; Mon, 29 Jun 2020 10:12:23 +0200 From: Samuel Thibault To: libc-alpha@sourceware.org Subject: [hurd,commited] hurd: Simplify usleep timeout computation Date: Mon, 29 Jun 2020 10:12:22 +0200 Message-Id: <20200629081222.924273-1-samuel.thibault@ens-lyon.org> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 X-Spam-Status: No, score=-10.8 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_NEUTRAL, TXREP autolearn=unavailable autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: commit-hurd@gnu.org Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" as suggested by Andreas Schwab * sysdeps/mach/usleep.c (usleep): Divide timeout in an overflow-safe way. --- sysdeps/mach/usleep.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/sysdeps/mach/usleep.c b/sysdeps/mach/usleep.c index 75514b2e35..bb989e2733 100644 --- a/sysdeps/mach/usleep.c +++ b/sysdeps/mach/usleep.c @@ -27,16 +27,13 @@ usleep (useconds_t useconds) { mach_port_t recv; int cancel_oldtype; - useconds_t useconds_up = useconds + 999; - - if (useconds_up < useconds) - useconds_up = UINT32_MAX; + mach_msg_timeout_t timeout = useconds / 1000 + (useconds % 1000 != 0); recv = __mach_reply_port (); cancel_oldtype = LIBC_CANCEL_ASYNC(); (void) __mach_msg (NULL, MACH_RCV_MSG|MACH_RCV_TIMEOUT|MACH_RCV_INTERRUPT, - 0, 0, recv, useconds_up / 1000, MACH_PORT_NULL); + 0, 0, recv, timeout, MACH_PORT_NULL); LIBC_CANCEL_RESET (cancel_oldtype); __mach_port_destroy (mach_task_self (), recv);