From patchwork Tue Dec 27 09:43:40 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Uros Bizjak X-Patchwork-Id: 133305 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 10603B6FA9 for ; Tue, 27 Dec 2011 20:44:00 +1100 (EST) Received: (qmail 28599 invoked by alias); 27 Dec 2011 09:43:56 -0000 Received: (qmail 28588 invoked by uid 22791); 27 Dec 2011 09:43:55 -0000 X-SWARE-Spam-Status: No, hits=-2.3 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, TW_IB, TW_ZJ X-Spam-Check-By: sourceware.org Received: from mail-yx0-f175.google.com (HELO mail-yx0-f175.google.com) (209.85.213.175) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 27 Dec 2011 09:43:41 +0000 Received: by yenm12 with SMTP id m12so6664366yen.20 for ; Tue, 27 Dec 2011 01:43:40 -0800 (PST) MIME-Version: 1.0 Received: by 10.236.187.97 with SMTP id x61mr36026785yhm.97.1324979020520; Tue, 27 Dec 2011 01:43:40 -0800 (PST) Received: by 10.146.236.18 with HTTP; Tue, 27 Dec 2011 01:43:40 -0800 (PST) Date: Tue, 27 Dec 2011 10:43:40 +0100 Message-ID: Subject: [PATCH, alpha]: Use __sync* functions in libjava locks.h From: Uros Bizjak To: gcc-patches@gcc.gnu.org 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! No functional change. 2011-12-27 Uros Bizjak PR libgcj/49193 * sysdep/alpha/locks.h (compare_and_swap): Call __sync_bool_compare_and_swap. (release_set): Call __sync_synchronize. Tested on alphaeev68-pc-linux-gnu, committed to mainline SVN. Uros. Index: sysdep/alpha/locks.h =================================================================== --- sysdep/alpha/locks.h (revision 182691) +++ sysdep/alpha/locks.h (working copy) @@ -1,6 +1,6 @@ // locks.h - Thread synchronization primitives. Alpha implementation. -/* Copyright (C) 2002 Free Software Foundation +/* Copyright (C) 2002, 2011 Free Software Foundation This file is part of libgcj. @@ -11,41 +11,38 @@ #ifndef __SYSDEP_LOCKS_H__ #define __SYSDEP_LOCKS_H__ -typedef size_t obj_addr_t; /* Integer type big enough for object */ - /* address. */ +/* Integer type big enough for object address. */ +typedef size_t obj_addr_t; +// Atomically replace *addr by new_val if it was initially equal to old. +// Return true if the comparison succeeded. +// Assumed to have acquire semantics, i.e. later memory operations +// cannot execute before the compare_and_swap finishes. inline static bool compare_and_swap(volatile obj_addr_t *addr, - obj_addr_t old, - obj_addr_t new_val) + obj_addr_t old, + obj_addr_t new_val) { - unsigned long oldval; - char result; - __asm__ __volatile__( - "1:ldq_l %0, %1\n\t" \ - "cmpeq %0, %5, %2\n\t" \ - "beq %2, 2f\n\t" \ - "mov %3, %0\n\t" \ - "stq_c %0, %1\n\t" \ - "bne %0, 2f\n\t" \ - "br 1b\n\t" \ - "2:mb" - : "=&r"(oldval), "=m"(*addr), "=&r"(result) - : "r" (new_val), "m"(*addr), "r"(old) : "memory"); - return (bool) result; + return __sync_bool_compare_and_swap(addr, old, new_val); } +// Set *addr to new_val with release semantics, i.e. making sure +// that prior loads and stores complete before this +// assignment. inline static void release_set(volatile obj_addr_t *addr, obj_addr_t new_val) { - __asm__ __volatile__("mb" : : : "memory"); + __sync_synchronize(); *(addr) = new_val; } +// Compare_and_swap with release semantics instead of acquire semantics. +// On many architecture, the operation makes both guarantees, so the +// implementation can be the same. inline static bool compare_and_swap_release(volatile obj_addr_t *addr, - obj_addr_t old, - obj_addr_t new_val) + obj_addr_t old, + obj_addr_t new_val) { return compare_and_swap(addr, old, new_val); }