[NC Apple coverage] Refactor Apple CountDownLatch to use idiomatic absl::Mutex patterns.

PiperOrigin-RevId: 807644485
This commit is contained in:
Edwin Wu
2025-09-16 04:46:51 -07:00
committed by Copybara-Service
parent 9e050cc73a
commit c52edc9bae
2 changed files with 11 additions and 2 deletions
@@ -26,9 +26,9 @@ Exception CountDownLatch::Await() {
}
ExceptionOr<bool> CountDownLatch::Await(absl::Duration timeout) {
bool condition = mutex_.LockWhenWithTimeout(
absl::MutexLock lock(&mutex_);
bool condition = mutex_.AwaitWithTimeout(
absl::Condition(IsZeroOrNegative, &count_), timeout);
mutex_.Unlock();
return ExceptionOr<bool>(condition);
}
@@ -79,6 +79,15 @@ TEST(CountDownLatchTest, InitialCountNegativeAwaitDoesNotBlock) {
EXPECT_TRUE(response.Ok());
}
TEST(CountDownLatchTest, CountDown) {
CountDownLatch latch(2);
latch.CountDown();
latch.CountDown();
auto response = latch.Await(absl::Milliseconds(100));
EXPECT_TRUE(response.ok());
EXPECT_TRUE(response.result());
}
} // namespace
} // namespace apple
} // namespace nearby