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 _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx
)
32 __attribute__ ((__unused__
))
33 __exchange_and_add(volatile _Atomic_word
* __mem
, int __val
) throw ()
35 _Atomic_word __tmp1
, __tmp2
;
36 _Atomic_word __val_extended
= __val
;
38 __asm__
__volatile__("1: ldx [%3], %0\n\t"
40 " casx [%3], %0, %1\n\t"
44 : "=&r" (__tmp1
), "=&r" (__tmp2
), "=m" (*__mem
)
45 : "r" (__mem
), "r" (__val_extended
), "m" (*__mem
));
50 __attribute__ ((__unused__
))
51 __atomic_add(volatile _Atomic_word
* __mem
, int __val
) throw ()
53 _Atomic_word __tmp1
, __tmp2
;
54 _Atomic_word __val_extended
= __val
;
56 __asm__
__volatile__("1: ldx [%3], %0\n\t"
58 " casx [%3], %0, %1\n\t"
62 : "=&r" (__tmp1
), "=&r" (__tmp2
), "=m" (*__mem
)
63 : "r" (__mem
), "r" (__val_extended
), "m" (*__mem
));
66 #else /* __arch32__ */
69 struct _Atomicity_lock
71 static unsigned char _S_atomicity_lock
;
75 unsigned char _Atomicity_lock
<__inst
>::_S_atomicity_lock
= 0;
77 template unsigned char _Atomicity_lock
<0>::_S_atomicity_lock
;
80 __attribute__ ((__unused__
))
81 __exchange_and_add(volatile _Atomic_word
* __mem
, int __val
) throw ()
83 _Atomic_word __result
, __tmp
;
85 __asm__
__volatile__("1: ldstub [%1], %0\n\t"
90 : "r" (&_Atomicity_lock
<0>::_S_atomicity_lock
)
94 __asm__
__volatile__("stb %%g0, [%0]"
96 : "r" (&_Atomicity_lock
<0>::_S_atomicity_lock
)
102 __attribute__ ((__unused__
))
103 __atomic_add(volatile _Atomic_word
* __mem
, int __val
) throw ()
107 __asm__
__volatile__("1: ldstub [%1], %0\n\t"
112 : "r" (&_Atomicity_lock
<0>::_S_atomicity_lock
)
115 __asm__
__volatile__("stb %%g0, [%0]"
117 : "r" (&_Atomicity_lock
<0>::_S_atomicity_lock
)
120 #endif /* __arch32__ */
122 _GLIBCXX_END_NAMESPACE