| 29 | namespace util { |
| 30 | |
| 31 | TEST(CountingSemaphore, Basic) { |
| 32 | #ifndef ARROW_ENABLE_THREADING |
| 33 | GTEST_SKIP() << "Test requires threading support"; |
| 34 | #endif |
| 35 | |
| 36 | CountingSemaphore semaphore; |
| 37 | std::atomic<bool> acquired{false}; |
| 38 | std::atomic<bool> started{false}; |
| 39 | std::thread acquirer([&] { |
| 40 | started.store(true); |
| 41 | ASSERT_OK(semaphore.Acquire(3)); |
| 42 | acquired = true; |
| 43 | }); |
| 44 | ASSERT_OK(semaphore.WaitForWaiters(1)); |
| 45 | ASSERT_TRUE(started.load()); |
| 46 | ASSERT_FALSE(acquired.load()); |
| 47 | ASSERT_OK(semaphore.Release(2)); |
| 48 | SleepABit(); |
| 49 | ASSERT_FALSE(acquired.load()); |
| 50 | ASSERT_OK(semaphore.Release(1)); |
| 51 | BusyWait(10, [&] { return acquired.load(); }); |
| 52 | ASSERT_TRUE(acquired.load()); |
| 53 | ASSERT_OK(semaphore.Close()); |
| 54 | acquirer.join(); |
| 55 | } |
| 56 | |
| 57 | TEST(CountingSemaphore, CloseAborts) { |
| 58 | #ifndef ARROW_ENABLE_THREADING |
nothing calls this directly
no test coverage detected