PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
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-2017, 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_COMPARE_EXCHANGE_U64
91 static inline bool
93  uint64 *expected, uint64 newval)
94 {
95  bool ret;
96  uint64 current;
97 
98  current = atomic_cas_64(&ptr->value, *expected, newval);
99  ret = current == *expected;
100  *expected = current;
101  return ret;
102 }
103 
104 #endif /* HAVE_ATOMIC_H */
105 
106 #endif /* defined(HAVE_ATOMICS) */
struct pg_atomic_uint32 pg_atomic_uint32
bool pg_atomic_compare_exchange_u64_impl(volatile pg_atomic_uint64 *ptr, uint64 *expected, uint64 newval)
Definition: atomics.c:183
struct pg_atomic_uint64 pg_atomic_uint64
bool pg_atomic_compare_exchange_u32_impl(volatile pg_atomic_uint32 *ptr, uint32 *expected, uint32 newval)
Definition: atomics.c:120
volatile uint32 value
Definition: fallback.h:100
unsigned int uint32
Definition: c.h:258
volatile uint64 value
Definition: fallback.h:118
#define newval