2
0

generic-sunpro.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*-------------------------------------------------------------------------
  2. *
  3. * generic-sunpro.h
  4. * Atomic operations for solaris' CC
  5. *
  6. * Portions Copyright (c) 2013-2022, PostgreSQL Global Development Group
  7. *
  8. * NOTES:
  9. *
  10. * Documentation:
  11. * * manpage for atomic_cas(3C)
  12. * http://www.unix.com/man-page/opensolaris/3c/atomic_cas/
  13. * http://docs.oracle.com/cd/E23824_01/html/821-1465/atomic-cas-3c.html
  14. *
  15. * src/include/port/atomics/generic-sunpro.h
  16. *
  17. * -------------------------------------------------------------------------
  18. */
  19. #if defined(HAVE_ATOMICS)
  20. #ifdef HAVE_MBARRIER_H
  21. #include <mbarrier.h>
  22. #define pg_compiler_barrier_impl() __compiler_barrier()
  23. #ifndef pg_memory_barrier_impl
  24. /*
  25. * Despite the name this is actually a full barrier. Expanding to mfence/
  26. * membar #StoreStore | #LoadStore | #StoreLoad | #LoadLoad on x86/sparc
  27. * respectively.
  28. */
  29. # define pg_memory_barrier_impl() __machine_rw_barrier()
  30. #endif
  31. #ifndef pg_read_barrier_impl
  32. # define pg_read_barrier_impl() __machine_r_barrier()
  33. #endif
  34. #ifndef pg_write_barrier_impl
  35. # define pg_write_barrier_impl() __machine_w_barrier()
  36. #endif
  37. #endif /* HAVE_MBARRIER_H */
  38. /* Older versions of the compiler don't have atomic.h... */
  39. #ifdef HAVE_ATOMIC_H
  40. #include <atomic.h>
  41. #define PG_HAVE_ATOMIC_U32_SUPPORT
  42. typedef struct pg_atomic_uint32
  43. {
  44. volatile uint32 value;
  45. } pg_atomic_uint32;
  46. #define PG_HAVE_ATOMIC_U64_SUPPORT
  47. typedef struct pg_atomic_uint64
  48. {
  49. /*
  50. * Syntax to enforce variable alignment should be supported by versions
  51. * supporting atomic.h, but it's hard to find accurate documentation. If
  52. * it proves to be a problem, we'll have to add more version checks for 64
  53. * bit support.
  54. */
  55. volatile uint64 value pg_attribute_aligned(8);
  56. } pg_atomic_uint64;
  57. #endif /* HAVE_ATOMIC_H */
  58. #endif /* defined(HAVE_ATOMICS) */
  59. #if defined(HAVE_ATOMICS)
  60. #ifdef HAVE_ATOMIC_H
  61. #define PG_HAVE_ATOMIC_COMPARE_EXCHANGE_U32
  62. static inline bool
  63. pg_atomic_compare_exchange_u32_impl(volatile pg_atomic_uint32 *ptr,
  64. uint32 *expected, uint32 newval)
  65. {
  66. bool ret;
  67. uint32 current;
  68. current = atomic_cas_32(&ptr->value, *expected, newval);
  69. ret = current == *expected;
  70. *expected = current;
  71. return ret;
  72. }
  73. #define PG_HAVE_ATOMIC_COMPARE_EXCHANGE_U64
  74. static inline bool
  75. pg_atomic_compare_exchange_u64_impl(volatile pg_atomic_uint64 *ptr,
  76. uint64 *expected, uint64 newval)
  77. {
  78. bool ret;
  79. uint64 current;
  80. current = atomic_cas_64(&ptr->value, *expected, newval);
  81. ret = current == *expected;
  82. *expected = current;
  83. return ret;
  84. }
  85. #endif /* HAVE_ATOMIC_H */
  86. #endif /* defined(HAVE_ATOMICS) */