locks.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // locks.h - Thread synchronization primitives. m68k implementation.
  2. /* Copyright (C) 2006, 2012 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. /* Integer type big enough for object address. */
  10. typedef size_t obj_addr_t __attribute__ ((aligned (4)));
  11. // Atomically replace *addr by new_val if it was initially equal to old.
  12. // Return true if the comparison succeeded.
  13. // Assumed to have acquire semantics, i.e. later memory operations
  14. // cannot execute before the compare_and_swap finishes.
  15. static inline bool
  16. compare_and_swap(volatile obj_addr_t *addr,
  17. obj_addr_t old, obj_addr_t new_val)
  18. {
  19. return __sync_bool_compare_and_swap (addr, old, new_val);
  20. }
  21. // Ensure that subsequent instructions do not execute on stale
  22. // data that was loaded from memory before the barrier.
  23. // On m68k, the hardware ensures that reads are properly ordered.
  24. static inline void
  25. read_barrier(void)
  26. {
  27. }
  28. // Ensure that prior stores to memory are completed with respect to other
  29. // processors.
  30. static inline void
  31. write_barrier(void)
  32. {
  33. // m68k does not reorder writes. We just need to ensure that gcc also doesn't.
  34. __asm__ __volatile__(" " : : : "memory");
  35. }
  36. // Set *addr to new_val with release semantics, i.e. making sure
  37. // that prior loads and stores complete before this
  38. // assignment.
  39. // On m68k, the hardware shouldn't reorder reads and writes,
  40. // so we just have to convince gcc not to do it either.
  41. static inline void
  42. release_set(volatile obj_addr_t *addr, obj_addr_t new_val)
  43. {
  44. write_barrier ();
  45. *addr = new_val;
  46. }
  47. // Compare_and_swap with release semantics instead of acquire semantics.
  48. // On many architecture, the operation makes both guarantees, so the
  49. // implementation can be the same.
  50. static inline bool
  51. compare_and_swap_release(volatile obj_addr_t *addr,
  52. obj_addr_t old,
  53. obj_addr_t new_val)
  54. {
  55. return compare_and_swap(addr, old, new_val);
  56. }
  57. #endif