FFmpeg
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 /*
20  * based on vlc_atomic.h from VLC
21  * Copyright (C) 2010 RĂ©mi Denis-Courmont
22  */
23 
24 #ifndef COMPAT_ATOMICS_PTHREAD_STDATOMIC_H
25 #define COMPAT_ATOMICS_PTHREAD_STDATOMIC_H
26 
27 #include <stdint.h>
28 
29 #define ATOMIC_FLAG_INIT 0
30 
31 #define ATOMIC_VAR_INIT(value) (value)
32 
33 #define atomic_init(obj, value) \
34 do { \
35  *(obj) = (value); \
36 } while(0)
37 
38 #define kill_dependency(y) ((void)0)
39 
40 #define atomic_signal_fence(order) \
41  ((void)0)
42 
43 #define atomic_is_lock_free(obj) 0
44 
45 typedef intptr_t atomic_flag;
46 typedef intptr_t atomic_bool;
47 typedef intptr_t atomic_char;
48 typedef intptr_t atomic_schar;
49 typedef intptr_t atomic_uchar;
50 typedef intptr_t atomic_short;
51 typedef intptr_t atomic_ushort;
52 typedef intptr_t atomic_int;
53 typedef intptr_t atomic_uint;
54 typedef intptr_t atomic_long;
55 typedef intptr_t atomic_ulong;
56 typedef intptr_t atomic_llong;
57 typedef intptr_t atomic_ullong;
58 typedef intptr_t atomic_wchar_t;
59 typedef intptr_t atomic_int_least8_t;
60 typedef intptr_t atomic_uint_least8_t;
61 typedef intptr_t atomic_int_least16_t;
62 typedef intptr_t atomic_uint_least16_t;
63 typedef intptr_t atomic_int_least32_t;
64 typedef intptr_t atomic_uint_least32_t;
65 typedef intptr_t atomic_int_least64_t;
66 typedef intptr_t atomic_uint_least64_t;
67 typedef intptr_t atomic_int_fast8_t;
68 typedef intptr_t atomic_uint_fast8_t;
69 typedef intptr_t atomic_int_fast16_t;
70 typedef intptr_t atomic_uint_fast16_t;
71 typedef intptr_t atomic_int_fast32_t;
72 typedef intptr_t atomic_uint_fast32_t;
73 typedef intptr_t atomic_int_fast64_t;
74 typedef intptr_t atomic_uint_fast64_t;
75 typedef intptr_t atomic_intptr_t;
76 typedef intptr_t atomic_uintptr_t;
77 typedef intptr_t atomic_size_t;
78 typedef intptr_t atomic_ptrdiff_t;
79 typedef intptr_t atomic_intmax_t;
80 typedef intptr_t atomic_uintmax_t;
81 
82 void avpriv_atomic_lock(void);
83 void avpriv_atomic_unlock(void);
84 
85 static inline void atomic_thread_fence(int order)
86 {
89 }
90 
91 static inline void atomic_store(intptr_t *object, intptr_t desired)
92 {
94  *object = desired;
96 }
97 
98 #define atomic_store_explicit(object, desired, order) \
99  atomic_store(object, desired)
100 
101 static inline intptr_t atomic_load(intptr_t *object)
102 {
103  intptr_t ret;
105  ret = *object;
107  return ret;
108 }
109 
110 #define atomic_load_explicit(object, order) \
111  atomic_load(object)
112 
113 static inline intptr_t atomic_exchange(intptr_t *object, intptr_t desired)
114 {
115  intptr_t ret;
117  ret = *object;
118  *object = desired;
120  return ret;
121 }
122 
123 #define atomic_exchange_explicit(object, desired, order) \
124  atomic_exchange(object, desired)
125 
126 static inline int atomic_compare_exchange_strong(intptr_t *object, intptr_t *expected,
127  intptr_t desired)
128 {
129  int ret;
131  if (*object == *expected) {
132  ret = 1;
133  *object = desired;
134  } else {
135  ret = 0;
136  *expected = *object;
137  }
139  return ret;
140 }
141 
142 #define atomic_compare_exchange_strong_explicit(object, expected, desired, success, failure) \
143  atomic_compare_exchange_strong(object, expected, desired)
144 
145 #define atomic_compare_exchange_weak(object, expected, desired) \
146  atomic_compare_exchange_strong(object, expected, desired)
147 
148 #define atomic_compare_exchange_weak_explicit(object, expected, desired, success, failure) \
149  atomic_compare_exchange_weak(object, expected, desired)
150 
151 #define FETCH_MODIFY(opname, op) \
152 static inline intptr_t atomic_fetch_ ## opname(intptr_t *object, intptr_t operand) \
153 { \
154  intptr_t ret; \
155  avpriv_atomic_lock(); \
156  ret = *object; \
157  *object = *object op operand; \
158  avpriv_atomic_unlock(); \
159  return ret; \
160 }
161 
162 FETCH_MODIFY(add, +)
163 FETCH_MODIFY(sub, -)
164 FETCH_MODIFY(or, |)
165 FETCH_MODIFY(xor, ^)
166 FETCH_MODIFY(and, &)
167 
168 #undef FETCH_MODIFY
169 
170 #define atomic_fetch_add_explicit(object, operand, order) \
171  atomic_fetch_add(object, operand)
172 
173 #define atomic_fetch_sub_explicit(object, operand, order) \
174  atomic_fetch_sub(object, operand)
175 
176 #define atomic_fetch_or_explicit(object, operand, order) \
177  atomic_fetch_or(object, operand)
178 
179 #define atomic_fetch_xor_explicit(object, operand, order) \
180  atomic_fetch_xor(object, operand)
181 
182 #define atomic_fetch_and_explicit(object, operand, order) \
183  atomic_fetch_and(object, operand)
184 
185 #define atomic_flag_test_and_set(object) \
186  atomic_exchange(object, 1)
187 
188 #define atomic_flag_test_and_set_explicit(object, order) \
189  atomic_flag_test_and_set(object)
190 
191 #define atomic_flag_clear(object) \
192  atomic_store(object, 0)
193 
194 #define atomic_flag_clear_explicit(object, order) \
195  atomic_flag_clear(object)
196 
197 #endif /* COMPAT_ATOMICS_PTHREAD_STDATOMIC_H */
atomic_char
intptr_t atomic_char
Definition: stdatomic.h:50
atomic_ptrdiff_t
intptr_t atomic_ptrdiff_t
Definition: stdatomic.h:81
atomic_wchar_t
intptr_t atomic_wchar_t
Definition: stdatomic.h:61
sub
static float sub(float src0, float src1)
Definition: dnn_backend_native_layer_mathbinary.c:31
atomic_uint_least8_t
intptr_t atomic_uint_least8_t
Definition: stdatomic.h:63
atomic_ushort
intptr_t atomic_ushort
Definition: stdatomic.h:54
avpriv_atomic_lock
void avpriv_atomic_lock(void)
Definition: stdatomic.c:31
atomic_bool
intptr_t atomic_bool
Definition: stdatomic.h:49
atomic_uint_fast8_t
intptr_t atomic_uint_fast8_t
Definition: stdatomic.h:71
atomic_int
intptr_t atomic_int
Definition: stdatomic.h:55
atomic_int_least8_t
intptr_t atomic_int_least8_t
Definition: stdatomic.h:62
atomic_flag
intptr_t atomic_flag
Definition: stdatomic.h:48
atomic_int_fast32_t
intptr_t atomic_int_fast32_t
Definition: stdatomic.h:74
atomic_long
intptr_t atomic_long
Definition: stdatomic.h:57
atomic_thread_fence
static void atomic_thread_fence(int order)
Definition: stdatomic.h:85
atomic_int_fast16_t
intptr_t atomic_int_fast16_t
Definition: stdatomic.h:72
atomic_uintptr_t
intptr_t atomic_uintptr_t
Definition: stdatomic.h:79
atomic_store
static void atomic_store(intptr_t *object, intptr_t desired)
Definition: stdatomic.h:91
atomic_size_t
intptr_t atomic_size_t
Definition: stdatomic.h:80
atomic_llong
intptr_t atomic_llong
Definition: stdatomic.h:59
atomic_int_least32_t
intptr_t atomic_int_least32_t
Definition: stdatomic.h:66
atomic_load
static intptr_t atomic_load(intptr_t *object)
Definition: stdatomic.h:101
atomic_int_fast8_t
intptr_t atomic_int_fast8_t
Definition: stdatomic.h:70
atomic_schar
intptr_t atomic_schar
Definition: stdatomic.h:51
atomic_compare_exchange_strong
static int atomic_compare_exchange_strong(intptr_t *object, intptr_t *expected, intptr_t desired)
Definition: stdatomic.h:126
atomic_ulong
intptr_t atomic_ulong
Definition: stdatomic.h:58
avpriv_atomic_unlock
void avpriv_atomic_unlock(void)
Definition: stdatomic.c:36
atomic_uint_fast16_t
intptr_t atomic_uint_fast16_t
Definition: stdatomic.h:73
atomic_int_least16_t
intptr_t atomic_int_least16_t
Definition: stdatomic.h:64
atomic_uchar
intptr_t atomic_uchar
Definition: stdatomic.h:52
atomic_uint_least16_t
intptr_t atomic_uint_least16_t
Definition: stdatomic.h:65
atomic_intmax_t
intptr_t atomic_intmax_t
Definition: stdatomic.h:82
atomic_ullong
intptr_t atomic_ullong
Definition: stdatomic.h:60
atomic_uint_fast32_t
intptr_t atomic_uint_fast32_t
Definition: stdatomic.h:75
atomic_uint_least32_t
intptr_t atomic_uint_least32_t
Definition: stdatomic.h:67
atomic_int_least64_t
intptr_t atomic_int_least64_t
Definition: stdatomic.h:68
atomic_int_fast64_t
intptr_t atomic_int_fast64_t
Definition: stdatomic.h:76
ret
ret
Definition: filter_design.txt:187
FETCH_MODIFY
#define FETCH_MODIFY(opname, op)
Definition: stdatomic.h:151
atomic_intptr_t
intptr_t atomic_intptr_t
Definition: stdatomic.h:78
atomic_short
intptr_t atomic_short
Definition: stdatomic.h:53
atomic_uint
intptr_t atomic_uint
Definition: stdatomic.h:56
atomic_uint_fast64_t
intptr_t atomic_uint_fast64_t
Definition: stdatomic.h:77
add
static float add(float src0, float src1)
Definition: dnn_backend_native_layer_mathbinary.c:35
atomic_uintmax_t
intptr_t atomic_uintmax_t
Definition: stdatomic.h:83
atomic_exchange
static intptr_t atomic_exchange(intptr_t *object, intptr_t desired)
Definition: stdatomic.h:113
atomic_uint_least64_t
intptr_t atomic_uint_least64_t
Definition: stdatomic.h:69