atomicity.h revision 169691
1169691Skan// Low-level functions for atomic operations: sh version -*- C++ -*- 2169691Skan 3169691Skan// Copyright (C) 1999, 2001, 2002, 2003, 2004, 2005, 2006 4169691Skan// Free Software Foundation, Inc. 5169691Skan// 6169691Skan// This file is part of the GNU ISO C++ Library. This library is free 7169691Skan// software; you can redistribute it and/or modify it under the 8169691Skan// terms of the GNU General Public License as published by the 9169691Skan// Free Software Foundation; either version 2, or (at your option) 10169691Skan// any later version. 11169691Skan 12169691Skan// This library is distributed in the hope that it will be useful, 13169691Skan// but WITHOUT ANY WARRANTY; without even the implied warranty of 14169691Skan// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15169691Skan// GNU General Public License for more details. 16169691Skan 17169691Skan// You should have received a copy of the GNU General Public License along 18169691Skan// with this library; see the file COPYING. If not, write to the Free 19169691Skan// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 20169691Skan// USA. 21169691Skan 22169691Skan// As a special exception, you may use this file as part of a free software 23169691Skan// library without restriction. Specifically, if other files instantiate 24169691Skan// templates or use macros or inline functions from this file, or you compile 25169691Skan// this file and link it with other files to produce an executable, this 26169691Skan// file does not by itself cause the resulting executable to be covered by 27169691Skan// the GNU General Public License. This exception does not however 28169691Skan// invalidate any other reasons why the executable file might be covered by 29169691Skan// the GNU General Public License. 30169691Skan 31169691Skan#ifndef _BITS_ATOMICITY_H 32169691Skan#define _BITS_ATOMICITY_H 1 33169691Skan 34169691Skan#ifdef __SH4A__ 35169691Skan 36169691Skantypedef int _Atomic_word; 37169691Skan 38169691Skanstatic inline _Atomic_word 39169691Skan__attribute__ ((__unused__)) 40169691Skan__exchange_and_add (volatile _Atomic_word* __mem, int __val) 41169691Skan{ 42169691Skan _Atomic_word __result; 43169691Skan 44169691Skan __asm__ __volatile__ 45169691Skan ("0:\n" 46169691Skan "\tmovli.l\t@%2,r0\n" 47169691Skan "\tmov\tr0,%1\n" 48169691Skan "\tadd\t%3,r0\n" 49169691Skan "\tmovco.l\tr0,@%2\n" 50169691Skan "\tbf\t0b" 51169691Skan : "+m" (*__mem), "=r" (__result) 52169691Skan : "r" (__mem), "rI08" (__val) 53169691Skan : "r0"); 54169691Skan 55169691Skan return __result; 56169691Skan} 57169691Skan 58169691Skan 59169691Skanstatic inline void 60169691Skan__attribute__ ((__unused__)) 61169691Skan__atomic_add (volatile _Atomic_word* __mem, int __val) 62169691Skan{ 63169691Skan asm("0:\n" 64169691Skan "\tmovli.l\t@%1,r0\n" 65169691Skan "\tadd\t%2,r0\n" 66169691Skan "\tmovco.l\tr0,@%1\n" 67169691Skan "\tbf\t0b" 68169691Skan : "+m" (*__mem) 69169691Skan : "r" (__mem), "rI08" (__val) 70169691Skan : "r0"); 71169691Skan} 72169691Skan 73169691Skan#else /* !__SH4A__ */ 74169691Skan 75169691Skan/* This is generic/atomicity.h */ 76169691Skan 77169691Skan#include <ext/atomicity.h> 78169691Skan#include <ext/concurrence.h> 79169691Skan 80169691Skannamespace 81169691Skan{ 82169691Skan __gnu_cxx::__mutex atomic_mutex; 83169691Skan} // anonymous namespace 84169691Skan 85169691Skan_GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx) 86169691Skan 87169691Skan _Atomic_word 88169691Skan __attribute__ ((__unused__)) 89169691Skan __exchange_and_add(volatile _Atomic_word* __mem, int __val) 90169691Skan { 91169691Skan __gnu_cxx::__scoped_lock sentry(atomic_mutex); 92169691Skan _Atomic_word __result; 93169691Skan __result = *__mem; 94169691Skan *__mem += __val; 95169691Skan return __result; 96169691Skan } 97169691Skan 98169691Skan void 99169691Skan __attribute__ ((__unused__)) 100169691Skan __atomic_add(volatile _Atomic_word* __mem, int __val) 101169691Skan { __exchange_and_add(__mem, __val); } 102169691Skan 103169691Skan_GLIBCXX_END_NAMESPACE 104169691Skan 105169691Skan#endif /* !__SH4A__ */ 106169691Skan 107169691Skan#endif /* atomicity.h */ 108