From patchwork Thu Jul 17 23:25:57 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John David Anglin X-Patchwork-Id: 371267 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 0EFA4140173 for ; Fri, 18 Jul 2014 09:26:28 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:from:to:content-type:subject:mime-version:date; q= dns; s=default; b=YTY//z+Q/pN6CFT4C4GJsIM5A5+8G0u/SMRr6basZs9tX9 Ff8A7AMr8AEhKc1+/p/GnhFSouOII2EQRCL4vRnJFsHaS4bCflvhuht00l4EuMaG trhJLRvW2cpHmVkhAUTwDYSzCgs02hLwb89RDocjQ+hG1qy4Hup+3TPsKprcI= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:from:to:content-type:subject:mime-version:date; s= default; bh=8hgN+P/hZU5J0RVh7cM3rEkeGy4=; b=rsbQhSYR1y7jcMifuTpJ sGD5opXsYOljJYrfaxtBZC4RevtohI9nkcMzdRp0vMANBHl3hyMPAVmVQUfFqRPF dtFT+0kp19Sz2y8c4jE/5tI9IKaGa0XTRphAk7p3muPZZIdH4Iwlb6MYZzDa4ZvA ucALzokVaHlWOPA0GLkIM9Q= Received: (qmail 2657 invoked by alias); 17 Jul 2014 23:26:21 -0000 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 Received: (qmail 2620 invoked by uid 89); 17 Jul 2014 23:26:19 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL, BAYES_00, MSGID_FROM_MTA_HEADER, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 X-HELO: BLU004-OMC3S23.hotmail.com Received: from blu004-omc3s23.hotmail.com (HELO BLU004-OMC3S23.hotmail.com) (65.55.116.98) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA256 encrypted) ESMTPS; Thu, 17 Jul 2014 23:26:16 +0000 Received: from BLU436-SMTP97 ([65.55.116.72]) by BLU004-OMC3S23.hotmail.com with Microsoft SMTPSVC(7.5.7601.22712); Thu, 17 Jul 2014 16:26:15 -0700 X-TMN: [3tlCYLYDrnaxzRdZ7sLU4qcgJXFw1Sxl] Message-ID: Received: from [192.168.2.16] ([70.26.30.52]) by smtphm.sympatico.ca over TLS secured channel with Microsoft SMTPSVC(8.0.9200.16384); Thu, 17 Jul 2014 16:26:13 -0700 From: John David Anglin To: GCC Patches Subject: [committed] Use __kernel_cmpxchg for __sync_lock_release MIME-Version: 1.0 (Apple Message framework v936) Date: Thu, 17 Jul 2014 19:25:57 -0400 Because the atomic sync functions in config/pa/linux-atomic.c are not lock free, we need to use __kernel_cmpxchg for the __sync_lock_release. This was found in glibc's pthread_spin_unlock implementation. Tested on hppa-unknown-linux-gnu. Committed to trunk. Dave --- John David Anglin dave.anglin@bell.net 2014-07-17 John David Anglin * config/pa/linux-atomic.c (__sync_lock_release_4): New. (SYNC_LOCK_RELEASE): Update to use __kernel_cmpxchg for release. Don't use SYNC_LOCK_RELEASE for int type. Index: config/pa/linux-atomic.c =================================================================== --- config/pa/linux-atomic.c (revision 210671) +++ config/pa/linux-atomic.c (working copy) @@ -293,13 +293,34 @@ SUBWORD_TEST_AND_SET (unsigned short, 2) SUBWORD_TEST_AND_SET (unsigned char, 1) +void HIDDEN +__sync_lock_release_4 (int *ptr) +{ + int failure, oldval; + + do { + oldval = *ptr; + failure = __kernel_cmpxchg (oldval, 0, ptr); + } while (failure != 0); +} + #define SYNC_LOCK_RELEASE(TYPE, WIDTH) \ void HIDDEN \ __sync_lock_release_##WIDTH (TYPE *ptr) \ { \ - *ptr = 0; \ + int failure; \ + unsigned int oldval, newval, shift, mask; \ + int *wordptr = (int *) ((unsigned long) ptr & ~3); \ + \ + shift = (((unsigned long) ptr & 3) << 3) ^ INVERT_MASK_##WIDTH; \ + mask = MASK_##WIDTH << shift; \ + \ + do { \ + oldval = *wordptr; \ + newval = oldval & ~mask; \ + failure = __kernel_cmpxchg (oldval, newval, wordptr); \ + } while (failure != 0); \ } -SYNC_LOCK_RELEASE (int, 4) SYNC_LOCK_RELEASE (short, 2) SYNC_LOCK_RELEASE (char, 1)