1169691Skan// Low-level type for atomic operations -*- C++ -*- 2169691Skan 3169691Skan// Copyright (C) 2004, 2005, 2006, 2007 Free Software Foundation, Inc. 4169691Skan// 5169691Skan// This file is part of the GNU ISO C++ Library. This library is free 6169691Skan// software; you can redistribute it and/or modify it under the 7169691Skan// terms of the GNU General Public License as published by the 8169691Skan// Free Software Foundation; either version 2, or (at your option) 9169691Skan// any later version. 10169691Skan 11169691Skan// This library is distributed in the hope that it will be useful, 12169691Skan// but WITHOUT ANY WARRANTY; without even the implied warranty of 13169691Skan// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14169691Skan// GNU General Public License for more details. 15169691Skan 16169691Skan// You should have received a copy of the GNU General Public License along 17169691Skan// with this library; see the file COPYING. If not, write to the Free 18169691Skan// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 19169691Skan// USA. 20169691Skan 21169691Skan// As a special exception, you may use this file as part of a free software 22169691Skan// library without restriction. Specifically, if other files instantiate 23169691Skan// templates or use macros or inline functions from this file, or you compile 24169691Skan// this file and link it with other files to produce an executable, this 25169691Skan// file does not by itself cause the resulting executable to be covered by 26169691Skan// the GNU General Public License. This exception does not however 27169691Skan// invalidate any other reasons why the executable file might be covered by 28169691Skan// the GNU General Public License. 29169691Skan 30169691Skan#ifndef _GLIBCXX_ATOMIC_WORD_H 31169691Skan#define _GLIBCXX_ATOMIC_WORD_H 1 32169691Skan 33169691Skan#include <bits/cxxabi_tweaks.h> 34169691Skan 35169691Skantypedef int _Atomic_word; 36169691Skan 37169691Skannamespace __gnu_cxx 38169691Skan{ 39169691Skan // Test the first byte of __g and ensure that no loads are hoisted across 40169691Skan // the test. 41169691Skan inline bool 42169691Skan __test_and_acquire (__cxxabiv1::__guard *__g) 43169691Skan { 44169691Skan unsigned char __c; 45169691Skan unsigned char *__p = reinterpret_cast<unsigned char *>(__g); 46169691Skan // ldN.acq is a load with an implied hoist barrier. 47169691Skan // would ld8+mask be faster than just doing an ld1? 48169691Skan __asm __volatile ("ld1.acq %0 = %1" : "=r"(__c) : "m"(*__p) : "memory"); 49169691Skan return __c != 0; 50169691Skan } 51169691Skan 52169691Skan // Set the first byte of __g to 1 and ensure that no stores are sunk 53169691Skan // across the store. 54169691Skan inline void 55169691Skan __set_and_release (__cxxabiv1::__guard *__g) 56169691Skan { 57169691Skan unsigned char *__p = reinterpret_cast<unsigned char *>(__g); 58169691Skan // stN.rel is a store with an implied sink barrier. 59169691Skan // could load word, set flag, and CAS it back 60169691Skan __asm __volatile ("st1.rel %0 = %1" : "=m"(*__p) : "r"(1) : "memory"); 61169691Skan } 62169691Skan 63169691Skan // We don't define the _BARRIER macros on ia64 because the barriers are 64169691Skan // included in the test and set, above. 65169691Skan#define _GLIBCXX_GUARD_TEST_AND_ACQUIRE(G) __gnu_cxx::__test_and_acquire (G) 66169691Skan#define _GLIBCXX_GUARD_SET_AND_RELEASE(G) __gnu_cxx::__set_and_release (G) 67169691Skan} 68169691Skan 69169691Skan#endif 70