From patchwork Tue Jun 23 23:20:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Thibault X-Patchwork-Id: 1315716 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=libc-alpha-bounces@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ens-lyon.org Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49s2MG2QKgz9sPF for ; Wed, 24 Jun 2020 09:20:42 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 52625393C8B0; Tue, 23 Jun 2020 23:20:37 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from hera.aquilenet.fr (hera.aquilenet.fr [185.233.100.1]) by sourceware.org (Postfix) with ESMTPS id 76B56386F457 for ; Tue, 23 Jun 2020 23:20:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 76B56386F457 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 6B094E154; Wed, 24 Jun 2020 01:20:33 +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 612twsf27PR7; Wed, 24 Jun 2020 01:20:32 +0200 (CEST) Received: from function (unknown [IPv6:2a01:cb19:956:1b00:9eb6:d0ff:fe88:c3c7]) by hera.aquilenet.fr (Postfix) with ESMTPSA id D551F4A51; Wed, 24 Jun 2020 01:20:31 +0200 (CEST) Received: from samy by function with local (Exim 4.94) (envelope-from ) id 1jnsDJ-009M2b-54; Wed, 24 Jun 2020 01:20:25 +0200 From: Samuel Thibault To: libc-alpha@sourceware.org Subject: [hurd, commited 1/2] htl: Simplify non-cancel path of __pthread_cond_timedwait_internal Date: Wed, 24 Jun 2020 01:20:23 +0200 Message-Id: <20200623232024.2229631-2-samuel.thibault@ens-lyon.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200623232024.2229631-1-samuel.thibault@ens-lyon.org> References: <20200623232024.2229631-1-samuel.thibault@ens-lyon.org> MIME-Version: 1.0 X-Spam-Status: No, score=-11.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_NEUTRAL, TXREP autolearn=ham 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" Since __pthread_exit does not return, we do not need to indent the noncancel path * sysdeps/htl/pt-cond-timedwait.c (__pthread_cond_timedwait_internal): Move cancelled path before non-cancelled path, to avoid "else" indentation. --- sysdeps/htl/pt-cond-timedwait.c | 41 +++++++++++++++++---------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/sysdeps/htl/pt-cond-timedwait.c b/sysdeps/htl/pt-cond-timedwait.c index c05944d16d..f7801b30ae 100644 --- a/sysdeps/htl/pt-cond-timedwait.c +++ b/sysdeps/htl/pt-cond-timedwait.c @@ -117,29 +117,30 @@ __pthread_cond_timedwait_internal (pthread_cond_t *cond, cancelled = (self->cancel_state == PTHREAD_CANCEL_ENABLE) && self->cancel_pending; - if (!cancelled) + if (cancelled) { - self->cancel_hook = cancel_hook; - self->cancel_hook_arg = &ctx; - oldtype = self->cancel_type; - - if (oldtype != PTHREAD_CANCEL_DEFERRED) - self->cancel_type = PTHREAD_CANCEL_DEFERRED; - - /* Add ourselves to the list of waiters. This is done while setting - the cancellation hook to simplify the cancellation procedure, i.e. - if the thread is queued, it can be cancelled, otherwise it is - already unblocked, progressing on the return path. */ - __pthread_spin_wait (&cond->__lock); - __pthread_enqueue (&cond->__queue, self); - if (cond->__attr != NULL && clockid == -1) - clock_id = cond->__attr->__clock; - __pthread_spin_unlock (&cond->__lock); + __pthread_mutex_unlock (&self->cancel_lock); + __pthread_exit (PTHREAD_CANCELED); } - __pthread_mutex_unlock (&self->cancel_lock); - if (cancelled) - __pthread_exit (PTHREAD_CANCELED); + self->cancel_hook = cancel_hook; + self->cancel_hook_arg = &ctx; + oldtype = self->cancel_type; + + if (oldtype != PTHREAD_CANCEL_DEFERRED) + self->cancel_type = PTHREAD_CANCEL_DEFERRED; + + /* Add ourselves to the list of waiters. This is done while setting + the cancellation hook to simplify the cancellation procedure, i.e. + if the thread is queued, it can be cancelled, otherwise it is + already unblocked, progressing on the return path. */ + __pthread_spin_wait (&cond->__lock); + __pthread_enqueue (&cond->__queue, self); + if (cond->__attr != NULL && clockid == -1) + clock_id = cond->__attr->__clock; + __pthread_spin_unlock (&cond->__lock); + + __pthread_mutex_unlock (&self->cancel_lock); /* Release MUTEX before blocking. */ __pthread_mutex_unlock (mutex);