locks.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // locks.h - Thread synchronization primitives. IA64 implementation.
  2. /* Copyright (C) 2002 Free Software Foundation
  3. This file is part of libgcj.
  4. This software is copyrighted work licensed under the terms of the
  5. Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
  6. details. */
  7. #ifndef __SYSDEP_LOCKS_H__
  8. #define __SYSDEP_LOCKS_H__
  9. #include <ia64intrin.h>
  10. typedef size_t obj_addr_t; /* Integer type big enough for object */
  11. /* address. */
  12. inline static bool
  13. compare_and_swap(volatile obj_addr_t *addr,
  14. obj_addr_t old,
  15. obj_addr_t new_val)
  16. {
  17. return __sync_bool_compare_and_swap (addr, old, new_val);
  18. }
  19. // The fact that *addr is volatile should cause the compiler to
  20. // automatically generate an st8.rel.
  21. inline static void
  22. release_set(volatile obj_addr_t *addr, obj_addr_t new_val)
  23. {
  24. __asm__ __volatile__("" : : : "memory");
  25. *(addr) = new_val;
  26. }
  27. inline static bool
  28. compare_and_swap_release(volatile obj_addr_t *addr,
  29. obj_addr_t old,
  30. obj_addr_t new_val)
  31. {
  32. register unsigned long ar_ccv __asm__("ar.ccv") = old;
  33. unsigned long out;
  34. __asm__ __volatile__("cmpxchg8.rel %0=%1,%2,%4"
  35. : "=r"(out), "=m"(*addr)
  36. : "r"(new_val), "m"(*addr), "d"(ar_ccv) : "memory");
  37. return (out == old);
  38. }
  39. inline static void
  40. read_barrier()
  41. {
  42. __sync_synchronize ();
  43. }
  44. inline static void
  45. write_barrier()
  46. {
  47. __sync_synchronize ();
  48. }
  49. #endif