Atomic-c-api.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. #pragma once
  2. #include "il2cpp-config-platforms.h"
  3. #include <stdint.h>
  4. #if defined(__cplusplus)
  5. extern "C" {
  6. #endif
  7. static inline int32_t UnityPalCompareExchange(volatile int32_t* dest, int32_t exchange, int32_t comparand);
  8. static inline int64_t UnityPalCompareExchange64(volatile int64_t* dest, int64_t exchange, int64_t comparand);
  9. static inline void* UnityPalCompareExchangePointer(void* volatile* dest, void* exchange, void* comparand);
  10. static inline int32_t UnityPalAdd(volatile int32_t* location1, int32_t value);
  11. static inline int64_t UnityPalAdd64(volatile int64_t* location1, int64_t value);
  12. static inline int32_t UnityPalIncrement(volatile int32_t* value);
  13. static inline int64_t UnityPalIncrement64(volatile int64_t* value);
  14. static inline int32_t UnityPalDecrement(volatile int32_t* value);
  15. static inline int64_t UnityPalDecrement64(volatile int64_t* value);
  16. static inline int32_t UnityPalExchange(volatile int32_t* dest, int32_t exchange);
  17. static inline int64_t UnityPalExchange64(volatile int64_t* dest, int64_t exchange);
  18. static inline void* UnityPalExchangePointer(void* volatile* dest, void* exchange);
  19. static inline int64_t UnityPalRead64(volatile int64_t* addr);
  20. #if defined(__cplusplus)
  21. }
  22. #endif
  23. #if !IL2CPP_SUPPORT_THREADS
  24. inline int32_t UnityPalAdd(volatile int32_t* location1, int32_t value)
  25. {
  26. return *location1 += value;
  27. }
  28. inline int64_t UnityPalAdd64(volatile int64_t* location1, int64_t value)
  29. {
  30. return *location1 += value;
  31. }
  32. inline int32_t UnityPalIncrement(volatile int32_t* value)
  33. {
  34. return ++(*value);
  35. }
  36. inline int64_t UnityPalIncrement64(volatile int64_t* value)
  37. {
  38. return ++(*value);
  39. }
  40. inline int32_t UnityPalDecrement(volatile int32_t* value)
  41. {
  42. return --(*value);
  43. }
  44. inline int64_t UnityPalDecrement64(volatile int64_t* value)
  45. {
  46. return --(*value);
  47. }
  48. inline int32_t UnityPalCompareExchange(volatile int32_t* dest, int32_t exchange, int32_t comparand)
  49. {
  50. int32_t orig = *dest;
  51. if (*dest == comparand)
  52. *dest = exchange;
  53. return orig;
  54. }
  55. inline int64_t UnityPalCompareExchange64(volatile int64_t* dest, int64_t exchange, int64_t comparand)
  56. {
  57. int64_t orig = *dest;
  58. if (*dest == comparand)
  59. *dest = exchange;
  60. return orig;
  61. }
  62. inline void* UnityPalCompareExchangePointer(void* volatile* dest, void* exchange, void* comparand)
  63. {
  64. void* orig = *dest;
  65. if (*dest == comparand)
  66. *dest = exchange;
  67. return orig;
  68. }
  69. inline int64_t UnityPalExchange64(volatile int64_t* dest, int64_t exchange)
  70. {
  71. int64_t orig = *dest;
  72. *dest = exchange;
  73. return orig;
  74. }
  75. inline int32_t UnityPalExchange(volatile int32_t* dest, int32_t exchange)
  76. {
  77. int32_t orig = *dest;
  78. *dest = exchange;
  79. return orig;
  80. }
  81. inline void* UnityPalExchangePointer(void* volatile* dest, void* exchange)
  82. {
  83. void* orig = *dest;
  84. *dest = exchange;
  85. return orig;
  86. }
  87. int64_t UnityPalRead64(volatile int64_t* addr)
  88. {
  89. return *addr;
  90. }
  91. #elif IL2CPP_TARGET_WINDOWS
  92. #include "Win32/AtomicImpl-c-api.h"
  93. #elif IL2CPP_TARGET_PS4
  94. #include "PS4/AtomicImpl-c-api.h" // has to come earlier than posix
  95. #elif IL2CPP_TARGET_PSP2
  96. #include "PSP2/AtomicImpl-c-api.h"
  97. #elif IL2CPP_TARGET_POSIX
  98. #include "Posix/AtomicImpl-c-api.h"
  99. #else
  100. #include "AtomicImpl-c-api.h"
  101. #endif