1 // Low-level functions for atomic operations: Sparc version -*- C++ -*-
3 // Copyright (C) 1999, 2000, 2001, 2002, 2004, 2005, 2009
4 // Free Software Foundation, Inc.
6 // This file is part of the GNU ISO C++ Library. This library is free
7 // software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the
9 // Free Software Foundation; either version 3, or (at your option)
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // Under Section 7 of GPL version 3, you are granted additional
18 // permissions described in the GCC Runtime Library Exception, version
19 // 3.1, as published by the Free Software Foundation.
21 // You should have received a copy of the GNU General Public License and
22 // a copy of the GCC Runtime Library Exception along with this program;
23 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24 // <http://www.gnu.org/licenses/>.
26 #include <ext/atomicity.h>
28 namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
30 _GLIBCXX_BEGIN_NAMESPACE_VERSION
34 __attribute__ ((__unused__))
35 __exchange_and_add(volatile _Atomic_word* __mem, int __val) throw ()
37 _Atomic_word __tmp1, __tmp2;
38 _Atomic_word __val_extended = __val;
40 __asm__ __volatile__("1: ldx [%3], %0\n\t"
42 " casx [%3], %0, %1\n\t"
46 : "=&r" (__tmp1), "=&r" (__tmp2), "=m" (*__mem)
47 : "r" (__mem), "r" (__val_extended), "m" (*__mem));
52 __attribute__ ((__unused__))
53 __atomic_add(volatile _Atomic_word* __mem, int __val) throw ()
55 _Atomic_word __tmp1, __tmp2;
56 _Atomic_word __val_extended = __val;
58 __asm__ __volatile__("1: ldx [%3], %0\n\t"
60 " casx [%3], %0, %1\n\t"
64 : "=&r" (__tmp1), "=&r" (__tmp2), "=m" (*__mem)
65 : "r" (__mem), "r" (__val_extended), "m" (*__mem));
68 #else /* __arch32__ */
71 struct _Atomicity_lock
73 static unsigned char _S_atomicity_lock;
77 unsigned char _Atomicity_lock<__inst>::_S_atomicity_lock = 0;
79 template unsigned char _Atomicity_lock<0>::_S_atomicity_lock;
82 __attribute__ ((__unused__))
83 __exchange_and_add(volatile _Atomic_word* __mem, int __val) throw ()
85 _Atomic_word __result, __tmp;
87 __asm__ __volatile__("1: ldstub [%1], %0\n\t"
92 : "r" (&_Atomicity_lock<0>::_S_atomicity_lock)
96 __asm__ __volatile__("stb %%g0, [%0]"
98 : "r" (&_Atomicity_lock<0>::_S_atomicity_lock)
104 __attribute__ ((__unused__))
105 __atomic_add(volatile _Atomic_word* __mem, int __val) throw ()
109 __asm__ __volatile__("1: ldstub [%1], %0\n\t"
114 : "r" (&_Atomicity_lock<0>::_S_atomicity_lock)
117 __asm__ __volatile__("stb %%g0, [%0]"
119 : "r" (&_Atomicity_lock<0>::_S_atomicity_lock)
122 #endif /* __arch32__ */
124 _GLIBCXX_END_NAMESPACE_VERSION