From patchwork Mon Feb 4 10:05:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 1035783 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-99732-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="mWSVWpYj"; 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 43tNck2L8Yz9sCh for ; Mon, 4 Feb 2019 21:05:26 +1100 (AEDT) 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=KEKmy9FFaQLW5C7tNYB6XK58p2OT2 SHLwRuQb3YmduQP/voPIHHfDoylDaefY3UMYMc+eRHuvio+M2G18XAWaU4CUMj7U POGopdugvpSQHwxQ2GcygrjwPManpvF8Q5EbIc3r5yVt+qsl7k4eAVcna7GAnL2p iuI2o5r73VqRFc= 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=pOEGri/t/40QoKx2dd61BuypV34=; b=mWS VWpYjXEYj2Nk6b1Ca83F6fJYqfWHBXlq/qVpoHZIf/RHpoAKeWq3EnX5VOCrDxdH icwVdud8Oi661AYpsruCBzlBzzgFT4WMBp/z4W45dwE6w7/mKu6B/km76TiBkjRg SJtKkVYAViigfxlcauO/EcK2Vfvi4fnFtspAyFEk= Received: (qmail 44056 invoked by alias); 4 Feb 2019 10:05:20 -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 44042 invoked by uid 89); 4 Feb 2019 10:05:20 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=self, Our, our X-HELO: mx1.redhat.com From: Florian Weimer To: libc-alpha@sourceware.org Subject: [PATCH] nptl: Use C11-style atomics for access to __nptl_nthreads Date: Mon, 04 Feb 2019 11:05:16 +0100 Message-ID: <87pns7x40z.fsf@oldenburg2.str.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 2019-02-03 Florian Weimer * nptl/allocatestack.c (__reclaim_stacks): Use C-11-style atomic access for __nptl_nthreads. * nptl/pthread_create.c (__nptl_deallocate_tsd): Likewise. (START_THREAD_DEFN): Likewise. (__pthread_create_2_1): Likewise. diff --git a/nptl/allocatestack.c b/nptl/allocatestack.c index 670cb8ffe6..0dbb155f70 100644 --- a/nptl/allocatestack.c +++ b/nptl/allocatestack.c @@ -952,7 +952,7 @@ __reclaim_stacks (void) list_add (&self->list, &stack_used); /* There is one thread running. */ - __nptl_nthreads = 1; + atomic_store_relaxed (&__nptl_nthreads, 1); in_flight_stack = 0; diff --git a/nptl/pthread_create.c b/nptl/pthread_create.c index 04d1c6453e..15fbeceac7 100644 --- a/nptl/pthread_create.c +++ b/nptl/pthread_create.c @@ -341,7 +341,7 @@ __nptl_main_thread_exited (void) { __nptl_deallocate_tsd (); - if (! atomic_decrement_and_test (&__nptl_nthreads)) + if (atomic_fetch_add_relaxed (&__nptl_nthreads, -1) > 1) /* Exit the thread, but not the process. */ __exit_thread (); } @@ -510,7 +510,7 @@ START_THREAD_DEFN /* If this is the last thread we terminate the process now. We do not notify the debugger, it might just irritate it if there is no thread left. */ - if (__glibc_unlikely (atomic_decrement_and_test (&__nptl_nthreads))) + if (atomic_fetch_add_relaxed (&__nptl_nthreads, -1) == 1) /* This was the last thread. */ exit (0); @@ -769,7 +769,7 @@ __pthread_create_2_1 (pthread_t *newthread, const pthread_attr_t *attr, collect_default_sched (pd); } - if (__glibc_unlikely (__nptl_nthreads == 1)) + if (__glibc_unlikely (atomic_load_relaxed (&__nptl_nthreads) == 1)) _IO_enable_locks (); /* Pass the descriptor to the caller. */ @@ -785,7 +785,7 @@ __pthread_create_2_1 (pthread_t *newthread, const pthread_attr_t *attr, we momentarily store a false value; this doesn't matter because there is no kosher thing a signal handler interrupting us right here can do that cares whether the thread count is correct. */ - atomic_increment (&__nptl_nthreads); + atomic_fetch_add_relaxed (&__nptl_nthreads, 1); /* Our local value of stopped_start and thread_ran can be accessed at any time. The PD->stopped_start may only be accessed if we have @@ -850,7 +850,7 @@ __pthread_create_2_1 (pthread_t *newthread, const pthread_attr_t *attr, NOTES above). */ /* Oops, we lied for a second. */ - atomic_decrement (&__nptl_nthreads); + atomic_fetch_add_relaxed (&__nptl_nthreads, -1); /* Perhaps a thread wants to change the IDs and is waiting for this stillborn thread. */