190285Sobrien// Low-level functions for atomic operations: x86, x >= 4 version -*- C++ -*- 290285Sobrien 390285Sobrien// Copyright (C) 1999, 2000, 2001, 2004, 2005 Free Software Foundation, Inc. 418334Speter// 518334Speter// This file is part of the GNU ISO C++ Library. This library is free 618334Speter// software; you can redistribute it and/or modify it under the 718334Speter// terms of the GNU General Public License as published by the 818334Speter// Free Software Foundation; either version 2, or (at your option) 918334Speter// any later version. 1018334Speter 1118334Speter// This library is distributed in the hope that it will be useful, 1218334Speter// but WITHOUT ANY WARRANTY; without even the implied warranty of 1318334Speter// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1418334Speter// GNU General Public License for more details. 1518334Speter 1618334Speter// You should have received a copy of the GNU General Public License along 1718334Speter// with this library; see the file COPYING. If not, write to the Free 1818334Speter// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 1918334Speter// USA. 2090285Sobrien 2118334Speter// As a special exception, you may use this file as part of a free software 2218334Speter// library without restriction. Specifically, if other files instantiate 2318334Speter// templates or use macros or inline functions from this file, or you compile 2418334Speter// this file and link it with other files to produce an executable, this 2518334Speter// file does not by itself cause the resulting executable to be covered by 2618334Speter// the GNU General Public License. This exception does not however 2718334Speter// invalidate any other reasons why the executable file might be covered by 2818334Speter// the GNU General Public License. 2918334Speter 3018334Speter#include <ext/atomicity.h> 3118334Speter 3218334Speter_GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx) 3390285Sobrien 3490285Sobrien _Atomic_word 3590285Sobrien __attribute__ ((__unused__)) 3618334Speter __exchange_and_add(volatile _Atomic_word* __mem, int __val) 3790285Sobrien { 3852295Sobrien register _Atomic_word __result; 3952295Sobrien __asm__ __volatile__ ("lock; xadd{l} {%0,%1|%1,%0}" 4018334Speter : "=r" (__result), "=m" (*__mem) 4118334Speter : "0" (__val), "m" (*__mem)); 4218334Speter return __result; 4318334Speter } 4418334Speter 4518334Speter void 4618334Speter __attribute__ ((__unused__)) 4718334Speter __atomic_add(volatile _Atomic_word* __mem, int __val) 4818334Speter { 4990285Sobrien __asm__ __volatile__ ("lock; add{l} {%1,%0|%0,%1}" 5018334Speter : "=m" (*__mem) : "ir" (__val), "m" (*__mem)); 5190285Sobrien } 5218334Speter 5318334Speter_GLIBCXX_END_NAMESPACE 5418334Speter 5550654Sobrien