Debian Codegraph @

src/include/port/atomics/generic-sunpro.h

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