PostgreSQL Source Code  git master
generic-sunpro.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * generic-sunpro.h
4  * Atomic operations for solaris' CC
5  *
6  * Portions Copyright (c) 2013-2024, 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 
20 #if defined(HAVE_ATOMICS)
21 
22 #ifdef HAVE_MBARRIER_H
23 #include <mbarrier.h>
24 
25 #define pg_compiler_barrier_impl() __compiler_barrier()
26 
27 #ifndef pg_memory_barrier_impl
28 /*
29  * Despite the name this is actually a full barrier. Expanding to mfence/
30  * membar #StoreStore | #LoadStore | #StoreLoad | #LoadLoad on x86/sparc
31  * respectively.
32  */
33 # define pg_memory_barrier_impl() __machine_rw_barrier()
34 #endif
35 #ifndef pg_read_barrier_impl
36 # define pg_read_barrier_impl() __machine_r_barrier()
37 #endif
38 #ifndef pg_write_barrier_impl
39 # define pg_write_barrier_impl() __machine_w_barrier()
40 #endif
41 
42 #endif /* HAVE_MBARRIER_H */
43 
44 /* Older versions of the compiler don't have atomic.h... */
45 #ifdef HAVE_ATOMIC_H
46 
47 #include <atomic.h>
48 
49 #define PG_HAVE_ATOMIC_U32_SUPPORT
50 typedef struct pg_atomic_uint32
51 {
52  volatile uint32 value;
54 
55 #define PG_HAVE_ATOMIC_U64_SUPPORT
56 typedef struct pg_atomic_uint64
57 {
58  /*
59  * Syntax to enforce variable alignment should be supported by versions
60  * supporting atomic.h, but it's hard to find accurate documentation. If
61  * it proves to be a problem, we'll have to add more version checks for 64
62  * bit support.
63  */
64  volatile uint64 value pg_attribute_aligned(8);
66 
67 #endif /* HAVE_ATOMIC_H */
68 
69 #endif /* defined(HAVE_ATOMICS) */
70 
71 
72 #if defined(HAVE_ATOMICS)
73 
74 #ifdef HAVE_ATOMIC_H
75 
76 #define PG_HAVE_ATOMIC_COMPARE_EXCHANGE_U32
77 static inline bool
79  uint32 *expected, uint32 newval)
80 {
81  bool ret;
82  uint32 current;
83 
84  current = atomic_cas_32(&ptr->value, *expected, newval);
85  ret = current == *expected;
86  *expected = current;
87  return ret;
88 }
89 
90 #define PG_HAVE_ATOMIC_EXCHANGE_U32
91 static inline uint32
92 pg_atomic_exchange_u32_impl(volatile pg_atomic_uint32 *ptr, uint32 newval)
93 {
94  return atomic_swap_32(&ptr->value, newval);
95 }
96 
97 #define PG_HAVE_ATOMIC_COMPARE_EXCHANGE_U64
98 static inline bool
100  uint64 *expected, uint64 newval)
101 {
102  bool ret;
103  uint64 current;
104 
105  current = atomic_cas_64(&ptr->value, *expected, newval);
106  ret = current == *expected;
107  *expected = current;
108  return ret;
109 }
110 
111 #define PG_HAVE_ATOMIC_EXCHANGE_U64
112 static inline uint64
113 pg_atomic_exchange_u64_impl(volatile pg_atomic_uint64 *ptr, uint64 newval)
114 {
115  return atomic_swap_64(&ptr->value, newval);
116 }
117 
118 #endif /* HAVE_ATOMIC_H */
119 
120 #endif /* defined(HAVE_ATOMICS) */
struct pg_atomic_uint32 pg_atomic_uint32
bool pg_atomic_compare_exchange_u32_impl(volatile pg_atomic_uint32 *ptr, uint32 *expected, uint32 newval)
Definition: atomics.c:137
bool pg_atomic_compare_exchange_u64_impl(volatile pg_atomic_uint64 *ptr, uint64 *expected, uint64 newval)
Definition: atomics.c:200
unsigned int uint32
Definition: c.h:506
struct pg_atomic_uint64 pg_atomic_uint64
#define newval
volatile uint32 value
Definition: arch-ppc.h:31
volatile uint64 value
Definition: fallback.h:119