1 // locks.h - Thread synchronization primitives. Sparc implementation.
3 /* Copyright (C) 2002 Free Software Foundation
5 This file is part of libgcj.
7 This software is copyrighted work licensed under the terms of the
8 Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
11 #ifndef __SYSDEP_LOCKS_H__
12 #define __SYSDEP_LOCKS_H__
14 typedef size_t obj_addr_t
; /* Integer type big enough for object */
18 /* Sparc64 implementation, use cas instruction. */
20 compare_and_swap(volatile obj_addr_t
*addr
,
24 __asm__
__volatile__("casx [%2], %3, %0\n\t"
25 "membar #StoreLoad | #StoreStore"
27 : "0" (new_val
), "r" (addr
), "r" (old
)
30 return (new_val
== old
) ? true : false;
34 release_set(volatile obj_addr_t
*addr
, obj_addr_t new_val
)
36 __asm__
__volatile__("membar #StoreStore | #LoadStore" : : : "memory");
41 compare_and_swap_release(volatile obj_addr_t
*addr
,
45 return compare_and_swap(addr
, old
, new_val
);
48 /* Sparc32 implementation, use a spinlock. */
49 static unsigned char __cas_lock
= 0;
52 __cas_start_atomic(void)
56 "1: ldstub [%1], %0\n"
57 " orcc %0, 0x0, %%g0\n"
61 " orcc %0, 0x0, %%g0\n"
70 __cas_end_atomic(void)
80 compare_and_swap(volatile obj_addr_t
*addr
,
86 __cas_start_atomic ();
102 release_set(volatile obj_addr_t
*addr
, obj_addr_t new_val
)
104 /* Technically stbar would be needed here but no sparc32
105 system actually requires it. Also the stbar would mean
106 this code would not work on sparcv7 chips. */
107 __asm__
__volatile__("" : : : "memory");
112 compare_and_swap_release(volatile obj_addr_t
*addr
,
116 return compare_and_swap(addr
, old
, new_val
);
118 #endif /* __arch64__ */
120 #endif /* ! __SYSDEP_LOCKS_H__ */