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:
parent
0322cb8e1d
commit
d8ec57451f
@ -43,7 +43,7 @@ void BlockingCounter::Wait() {
|
||||
const auto& condition = [this]() {
|
||||
return count_.load(std::memory_order_acquire) == 0;
|
||||
};
|
||||
WaitUntil(condition, &count_cond_, &count_mutex_);
|
||||
ruy::Wait(condition, &count_cond_, &count_mutex_);
|
||||
}
|
||||
|
||||
} // namespace ruy
|
||||
|
@ -116,7 +116,7 @@ class Thread {
|
||||
const auto& condition = [this]() {
|
||||
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.
|
||||
switch (state_.load(std::memory_order_acquire)) {
|
||||
|
@ -19,9 +19,8 @@ limitations under the License.
|
||||
|
||||
namespace ruy {
|
||||
|
||||
void WaitUntil(const std::function<bool()>& condition,
|
||||
const Duration& spin_duration, std::condition_variable* condvar,
|
||||
std::mutex* mutex) {
|
||||
void Wait(const std::function<bool()>& condition, const Duration& spin_duration,
|
||||
std::condition_variable* condvar, std::mutex* mutex) {
|
||||
// First, trivial case where the `condition` is already true;
|
||||
if (condition()) {
|
||||
return;
|
||||
@ -40,8 +39,8 @@ void WaitUntil(const std::function<bool()>& condition,
|
||||
condvar->wait(lock, condition);
|
||||
}
|
||||
|
||||
void WaitUntil(const std::function<bool()>& condition,
|
||||
std::condition_variable* condvar, std::mutex* mutex) {
|
||||
void Wait(const std::function<bool()>& condition,
|
||||
std::condition_variable* condvar, std::mutex* mutex) {
|
||||
// This value was empirically derived with some microbenchmark, we don't have
|
||||
// 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,
|
||||
// in which case we'll end up passively waiting below.
|
||||
const Duration spin_duration = DurationFromMilliseconds(2);
|
||||
WaitUntil(condition, spin_duration, condvar, mutex);
|
||||
Wait(condition, spin_duration, condvar, mutex);
|
||||
}
|
||||
|
||||
} // namespace ruy
|
||||
|
@ -59,15 +59,14 @@ namespace ruy {
|
||||
// inline storage, avoiding a heap allocation. However, we can't effectively
|
||||
// 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 what this WaitUntil function does.
|
||||
void WaitUntil(const std::function<bool()>& condition,
|
||||
const Duration& spin_duration, std::condition_variable* condvar,
|
||||
std::mutex* mutex);
|
||||
// latency of what this Wait function does.
|
||||
void Wait(const std::function<bool()>& condition, const Duration& spin_duration,
|
||||
std::condition_variable* condvar, std::mutex* mutex);
|
||||
|
||||
// Convenience overload using a default `spin_duration`.
|
||||
// TODO(benoitjacob): let this be controlled from the ruy API.
|
||||
void WaitUntil(const std::function<bool()>& condition,
|
||||
std::condition_variable* condvar, std::mutex* mutex);
|
||||
void Wait(const std::function<bool()>& condition,
|
||||
std::condition_variable* condvar, std::mutex* mutex);
|
||||
|
||||
} // namespace ruy
|
||||
|
||||
|
@ -80,7 +80,7 @@ void WaitTest(const Duration& spin_duration, const Duration& delay) {
|
||||
const auto& condition = [&value, &end_value]() {
|
||||
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());
|
||||
}
|
||||
end_value.store(-1);
|
||||
|
Loading…
Reference in New Issue
Block a user