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