From patchwork Thu Aug 30 10:48:34 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thiago Macieira X-Patchwork-Id: 180816 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]) by ozlabs.org (Postfix) with SMTP id 6A28B2C0201 for ; Thu, 30 Aug 2012 20:48:55 +1000 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1346928535; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: From:To:Subject:Date:Message-ID:User-Agent:MIME-Version: Content-Type:Content-Transfer-Encoding:Mailing-List:Precedence: List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender: Delivered-To; bh=DNyZGeHFJZ1Hohni+0kKyUIuTGc=; b=oSeaPaY5b7sUctM zFIg137BXI067wzxt/ZqHiMl6uobWyyV8StHx24BPyPCQjVqIUNMHfcTjnUdI6BP qA6Lr5ajMdHGsQv6DdHh3wsIpWkkGxAE/vIxFNp0eUtCJh+IEqCFL3CcE4J9kE27 ZgNUMQSlSOQCCg4uZVcIjCOEAU5s= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:X-ExtLoop1:Received:From:To:Subject:Date:Message-ID:User-Agent:MIME-Version:Content-Type:Content-Transfer-Encoding:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=UOqOQK082WtZZ1cZ/GafQEi+K9wVVJI5kFeQsddsWPkuuov98V9MFRkjUzfjO1 XBjRa65fyOADfR0ikqAlaJc9PfU6/LYbjeR6HuQAsRGEQrBG+obtrAskExt8A0cC pbsH70q0UYHJ5YA0FihpycSUUzLKlgJwuSYT2Ll155g4c=; Received: (qmail 31658 invoked by alias); 30 Aug 2012 10:48:50 -0000 Received: (qmail 31644 invoked by uid 22791); 30 Aug 2012 10:48:49 -0000 X-SWARE-Spam-Status: No, hits=-6.6 required=5.0 tests=BAYES_00, KHOP_RCVD_UNTRUST, RCVD_IN_DNSWL_HI, RCVD_IN_HOSTKARMA_W, RP_MATCHES_RCVD, TW_CX X-Spam-Check-By: sourceware.org Received: from mga03.intel.com (HELO mga03.intel.com) (143.182.124.21) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 30 Aug 2012 10:48:36 +0000 Received: from azsmga002.ch.intel.com ([10.2.17.35]) by azsmga101.ch.intel.com with ESMTP; 30 Aug 2012 03:48:36 -0700 X-ExtLoop1: 1 Received: from unknown (HELO tjmaciei-mobl2.localnet) ([10.252.121.147]) by AZSMGA002.ch.intel.com with ESMTP; 30 Aug 2012 03:48:35 -0700 From: Thiago Macieira To: gcc-patches@gcc.gnu.org, libstdc++@gcc.gnu.org Subject: [PATCH, libstdc++] Improve slightly __cxa_guard_acquire Date: Thu, 30 Aug 2012 12:48:34 +0200 Message-ID: <2255222.Ergk1VO0fz@tjmaciei-mobl2> User-Agent: KMail/4.9 beta1 (Linux/3.5.2-3.fc17.x86_64; KDE/4.8.5; x86_64; git-2bb8395; 2012-06-03) MIME-Version: 1.0 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Hello The attached patch is a simple improvement to make a thread that failed to set the waiting bit to exit the function earlier, if it detects that another thread has successfully finished initialising. It matches the CAS code from a few lines above. The change from RELAXED to ACQUIRE is noted in the previous patch I've just sent. 2012-08-30 Thiago Macieira * libsupc++/guard.cc (__cxa_guard_acquire): exit the loop earlier if we detect that another thread has had success. --- libstdc++-v3/libsupc++/guard.cc | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/libstdc++-v3/libsupc++/guard.cc b/libstdc++-v3/libsupc++/guard.cc index bfe1a59..73d7221 100644 --- a/libstdc++-v3/libsupc++/guard.cc +++ b/libstdc++-v3/libsupc++/guard.cc @@ -269,8 +269,16 @@ namespace __cxxabiv1 int newv = expected | waiting_bit; if (!__atomic_compare_exchange_n(gi, &expected, newv, false, __ATOMIC_ACQ_REL, - __ATOMIC_RELAXED)) - continue; + __ATOMIC_ACQUIRE)) + { + if (expected == guard_bit) + { + // Already initialized. + return 0; + } + if (expected == 0) + continue; + } expected = newv; } -- 1.7.11.4