Rename ruy::WaitUntil to ruy::Wait, because it is most closely related to std::condition_variable::wait, rather than to std::condition_variable::wait_until, so this could have been confusing. For us the "until" means "until the predicate returns true" while in the standard library, the _until suffix means "until some delay has elapsed".

PiperOrigin-RevId: 292200429
Change-Id: I1e446b95677724ebac137cedd1348a6b27e392d7
This commit is contained in:
Benoit Jacob 2020-01-29 12:57:02 -08:00 committed by TensorFlower Gardener
parent 0322cb8e1d
commit d8ec57451f
5 changed files with 13 additions and 15 deletions

View File

@ -43,7 +43,7 @@ void BlockingCounter::Wait() {
const auto& condition = [this]() { const auto& condition = [this]() {
return count_.load(std::memory_order_acquire) == 0; return count_.load(std::memory_order_acquire) == 0;
}; };
WaitUntil(condition, &count_cond_, &count_mutex_); ruy::Wait(condition, &count_cond_, &count_mutex_);
} }
} // namespace ruy } // namespace ruy

View File

@ -116,7 +116,7 @@ class Thread {
const auto& condition = [this]() { const auto& condition = [this]() {
return state_.load(std::memory_order_acquire) != State::Ready; return state_.load(std::memory_order_acquire) != State::Ready;
}; };
WaitUntil(condition, &state_cond_, &state_mutex_); Wait(condition, &state_cond_, &state_mutex_);
// Act on new state. // Act on new state.
switch (state_.load(std::memory_order_acquire)) { switch (state_.load(std::memory_order_acquire)) {

View File

@ -19,9 +19,8 @@ limitations under the License.
namespace ruy { namespace ruy {
void WaitUntil(const std::function<bool()>& condition, void Wait(const std::function<bool()>& condition, const Duration& spin_duration,
const Duration& spin_duration, std::condition_variable* condvar, std::condition_variable* condvar, std::mutex* mutex) {
std::mutex* mutex) {
// First, trivial case where the `condition` is already true; // First, trivial case where the `condition` is already true;
if (condition()) { if (condition()) {
return; return;
@ -40,8 +39,8 @@ void WaitUntil(const std::function<bool()>& condition,
condvar->wait(lock, condition); condvar->wait(lock, condition);
} }
void WaitUntil(const std::function<bool()>& condition, void Wait(const std::function<bool()>& condition,
std::condition_variable* condvar, std::mutex* mutex) { std::condition_variable* condvar, std::mutex* mutex) {
// This value was empirically derived with some microbenchmark, we don't have // This value was empirically derived with some microbenchmark, we don't have
// high confidence in it. // high confidence in it.
// //
@ -64,7 +63,7 @@ void WaitUntil(const std::function<bool()>& condition,
// may be a little longer. There may also not be another GEMM for a long time, // may be a little longer. There may also not be another GEMM for a long time,
// in which case we'll end up passively waiting below. // in which case we'll end up passively waiting below.
const Duration spin_duration = DurationFromMilliseconds(2); const Duration spin_duration = DurationFromMilliseconds(2);
WaitUntil(condition, spin_duration, condvar, mutex); Wait(condition, spin_duration, condvar, mutex);
} }
} // namespace ruy } // namespace ruy

View File

@ -59,15 +59,14 @@ namespace ruy {
// inline storage, avoiding a heap allocation. However, we can't effectively // inline storage, avoiding a heap allocation. However, we can't effectively
// guard that assumption, and that's not a big concern anyway because the // guard that assumption, and that's not a big concern anyway because the
// latency of a small heap allocation is probably low compared to the intrinsic // latency of a small heap allocation is probably low compared to the intrinsic
// latency of what this WaitUntil function does. // latency of what this Wait function does.
void WaitUntil(const std::function<bool()>& condition, void Wait(const std::function<bool()>& condition, const Duration& spin_duration,
const Duration& spin_duration, std::condition_variable* condvar, std::condition_variable* condvar, std::mutex* mutex);
std::mutex* mutex);
// Convenience overload using a default `spin_duration`. // Convenience overload using a default `spin_duration`.
// TODO(benoitjacob): let this be controlled from the ruy API. // TODO(benoitjacob): let this be controlled from the ruy API.
void WaitUntil(const std::function<bool()>& condition, void Wait(const std::function<bool()>& condition,
std::condition_variable* condvar, std::mutex* mutex); std::condition_variable* condvar, std::mutex* mutex);
} // namespace ruy } // namespace ruy

View File

@ -80,7 +80,7 @@ void WaitTest(const Duration& spin_duration, const Duration& delay) {
const auto& condition = [&value, &end_value]() { const auto& condition = [&value, &end_value]() {
return value.load() == end_value.load(); return value.load() == end_value.load();
}; };
ruy::WaitUntil(condition, spin_duration, &condvar, &mutex); ruy::Wait(condition, spin_duration, &condvar, &mutex);
EXPECT_EQ(value.load(), end_value.load()); EXPECT_EQ(value.load(), end_value.load());
} }
end_value.store(-1); end_value.store(-1);