stdatomic.h 5.3 KB

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