From patchwork Tue Feb 1 20:15:23 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Lance Taylor X-Patchwork-Id: 81370 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 672FBB710D for ; Wed, 2 Feb 2011 07:15:40 +1100 (EST) Received: (qmail 31597 invoked by alias); 1 Feb 2011 20:15:38 -0000 Received: (qmail 31580 invoked by uid 22791); 1 Feb 2011 20:15:35 -0000 X-SWARE-Spam-Status: No, hits=-2.3 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, SPF_HELO_PASS, T_RP_MATCHES_RCVD, T_TVD_MIME_NO_HEADERS X-Spam-Check-By: sourceware.org Received: from smtp-out.google.com (HELO smtp-out.google.com) (216.239.44.51) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 01 Feb 2011 20:15:29 +0000 Received: from kpbe15.cbf.corp.google.com (kpbe15.cbf.corp.google.com [172.25.105.79]) by smtp-out.google.com with ESMTP id p11KFRCr005451 for ; Tue, 1 Feb 2011 12:15:27 -0800 Received: from iwr19 (iwr19.prod.google.com [10.241.69.83]) by kpbe15.cbf.corp.google.com with ESMTP id p11KEYie029988 (version=TLSv1/SSLv3 cipher=RC4-MD5 bits=128 verify=NOT) for ; Tue, 1 Feb 2011 12:15:26 -0800 Received: by iwr19 with SMTP id 19so8159539iwr.37 for ; Tue, 01 Feb 2011 12:15:25 -0800 (PST) Received: by 10.42.171.10 with SMTP id h10mr10176291icz.305.1296591325671; Tue, 01 Feb 2011 12:15:25 -0800 (PST) Received: from coign.google.com (dhcp-172-22-122-181.mtv.corp.google.com [172.22.122.181]) by mx.google.com with ESMTPS id k42sm17232560ick.20.2011.02.01.12.15.24 (version=TLSv1/SSLv3 cipher=RC4-MD5); Tue, 01 Feb 2011 12:15:25 -0800 (PST) From: Ian Lance Taylor To: gcc-patches@gcc.gnu.org, gofrontend-dev@googlegroups.com Subject: libgo patch committed: Add __sync_bool_compare_and_swap_4 Date: Tue, 01 Feb 2011 12:15:23 -0800 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) MIME-Version: 1.0 X-System-Of-Record: true X-IsSubscribed: yes 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 The libgo library uses __sync_bool_compare_and_swap_4 (i.e., uses __sync_bool_compare_and_swap on uint32 types). That function is not available for all gcc targets. This patch adds the function to the library for those cases. Ideally this would be handled by libgcc, but that does not currently happen. This function should be harmless if libgcc does get an implementation. This implementation is rather slow but it is better than having the build fail. Bootstrapped and ran Go testsuite on x86_64-unknown-linux-gnu. Committed to mainline. Ian diff -r 948edbf8367c libgo/runtime/thread.c --- a/libgo/runtime/thread.c Mon Jan 31 15:32:52 2011 -0800 +++ b/libgo/runtime/thread.c Tue Feb 01 12:11:10 2011 -0800 @@ -3,6 +3,7 @@ // license that can be found in the LICENSE file. #include "runtime.h" +#include "go-assert.h" void runtime_initlock(Lock *l) @@ -75,3 +76,38 @@ { sem_destroy(&l->sem); } + +#ifndef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 + +// For targets which don't have the required sync support. Really +// this should be provided by gcc itself. FIXME. + +static pthread_mutex_t sync_lock = PTHREAD_MUTEX_INITIALIZER; + +_Bool +__sync_bool_compare_and_swap_4(uint32*, uint32, uint32) + __attribute__((visibility("hidden"))); + +_Bool +__sync_bool_compare_and_swap_4(uint32* ptr, uint32 old, uint32 new) +{ + int i; + _Bool ret; + + i = pthread_mutex_lock(&sync_lock); + __go_assert(i == 0); + + if(*ptr != old) { + ret = 0; + } else { + *ptr = new; + ret = 1; + } + + i = pthread_mutex_unlock(&sync_lock); + __go_assert(i == 0); + + return ret; +} + +#endif