1 // locks.h - Thread synchronization primitives. PowerPC 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__
15 #define _LARX "ldarx "
16 #define _STCX "stdcx. "
18 #define _LARX "lwarx "
20 #define _STCX "sync; stwcx. "
22 #define _STCX "stwcx. "
26 typedef size_t obj_addr_t
; /* Integer type big enough for object */
30 compare_and_swap (volatile obj_addr_t
*addr
, obj_addr_t old
,
35 __asm__
__volatile__ (
36 "0: " _LARX
"%0,0,%1 \n"
43 : "r" (addr
), "r" (new_val
), "r" (old
)
46 /* This version of __compare_and_swap is to be used when acquiring
47 a lock, so we don't need to worry about whether other memory
48 operations have completed, but we do need to be sure that any loads
49 after this point really occur after we have acquired the lock. */
50 __asm__
__volatile__ ("isync" : : : "memory");
55 release_set (volatile obj_addr_t
*addr
, obj_addr_t new_val
)
57 __asm__
__volatile__ ("sync" : : : "memory");
62 compare_and_swap_release (volatile obj_addr_t
*addr
, obj_addr_t old
,
67 __asm__
__volatile__ ("sync" : : : "memory");
69 __asm__
__volatile__ (
70 "0: " _LARX
"%0,0,%1 \n"
77 : "r" (addr
), "r" (new_val
), "r" (old
)
83 // Ensure that subsequent instructions do not execute on stale
84 // data that was loaded from memory before the barrier.
88 __asm__
__volatile__ ("isync" : : : "memory");
91 // Ensure that prior stores to memory are completed with respect to other
96 __asm__
__volatile__ ("sync" : : : "memory");