2 * This file is part of FFmpeg.
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.
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.
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
20 * based on vlc_atomic.h from VLC
21 * Copyright (C) 2010 RĂ©mi Denis-Courmont
24 #ifndef COMPAT_ATOMICS_GCC_STDATOMIC_H
25 #define COMPAT_ATOMICS_GCC_STDATOMIC_H
30 #define ATOMIC_FLAG_INIT 0
32 #define ATOMIC_VAR_INIT(value) (value)
34 #define atomic_init(obj, value) \
39 #define kill_dependency(y) ((void)0)
41 #define atomic_thread_fence(order) \
44 #define atomic_signal_fence(order) \
47 #define atomic_is_lock_free(obj) 0
49 typedef _Bool atomic_flag;
50 typedef _Bool atomic_bool;
51 typedef char atomic_char;
52 typedef signed char atomic_schar;
53 typedef unsigned char atomic_uchar;
54 typedef short atomic_short;
55 typedef unsigned short atomic_ushort;
56 typedef int atomic_int;
57 typedef unsigned int atomic_uint;
58 typedef long atomic_long;
59 typedef unsigned long atomic_ulong;
60 typedef long long atomic_llong;
61 typedef unsigned long long atomic_ullong;
62 typedef wchar_t atomic_wchar_t;
63 typedef int_least8_t atomic_int_least8_t;
64 typedef uint_least8_t atomic_uint_least8_t;
65 typedef int_least16_t atomic_int_least16_t;
66 typedef uint_least16_t atomic_uint_least16_t;
67 typedef int_least32_t atomic_int_least32_t;
68 typedef uint_least32_t atomic_uint_least32_t;
69 typedef int_least64_t atomic_int_least64_t;
70 typedef uint_least64_t atomic_uint_least64_t;
71 typedef int_fast8_t atomic_int_fast8_t;
72 typedef uint_fast8_t atomic_uint_fast8_t;
73 typedef int_fast16_t atomic_int_fast16_t;
74 typedef uint_fast16_t atomic_uint_fast16_t;
75 typedef int_fast32_t atomic_int_fast32_t;
76 typedef uint_fast32_t atomic_uint_fast32_t;
77 typedef int_fast64_t atomic_int_fast64_t;
78 typedef uint_fast64_t atomic_uint_fast64_t;
79 typedef intptr_t atomic_intptr_t;
80 typedef uintptr_t atomic_uintptr_t;
81 typedef size_t atomic_size_t;
82 typedef ptrdiff_t atomic_ptrdiff_t;
83 typedef intmax_t atomic_intmax_t;
84 typedef uintmax_t atomic_uintmax_t;
86 #define atomic_store(object, desired) \
88 *(object) = (desired); \
89 __sync_synchronize(); \
92 #define atomic_store_explicit(object, desired, order) \
93 atomic_store(object, desired)
95 #define atomic_load(object) \
96 (__sync_synchronize(), *(object))
98 #define atomic_load_explicit(object, order) \
101 #define atomic_exchange(object, desired) \
103 __typeof__(object) _obj = (object); \
104 __typeof__(*object) _old; \
106 _old = atomic_load(_obj); \
107 while (!__sync_bool_compare_and_swap(_obj, _old, (desired))); \
111 #define atomic_exchange_explicit(object, desired, order) \
112 atomic_exchange(object, desired)
114 #define atomic_compare_exchange_strong(object, expected, desired) \
116 __typeof__(object) _exp = (expected); \
117 __typeof__(*object) _old = *_exp; \
118 *_exp = __sync_val_compare_and_swap((object), _old, (desired)); \
122 #define atomic_compare_exchange_strong_explicit(object, expected, desired, success, failure) \
123 atomic_compare_exchange_strong(object, expected, desired)
125 #define atomic_compare_exchange_weak(object, expected, desired) \
126 atomic_compare_exchange_strong(object, expected, desired)
128 #define atomic_compare_exchange_weak_explicit(object, expected, desired, success, failure) \
129 atomic_compare_exchange_weak(object, expected, desired)
131 #define atomic_fetch_add(object, operand) \
132 __sync_fetch_and_add(object, operand)
134 #define atomic_fetch_add_explicit(object, operand, order) \
135 atomic_fetch_add(object, operand)
137 #define atomic_fetch_sub(object, operand) \
138 __sync_fetch_and_sub(object, operand)
140 #define atomic_fetch_sub_explicit(object, operand, order) \
141 atomic_fetch_sub(object, operand)
143 #define atomic_fetch_or(object, operand) \
144 __sync_fetch_and_or(object, operand)
146 #define atomic_fetch_or_explicit(object, operand, order) \
147 atomic_fetch_or(object, operand)
149 #define atomic_fetch_xor(object, operand) \
150 __sync_fetch_and_xor(object, operand)
152 #define atomic_fetch_xor_explicit(object, operand, order) \
153 atomic_fetch_xor(object, operand)
155 #define atomic_fetch_and(object, operand) \
156 __sync_fetch_and_and(object, operand)
158 #define atomic_fetch_and_explicit(object, operand, order) \
159 atomic_fetch_and(object, operand)
161 #define atomic_flag_test_and_set(object) \
162 atomic_exchange(object, 1)
164 #define atomic_flag_test_and_set_explicit(object, order) \
165 atomic_flag_test_and_set(object)
167 #define atomic_flag_clear(object) \
168 atomic_store(object, 0)
170 #define atomic_flag_clear_explicit(object, order) \
171 atomic_flag_clear(object)
173 #endif /* COMPAT_ATOMICS_GCC_STDATOMIC_H */