12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #ifndef OS_CPU_SOLARIS_SPARC_VM_ATOMIC_SOLARIS_SPARC_HPP
26 #define OS_CPU_SOLARIS_SPARC_VM_ATOMIC_SOLARIS_SPARC_HPP
27
28 // Implementation of class atomic
29
30 // Implement ADD using a CAS loop.
31 template<size_t byte_size>
32 struct Atomic::PlatformAdd VALUE_OBJ_CLASS_SPEC {
33 template<typename I, typename D>
34 inline D operator()(I add_value, D volatile* dest) const {
35 D old_value = *dest;
36 while (true) {
37 D new_value = old_value + add_value;
38 D result = cmpxchg(new_value, dest, old_value);
39 if (result == old_value) break;
40 old_value = result;
41 }
42 return old_value + add_value;
43 }
44 };
45
46 template<>
47 template<typename T>
48 inline T Atomic::PlatformXchg<4>::operator()(T exchange_value,
49 T volatile* dest) const {
50 STATIC_ASSERT(4 == sizeof(T));
51 __asm__ volatile ( "swap [%2],%0"
52 : "=r" (exchange_value)
|
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #ifndef OS_CPU_SOLARIS_SPARC_VM_ATOMIC_SOLARIS_SPARC_HPP
26 #define OS_CPU_SOLARIS_SPARC_VM_ATOMIC_SOLARIS_SPARC_HPP
27
28 // Implementation of class atomic
29
30 // Implement ADD using a CAS loop.
31 template<size_t byte_size>
32 struct Atomic::PlatformAdd {
33 template<typename I, typename D>
34 inline D operator()(I add_value, D volatile* dest) const {
35 D old_value = *dest;
36 while (true) {
37 D new_value = old_value + add_value;
38 D result = cmpxchg(new_value, dest, old_value);
39 if (result == old_value) break;
40 old_value = result;
41 }
42 return old_value + add_value;
43 }
44 };
45
46 template<>
47 template<typename T>
48 inline T Atomic::PlatformXchg<4>::operator()(T exchange_value,
49 T volatile* dest) const {
50 STATIC_ASSERT(4 == sizeof(T));
51 __asm__ volatile ( "swap [%2],%0"
52 : "=r" (exchange_value)
|