You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

180 lines
5.5KB

  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. #ifndef COMPAT_ATOMICS_WIN32_STDATOMIC_H
  19. #define COMPAT_ATOMICS_WIN32_STDATOMIC_H
  20. #include <stddef.h>
  21. #include <stdint.h>
  22. #include <windows.h>
  23. #define ATOMIC_FLAG_INIT 0
  24. #define ATOMIC_VAR_INIT(value) (value)
  25. #define atomic_init(obj, value) \
  26. do { \
  27. *(obj) = (value); \
  28. } while(0)
  29. #define kill_dependency(y) ((void)0)
  30. #define atomic_thread_fence(order) \
  31. MemoryBarrier();
  32. #define atomic_signal_fence(order) \
  33. ((void)0)
  34. #define atomic_is_lock_free(obj) 0
  35. typedef intptr_t atomic_flag;
  36. typedef intptr_t atomic_bool;
  37. typedef intptr_t atomic_char;
  38. typedef intptr_t atomic_schar;
  39. typedef intptr_t atomic_uchar;
  40. typedef intptr_t atomic_short;
  41. typedef intptr_t atomic_ushort;
  42. typedef intptr_t atomic_int;
  43. typedef intptr_t atomic_uint;
  44. typedef intptr_t atomic_long;
  45. typedef intptr_t atomic_ulong;
  46. typedef intptr_t atomic_llong;
  47. typedef intptr_t atomic_ullong;
  48. typedef intptr_t atomic_wchar_t;
  49. typedef intptr_t atomic_int_least8_t;
  50. typedef intptr_t atomic_uint_least8_t;
  51. typedef intptr_t atomic_int_least16_t;
  52. typedef intptr_t atomic_uint_least16_t;
  53. typedef intptr_t atomic_int_least32_t;
  54. typedef intptr_t atomic_uint_least32_t;
  55. typedef intptr_t atomic_int_least64_t;
  56. typedef intptr_t atomic_uint_least64_t;
  57. typedef intptr_t atomic_int_fast8_t;
  58. typedef intptr_t atomic_uint_fast8_t;
  59. typedef intptr_t atomic_int_fast16_t;
  60. typedef intptr_t atomic_uint_fast16_t;
  61. typedef intptr_t atomic_int_fast32_t;
  62. typedef intptr_t atomic_uint_fast32_t;
  63. typedef intptr_t atomic_int_fast64_t;
  64. typedef intptr_t atomic_uint_fast64_t;
  65. typedef intptr_t atomic_intptr_t;
  66. typedef intptr_t atomic_uintptr_t;
  67. typedef intptr_t atomic_size_t;
  68. typedef intptr_t atomic_ptrdiff_t;
  69. typedef intptr_t atomic_intmax_t;
  70. typedef intptr_t atomic_uintmax_t;
  71. #define atomic_store(object, desired) \
  72. do { \
  73. *(object) = (desired); \
  74. MemoryBarrier(); \
  75. } while (0)
  76. #define atomic_store_explicit(object, desired, order) \
  77. atomic_store(object, desired)
  78. #define atomic_load(object) \
  79. (MemoryBarrier(), *(object))
  80. #define atomic_load_explicit(object, order) \
  81. atomic_load(object)
  82. #define atomic_exchange(object, desired) \
  83. InterlockedExchangePointer(object, desired);
  84. #define atomic_exchange_explicit(object, desired, order) \
  85. atomic_exchange(object, desired)
  86. static inline int atomic_compare_exchange_strong(intptr_t *object, intptr_t *expected,
  87. intptr_t desired)
  88. {
  89. intptr_t old = *expected;
  90. *expected = InterlockedCompareExchangePointer(object, desired, old);
  91. return *expected == old;
  92. }
  93. #define atomic_compare_exchange_strong_explicit(object, expected, desired, success, failure) \
  94. atomic_compare_exchange_strong(object, expected, desired)
  95. #define atomic_compare_exchange_weak(object, expected, desired) \
  96. atomic_compare_exchange_strong(object, expected, desired)
  97. #define atomic_compare_exchange_weak_explicit(object, expected, desired, success, failure) \
  98. atomic_compare_exchange_weak(object, expected, desired)
  99. #ifdef _WIN64
  100. #define atomic_fetch_add(object, operand) \
  101. InterlockedExchangeAdd64(object, operand)
  102. #define atomic_fetch_sub(object, operand) \
  103. InterlockedExchangeAdd64(object, -(operand))
  104. #define atomic_fetch_or(object, operand) \
  105. InterlockedOr64(object, operand)
  106. #define atomic_fetch_xor(object, operand) \
  107. InterlockedXor64(object, operand)
  108. #define atomic_fetch_and(object, operand) \
  109. InterlockedAnd64(object, operand)
  110. #else
  111. #define atomic_fetch_add(object, operand) \
  112. InterlockedExchangeAdd(object, operand)
  113. #define atomic_fetch_sub(object, operand) \
  114. InterlockedExchangeAdd(object, -(operand))
  115. #define atomic_fetch_or(object, operand) \
  116. InterlockedOr(object, operand)
  117. #define atomic_fetch_xor(object, operand) \
  118. InterlockedXor(object, operand)
  119. #define atomic_fetch_and(object, operand) \
  120. InterlockedAnd(object, operand)
  121. #endif /* _WIN64 */
  122. #define atomic_fetch_add_explicit(object, operand, order) \
  123. atomic_fetch_add(object, operand)
  124. #define atomic_fetch_sub_explicit(object, operand, order) \
  125. atomic_fetch_sub(object, operand)
  126. #define atomic_fetch_or_explicit(object, operand, order) \
  127. atomic_fetch_or(object, operand)
  128. #define atomic_fetch_xor_explicit(object, operand, order) \
  129. atomic_fetch_xor(object, operand)
  130. #define atomic_fetch_and_explicit(object, operand, order) \
  131. atomic_fetch_and(object, operand)
  132. #define atomic_flag_test_and_set(object) \
  133. atomic_exchange(object, 1)
  134. #define atomic_flag_test_and_set_explicit(object, order) \
  135. atomic_flag_test_and_set(object)
  136. #define atomic_flag_clear(object) \
  137. atomic_store(object, 0)
  138. #define atomic_flag_clear_explicit(object, order) \
  139. atomic_flag_clear(object)
  140. #endif /* COMPAT_ATOMICS_WIN32_STDATOMIC_H */