From patchwork Thu Jun 5 08:53:10 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Konstantin Serebryany X-Patchwork-Id: 356230 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 77139140093 for ; Thu, 5 Jun 2014 18:53:40 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-type; q=dns; s=default; b=cOpp L6Ph+ACNdYKeyPITeiRQ0eyQ8j9G5ujjHnvmc4TNwkN5szs7Lr19gyypGtK+z063 shT3RCMkTS3pEGodDQGhdC8G58LI/iXd/XmhpWy4tUdla0/XV8HIv30g8HNmsv02 /sfgJHce+vI6FS8LhHhVg0RMDE5iuuWUcAG+YrE= 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:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-type; s=default; bh=vLdnx0Qqfc d2LkYL7OSu/oOgxeM=; b=uR9PHxlcm7DJf2qNUZYg6J8T2Tq0Ho1OuIXZQxBVu5 F1aSFQ/gsGHl2nJ8LrodBRcfNiAMFUWmOxJ6A7/i1HMHAdoVvsu9YrZNGoV1yS5j eKoCNTOYpwfq8RTNrkWtpEN9oCX3DCt7fWqV+zF5gpNvHj4KGR3xrg1m18agcdSc k= Received: (qmail 30915 invoked by alias); 5 Jun 2014 08:53:35 -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 30902 invoked by uid 89); 5 Jun 2014 08:53:34 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.1 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-qg0-f50.google.com X-Received: by 10.224.163.8 with SMTP id y8mr15144563qax.46.1401958410536; Thu, 05 Jun 2014 01:53:30 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <20140604171623.362652C39B4@topped-with-meat.com> References: <20140604171623.362652C39B4@topped-with-meat.com> From: Konstantin Serebryany Date: Thu, 5 Jun 2014 12:53:10 +0400 Message-ID: Subject: Re: [PATCH] remove one nested function from nptl/allocatestack.c To: Roland McGrath Cc: GNU C Library Bool is easy, done. (I did not realize that this code uses bool. Great!) Comments are harder -- I do not feel comfortable re-commenting someone else's code. Do you have a suggestion? On Wed, Jun 4, 2014 at 9:16 PM, Roland McGrath wrote: > That is fine, though it wouldn't hurt to improve the commentary and use > bool while you're there. diff --git a/nptl/allocatestack.c b/nptl/allocatestack.c index 1e22f7d..359c444 100644 --- a/nptl/allocatestack.c +++ b/nptl/allocatestack.c @@ -809,6 +809,24 @@ __make_stacks_executable (void **stack_endp) return err; } +/* We always add at the beginning of the list. So in this + case we only need to check the beginning of these lists. */ +static bool +check_list (list_t *l, list_t *elem) +{ + if (l->next->prev != l) + { + assert (l->next->prev == elem); + + elem->next = l->next; + elem->prev = l; + l->next = elem; + + return true; + } + + return false; +} /* In case of a fork() call the memory allocation in the child will be the same but only one thread is running. All stacks except that of @@ -830,26 +848,8 @@ __reclaim_stacks (void) if (add_p) { - /* We always add at the beginning of the list. So in this - case we only need to check the beginning of these lists. */ - int check_list (list_t *l) - { - if (l->next->prev != l) - { - assert (l->next->prev == elem); - - elem->next = l->next; - elem->prev = l; - l->next = elem; - - return 1; - } - - return 0; - } - - if (check_list (&stack_used) == 0) - (void) check_list (&stack_cache); + if (!check_list (&stack_used, elem)) + (void) check_list (&stack_cache, elem); } else {