1 // locks.h - Thread synchronization primitives. PA-RISC implementation.
3 /* Copyright (C) 2002, 2005 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 // Integer type big enough for object address.
15 typedef size_t obj_addr_t
;
18 struct _pa_jv_cas_lock
20 static volatile int _S_pa_jv_cas_lock
;
25 _pa_jv_cas_lock
<_Inst
>::_S_pa_jv_cas_lock
__attribute__ ((aligned (16))) = 1;
27 // Because of the lack of weak support when using the hpux som
28 // linker, we explicitly instantiate the atomicity lock.
29 template volatile int _pa_jv_cas_lock
<0>::_S_pa_jv_cas_lock
;
31 // Atomically replace *addr by new_val if it was initially equal to old_val.
32 // Return true if the comparison is successful.
33 // Assumed to have acquire semantics, i.e. later memory operations
34 // cannot execute before the compare_and_swap finishes.
35 // The following implementation is atomic but it can deadlock
36 // (e.g., if a thread dies holding the lock).
38 __attribute__ ((__unused__
))
39 compare_and_swap(volatile obj_addr_t
*addr
,
45 volatile int& lock
= _pa_jv_cas_lock
<0>::_S_pa_jv_cas_lock
;
47 __asm__
__volatile__ ("ldcw 0(%1),%0\n\t"
48 "cmpib,<>,n 0,%0,.+20\n\t"
50 "cmpib,= 0,%0,.-4\n\t"
65 /* Reset lock with PA 2.0 "ordered" store. */
66 __asm__
__volatile__ ("stw,ma %1,0(%0)"
67 : : "r" (&lock
), "r" (tmp
) : "memory");
72 // Set *addr to new_val with release semantics, i.e. making sure
73 // that prior loads and stores complete before this
76 release_set(volatile obj_addr_t
*addr
, obj_addr_t new_val
)
78 __asm__
__volatile__(" " : : : "memory");
82 // Compare_and_swap with release semantics instead of acquire semantics.
83 // On many architecture, the operation makes both guarantees, so the
84 // implementation can be the same.
86 compare_and_swap_release(volatile obj_addr_t
*addr
,
90 return compare_and_swap(addr
, old
, new_val
);
93 // Ensure that subsequent instructions do not execute on stale
94 // data that was loaded from memory before the barrier.
98 __asm__
__volatile__(" " : : : "memory");
101 // Ensure that prior stores to memory are completed with respect to other
106 __asm__
__volatile__(" " : : : "memory");