locks.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. typedef size_t obj_addr_t; /* Integer type big enough for object */
  10. /* address. */
  11. inline static bool
  12. compare_and_swap(volatile obj_addr_t *addr,
  13. obj_addr_t old,
  14. obj_addr_t new_val)
  15. {
  16. unsigned long oldval;
  17. __asm__ __volatile__("mov ar.ccv=%4 ;; cmpxchg8.acq %0=%1,%2,ar.ccv"
  18. : "=r"(oldval), "=m"(*addr)
  19. : "r"(new_val), "1"(*addr), "r"(old) : "memory");
  20. return (oldval == old);
  21. }
  22. // The fact that *addr is volatile should cause the compiler to
  23. // automatically generate an st8.rel.
  24. inline static void
  25. release_set(volatile obj_addr_t *addr, obj_addr_t new_val)
  26. {
  27. __asm__ __volatile__(" " : : : "memory");
  28. *(addr) = new_val;
  29. }
  30. inline static bool
  31. compare_and_swap_release(volatile obj_addr_t *addr,
  32. obj_addr_t old,
  33. obj_addr_t new_val)
  34. {
  35. unsigned long oldval;
  36. __asm__ __volatile__("mov ar.ccv=%4 ;; cmpxchg8.rel %0=%1,%2,ar.ccv"
  37. : "=r"(oldval), "=m"(*addr)
  38. : "r"(new_val), "1"(*addr), "r"(old) : "memory");
  39. return (oldval == old);
  40. }
  41. #endif