| 407 | { |
| 408 | #if defined(_WIN32) |
| 409 | class Semaphore |
| 410 | { |
| 411 | private: |
| 412 | void* m_hSema; |
| 413 | |
| 414 | Semaphore(const Semaphore& other); |
| 415 | Semaphore& operator=(const Semaphore& other); |
| 416 | |
| 417 | public: |
| 418 | AE_NO_TSAN Semaphore(int initialCount = 0) : m_hSema() |
| 419 | { |
| 420 | assert(initialCount >= 0); |
| 421 | const long maxLong = 0x7fffffff; |
| 422 | m_hSema = CreateSemaphoreW(nullptr, initialCount, maxLong, nullptr); |
| 423 | assert(m_hSema); |
| 424 | } |
| 425 | |
| 426 | AE_NO_TSAN ~Semaphore() |
| 427 | { |
| 428 | CloseHandle(m_hSema); |
| 429 | } |
| 430 | |
| 431 | bool wait() AE_NO_TSAN |
| 432 | { |
| 433 | const unsigned long infinite = 0xffffffff; |
| 434 | return WaitForSingleObject(m_hSema, infinite) == 0; |
| 435 | } |
| 436 | |
| 437 | bool try_wait() AE_NO_TSAN |
| 438 | { |
| 439 | return WaitForSingleObject(m_hSema, 0) == 0; |
| 440 | } |
| 441 | |
| 442 | bool timed_wait(std::uint64_t usecs) AE_NO_TSAN |
| 443 | { |
| 444 | return WaitForSingleObject(m_hSema, (unsigned long)(usecs / 1000)) == 0; |
| 445 | } |
| 446 | |
| 447 | void signal(int count = 1) AE_NO_TSAN |
| 448 | { |
| 449 | while (!ReleaseSemaphore(m_hSema, count, nullptr)); |
| 450 | } |
| 451 | }; |
| 452 | #elif defined(__MACH__) |
| 453 | //--------------------------------------------------------- |
| 454 | // Semaphore (Apple iOS and OSX) |
nothing calls this directly
no outgoing calls
no test coverage detected