PR middle-end/44765
[official-gcc.git] / libjava / sysdep / sh / locks.h
blob9a152fb30e58c7159c98556ce92e637bde4479c2
1 // locks.h - Thread synchronization primitives. SuperH implementation.
3 /* Copyright (C) 2002, 2007 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
9 details. */
11 #ifndef __SYSDEP_LOCKS_H__
12 #define __SYSDEP_LOCKS_H__
14 typedef size_t obj_addr_t; /* Integer type big enough for object */
15 /* address. */
17 static unsigned char __cas_lock = 0;
19 inline static void
20 __cas_start_atomic (void)
22 unsigned int val;
25 __asm__ __volatile__ ("tas.b @%1; movt %0"
26 : "=r" (val)
27 : "r" (&__cas_lock)
28 : "memory");
29 while (val == 0);
32 inline static void
33 __cas_end_atomic (void)
35 __asm__ __volatile__ (" " : : : "memory");
36 __cas_lock = 0;
39 inline static bool
40 compare_and_swap (volatile obj_addr_t *addr, obj_addr_t old,
41 obj_addr_t new_val)
43 bool ret;
45 __cas_start_atomic ();
46 if (*addr != old)
47 ret = false;
48 else
50 *addr = new_val;
51 ret = true;
53 __cas_end_atomic ();
55 return ret;
58 inline static void
59 release_set (volatile obj_addr_t *addr, obj_addr_t new_val)
61 __asm__ __volatile__ (" " : : : "memory");
62 *(addr) = new_val;
65 inline static bool
66 compare_and_swap_release (volatile obj_addr_t *addr, obj_addr_t old,
67 obj_addr_t new_val)
69 return compare_and_swap (addr, old, new_val);
72 inline static void
73 read_barrier()
75 __asm__ __volatile__(" " : : : "memory");
78 inline static void
79 write_barrier()
81 __asm__ __volatile__(" " : : : "memory");
84 #endif /* ! __SYSDEP_LOCKS_H__ */