ThreadPoolMacros.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #pragma once
  2. #if NET_4_0
  3. #include "vm/Atomic.h"
  4. #define COUNTER_CHECK(counter) \
  5. do { \
  6. IL2CPP_ASSERT(counter._.max_working > 0); \
  7. IL2CPP_ASSERT(counter._.working >= 0); \
  8. IL2CPP_ASSERT(counter._.active >= 0); \
  9. } while (0)
  10. #define COUNTER_READ() (il2cpp::vm::Atomic::Read64 (&g_ThreadPool->counters.as_int64_t))
  11. #define COUNTER_ATOMIC(var, block) \
  12. do { \
  13. ThreadPoolCounter __old; \
  14. do { \
  15. IL2CPP_ASSERT(g_ThreadPool); \
  16. __old.as_int64_t = COUNTER_READ (); \
  17. (var) = __old; \
  18. { block; } \
  19. COUNTER_CHECK (var); \
  20. } while (il2cpp::vm::Atomic::CompareExchange64 (&g_ThreadPool->counters.as_int64_t, (var).as_int64_t, __old.as_int64_t) != __old.as_int64_t); \
  21. } while (0)
  22. #define COUNTER_TRY_ATOMIC(res, var, block) \
  23. do { \
  24. ThreadPoolCounter __old; \
  25. do { \
  26. IL2CPP_ASSERT(g_ThreadPool); \
  27. __old.as_int64_t = COUNTER_READ (); \
  28. (var) = __old; \
  29. (res) = false; \
  30. { block; } \
  31. COUNTER_CHECK (var); \
  32. (res) = il2cpp::vm::Atomic::CompareExchange64 (&g_ThreadPool->counters.as_int64_t, (var).as_int64_t, __old.as_int64_t) == __old.as_int64_t; \
  33. } while (0); \
  34. } while (0)
  35. #define CPU_USAGE_LOW 80
  36. #define CPU_USAGE_HIGH 95
  37. #endif // NET_4_0