mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-16 15:36:12 -04:00
[NC Apple coverage] Refactor Apple CountDownLatch to use idiomatic absl::Mutex patterns.
PiperOrigin-RevId: 807644485
This commit is contained in:
committed by
Copybara-Service
parent
9e050cc73a
commit
c52edc9bae
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user