From patchwork Fri May 3 10:06:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 1094770 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-101725-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="AIr17ndR"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44wSTJ2cpfz9s9y for ; Fri, 3 May 2019 20:06:28 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id:mime-version :content-type; q=dns; s=default; b=ygV5NFbhzM9Zj00UqxK0bUNOy/avJ jrmZpcDZiHHbLDN1RCHtfkdss7KK/2Oy12BRcl089dOFlUz47fxc9o4hIgGE9ITv 5Pr1J0IkjtTLxwX90YTE4vFPrprPbO6udAD4OlYkzz/hge9k+G+24NyYbNLNf2x/ zw7wQqY9TwptlY= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id:mime-version :content-type; s=default; bh=k1V7czXj1S6Gqtq8wHsDehZN9IE=; b=AIr 17ndRmMm/r5KHcLMf1hn4XaIWb1yreIv73PWh/O7bIBeNUaUtOX2te7zhlAUZ+og /lig7fAg0lt8TlvnWoq5VY5oBgvhogahZk6Zxn4Qd9GXoAESXcHdz2nPvB24fWSy j8uDb/ljx0MrC0ksYBf8BFUa93iSJFBLzDJMNA1w= Received: (qmail 92920 invoked by alias); 3 May 2019 10:06:22 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 92912 invoked by uid 89); 3 May 2019 10:06:22 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-19.0 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_PASS autolearn=ham version=3.3.1 spammy=visit X-HELO: mx1.redhat.com From: Florian Weimer To: libc-alpha@sourceware.org Subject: [PATCH] sem_close: Use __twalk_r Date: Fri, 03 May 2019 12:06:17 +0200 Message-ID: <8736lvua1y.fsf@oldenburg2.str.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 (Adhemerval, you said you wanted to rewrite this, but this cleanup patch is simple enough so that we can apply it nevertheless, I think.) 2019-05-03 Florian Weimer * nptl/sem_close.c (struct walk_closure): Define. (walker): Adjust for __twalk_r. (sem_close): Call __twalk_r. Reviewed-by: Adhemerval Zanella diff --git a/nptl/sem_close.c b/nptl/sem_close.c index b8828cba06..8941f111f9 100644 --- a/nptl/sem_close.c +++ b/nptl/sem_close.c @@ -21,21 +21,20 @@ #include #include "semaphoreP.h" - -/* Global variables to parametrize the walk function. This works - since we always have to use locks. And we have to use the twalk - function since the entries are not sorted wrt the mapping - address. */ -static sem_t *the_sem; -static struct inuse_sem *rec; +struct walk_closure +{ + sem_t *the_sem; + struct inuse_sem *rec; +}; static void -walker (const void *inodep, const VISIT which, const int depth) +walker (const void *inodep, VISIT which, void *closure0) { + struct walk_closure *closure = closure0; struct inuse_sem *nodep = *(struct inuse_sem **) inodep; - if (nodep->sem == the_sem) - rec = nodep; + if (nodep->sem == closure->the_sem) + closure->rec = nodep; } @@ -48,9 +47,12 @@ sem_close (sem_t *sem) lll_lock (__sem_mappings_lock, LLL_PRIVATE); /* Locate the entry for the mapping the caller provided. */ - rec = NULL; - the_sem = sem; - __twalk (__sem_mappings, walker); + struct inuse_sem *rec; + { + struct walk_closure closure = { .the_sem = sem, .rec = NULL }; + __twalk_r (__sem_mappings, walker, &closure); + rec = closure.rec; + } if (rec != NULL) { /* Check the reference counter. If it is going to be zero, free