🛠️🐜 Antkeeper superbuild with dependencies included https://antkeeper.com
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.

48 lines
1.1 KiB

  1. #ifndef AL_THREADS_H
  2. #define AL_THREADS_H
  3. #if defined(__GNUC__) && defined(__i386__)
  4. /* force_align_arg_pointer is required for proper function arguments aligning
  5. * when SSE code is used. Some systems (Windows, QNX) do not guarantee our
  6. * thread functions will be properly aligned on the stack, even though GCC may
  7. * generate code with the assumption that it is. */
  8. #define FORCE_ALIGN __attribute__((force_align_arg_pointer))
  9. #else
  10. #define FORCE_ALIGN
  11. #endif
  12. #if defined(__APPLE__)
  13. #include <dispatch/dispatch.h>
  14. #elif !defined(_WIN32)
  15. #include <semaphore.h>
  16. #endif
  17. void althrd_setname(const char *name);
  18. namespace al {
  19. class semaphore {
  20. #ifdef _WIN32
  21. using native_type = void*;
  22. #elif defined(__APPLE__)
  23. using native_type = dispatch_semaphore_t;
  24. #else
  25. using native_type = sem_t;
  26. #endif
  27. native_type mSem;
  28. public:
  29. semaphore(unsigned int initial=0);
  30. semaphore(const semaphore&) = delete;
  31. ~semaphore();
  32. semaphore& operator=(const semaphore&) = delete;
  33. void post();
  34. void wait() noexcept;
  35. bool try_wait() noexcept;
  36. };
  37. } // namespace al
  38. #endif /* AL_THREADS_H */