FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
stdatomic.h
Go to the documentation of this file.
1 /*
2  * This file is part of FFmpeg.
3  *
4  * FFmpeg is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * FFmpeg is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with FFmpeg; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
19 #ifndef COMPAT_ATOMICS_SUNCC_STDATOMIC_H
20 #define COMPAT_ATOMICS_SUNCC_STDATOMIC_H
21 
22 #include <atomic.h>
23 #include <mbarrier.h>
24 #include <stddef.h>
25 #include <stdint.h>
26 
27 #define ATOMIC_FLAG_INIT 0
28 
29 #define ATOMIC_VAR_INIT(value) (value)
30 
31 #define atomic_init(obj, value) \
32 do { \
33  *(obj) = (value); \
34 } while(0)
35 
36 #define kill_dependency(y) ((void)0)
37 
38 #define atomic_thread_fence(order) \
39  __machine_rw_barrier();
40 
41 #define atomic_signal_fence(order) \
42  ((void)0)
43 
44 #define atomic_is_lock_free(obj) 0
45 
46 typedef intptr_t atomic_flag;
47 typedef intptr_t atomic_bool;
48 typedef intptr_t atomic_char;
49 typedef intptr_t atomic_schar;
50 typedef intptr_t atomic_uchar;
51 typedef intptr_t atomic_short;
52 typedef intptr_t atomic_ushort;
53 typedef intptr_t atomic_int;
54 typedef intptr_t atomic_uint;
55 typedef intptr_t atomic_long;
56 typedef intptr_t atomic_ulong;
57 typedef intptr_t atomic_llong;
58 typedef intptr_t atomic_ullong;
59 typedef intptr_t atomic_wchar_t;
60 typedef intptr_t atomic_int_least8_t;
61 typedef intptr_t atomic_uint_least8_t;
62 typedef intptr_t atomic_int_least16_t;
63 typedef intptr_t atomic_uint_least16_t;
64 typedef intptr_t atomic_int_least32_t;
65 typedef intptr_t atomic_uint_least32_t;
66 typedef intptr_t atomic_int_least64_t;
67 typedef intptr_t atomic_uint_least64_t;
68 typedef intptr_t atomic_int_fast8_t;
69 typedef intptr_t atomic_uint_fast8_t;
70 typedef intptr_t atomic_int_fast16_t;
71 typedef intptr_t atomic_uint_fast16_t;
72 typedef intptr_t atomic_int_fast32_t;
73 typedef intptr_t atomic_uint_fast32_t;
74 typedef intptr_t atomic_int_fast64_t;
75 typedef intptr_t atomic_uint_fast64_t;
76 typedef intptr_t atomic_intptr_t;
77 typedef intptr_t atomic_uintptr_t;
78 typedef intptr_t atomic_size_t;
79 typedef intptr_t atomic_ptrdiff_t;
80 typedef intptr_t atomic_intmax_t;
81 typedef intptr_t atomic_uintmax_t;
82 
83 static inline void atomic_store(intptr_t *object, intptr_t desired)
84 {
85  *object = desired;
86  __machine_rw_barrier();
87 }
88 
89 #define atomic_store_explicit(object, desired, order) \
90  atomic_store(object, desired)
91 
92 static inline intptr_t atomic_load(intptr_t *object)
93 {
94  __machine_rw_barrier();
95  return *object;
96 }
97 
98 #define atomic_load_explicit(object, order) \
99  atomic_load(object)
100 
101 #define atomic_exchange(object, desired) \
102  atomic_swap_ptr(object, desired)
103 
104 #define atomic_exchange_explicit(object, desired, order) \
105  atomic_exchange(object, desired)
106 
107 static inline int atomic_compare_exchange_strong(intptr_t *object, intptr_t *expected,
108  intptr_t desired)
109 {
110  intptr_t old = *expected;
111  *expected = (intptr_t)atomic_cas_ptr(object, (void *)old, (void *)desired);
112  return *expected == old;
113 }
114 
115 #define atomic_compare_exchange_strong_explicit(object, expected, desired, success, failure) \
116  atomic_compare_exchange_strong(object, expected, desired)
117 
118 #define atomic_compare_exchange_weak(object, expected, desired) \
119  atomic_compare_exchange_strong(object, expected, desired)
120 
121 #define atomic_compare_exchange_weak_explicit(object, expected, desired, success, failure) \
122  atomic_compare_exchange_weak(object, expected, desired)
123 
124 static inline intptr_t atomic_fetch_add(intptr_t *object, intptr_t operand)
125 {
126  return atomic_add_ptr_nv(object, operand) - operand;
127 }
128 
129 #define atomic_fetch_sub(object, operand) \
130  atomic_fetch_add(object, -(operand))
131 
132 static inline intptr_t atomic_fetch_or(intptr_t *object, intptr_t operand)
133 {
134  intptr_t old;
135  do {
136  old = atomic_load(object);
137  } while (!atomic_compare_exchange_strong(object, old, old | operand));
138  return old;
139 }
140 
141 static inline intptr_t atomic_fetch_xor(intptr_t *object, intptr_t operand)
142 {
143  intptr_t old;
144  do {
145  old = atomic_load(object);
146  } while (!atomic_compare_exchange_strong(object, old, old ^ operand));
147  return old;
148 }
149 
150 static inline intptr_t atomic_fetch_and(intptr_t *object, intptr_t operand)
151 {
152  intptr_t old;
153  do {
154  old = atomic_load(object);
155  } while (!atomic_compare_exchange_strong(object, old, old & operand));
156  return old;
157 }
158 
159 #define atomic_fetch_add_explicit(object, operand, order) \
160  atomic_fetch_add(object, operand)
161 
162 #define atomic_fetch_sub_explicit(object, operand, order) \
163  atomic_fetch_sub(object, operand)
164 
165 #define atomic_fetch_or_explicit(object, operand, order) \
166  atomic_fetch_or(object, operand)
167 
168 #define atomic_fetch_xor_explicit(object, operand, order) \
169  atomic_fetch_xor(object, operand)
170 
171 #define atomic_fetch_and_explicit(object, operand, order) \
172  atomic_fetch_and(object, operand)
173 
174 #define atomic_flag_test_and_set(object) \
175  atomic_exchange(object, 1)
176 
177 #define atomic_flag_test_and_set_explicit(object, order) \
178  atomic_flag_test_and_set(object)
179 
180 #define atomic_flag_clear(object) \
181  atomic_store(object, 0)
182 
183 #define atomic_flag_clear_explicit(object, order) \
184  atomic_flag_clear(object)
185 
186 #endif /* COMPAT_ATOMICS_SUNCC_STDATOMIC_H */
intptr_t atomic_flag
Definition: stdatomic.h:48
intptr_t atomic_bool
Definition: stdatomic.h:49
static intptr_t atomic_load(intptr_t *object)
Definition: stdatomic.h:92
intptr_t atomic_uint_fast8_t
Definition: stdatomic.h:71
intptr_t atomic_ushort
Definition: stdatomic.h:54
intptr_t atomic_int
Definition: stdatomic.h:55
intptr_t atomic_int_least8_t
Definition: stdatomic.h:62
intptr_t atomic_long
Definition: stdatomic.h:57
intptr_t atomic_int_least32_t
Definition: stdatomic.h:66
intptr_t atomic_int_fast16_t
Definition: stdatomic.h:72
static intptr_t atomic_fetch_or(intptr_t *object, intptr_t operand)
Definition: stdatomic.h:132
intptr_t atomic_uintptr_t
Definition: stdatomic.h:79
intptr_t atomic_size_t
Definition: stdatomic.h:80
intptr_t atomic_int_fast32_t
Definition: stdatomic.h:74
static void atomic_store(intptr_t *object, intptr_t desired)
Definition: stdatomic.h:83
static intptr_t atomic_fetch_add(intptr_t *object, intptr_t operand)
Definition: stdatomic.h:124
intptr_t atomic_schar
Definition: stdatomic.h:51
intptr_t atomic_llong
Definition: stdatomic.h:59
intptr_t atomic_int_fast8_t
Definition: stdatomic.h:70
intptr_t atomic_ulong
Definition: stdatomic.h:58
static intptr_t atomic_fetch_xor(intptr_t *object, intptr_t operand)
Definition: stdatomic.h:141
intptr_t atomic_uint_fast16_t
Definition: stdatomic.h:73
static intptr_t atomic_fetch_and(intptr_t *object, intptr_t operand)
Definition: stdatomic.h:150
intptr_t atomic_int_least16_t
Definition: stdatomic.h:64
intptr_t atomic_uint
Definition: stdatomic.h:56
intptr_t atomic_uint_fast32_t
Definition: stdatomic.h:75
intptr_t atomic_uint_least32_t
Definition: stdatomic.h:67
intptr_t atomic_int_fast64_t
Definition: stdatomic.h:76
intptr_t atomic_uchar
Definition: stdatomic.h:52
intptr_t atomic_short
Definition: stdatomic.h:53
intptr_t atomic_uint_least16_t
Definition: stdatomic.h:65
intptr_t atomic_intptr_t
Definition: stdatomic.h:78
intptr_t atomic_intmax_t
Definition: stdatomic.h:82
static int atomic_compare_exchange_strong(intptr_t *object, intptr_t *expected, intptr_t desired)
Definition: stdatomic.h:107
intptr_t atomic_uint_fast64_t
Definition: stdatomic.h:77
intptr_t atomic_ullong
Definition: stdatomic.h:60
intptr_t atomic_uintmax_t
Definition: stdatomic.h:83
intptr_t atomic_int_least64_t
Definition: stdatomic.h:68
intptr_t atomic_char
Definition: stdatomic.h:50
intptr_t atomic_ptrdiff_t
Definition: stdatomic.h:81
intptr_t atomic_wchar_t
Definition: stdatomic.h:61
intptr_t atomic_uint_least8_t
Definition: stdatomic.h:63
intptr_t atomic_uint_least64_t
Definition: stdatomic.h:69