replace use of await, which is a keyword in Rust 2018

This commit is contained in:
Niko Matsakis 2018-10-19 05:17:26 -04:00
parent 60e5221a69
commit e58702ebd0
3 changed files with 26 additions and 24 deletions

View file

@ -18,7 +18,7 @@ fn in_par_get_set_cancellation() {
move || { move || {
let v1 = db.knobs().sum_signal_on_entry.with_value(1, || { let v1 = db.knobs().sum_signal_on_entry.with_value(1, || {
db.knobs() db.knobs()
.sum_await_cancellation .sum_wait_for_cancellation
.with_value(true, || db.sum("abc")) .with_value(true, || db.sum("abc"))
}); });
@ -27,7 +27,7 @@ fn in_par_get_set_cancellation() {
// at this point, we have observed cancellation, so let's // at this point, we have observed cancellation, so let's
// wait until the `set` is known to have occurred. // wait until the `set` is known to have occurred.
db.await(2); db.wait_for(2);
// Now when we read we should get the correct sums. Note // Now when we read we should get the correct sums. Note
// in particular that we re-compute the sum of `"abc"` // in particular that we re-compute the sum of `"abc"`
@ -41,7 +41,7 @@ fn in_par_get_set_cancellation() {
let db = db.fork(); let db = db.fork();
move || { move || {
// Wait until we have entered `sum` in the other thread. // Wait until we have entered `sum` in the other thread.
db.await(1); db.wait_for(1);
db.query(Input).set('d', 1000); db.query(Input).set('d', 1000);

View file

@ -25,7 +25,7 @@ pub(crate) trait Knobs {
fn signal(&self, stage: usize); fn signal(&self, stage: usize);
fn await(&self, stage: usize); fn wait_for(&self, stage: usize);
} }
pub(crate) trait WithValue<T> { pub(crate) trait WithValue<T> {
@ -56,15 +56,15 @@ pub(crate) struct KnobsStruct {
/// Invocations of `sum` will signal this stage on entry. /// Invocations of `sum` will signal this stage on entry.
pub(crate) sum_signal_on_entry: Cell<usize>, pub(crate) sum_signal_on_entry: Cell<usize>,
/// Invocations of `sum` will await this stage on entry. /// Invocations of `sum` will wait for this stage on entry.
pub(crate) sum_await_on_entry: Cell<usize>, pub(crate) sum_wait_for_on_entry: Cell<usize>,
/// If true, invocations of `sum` will await cancellation before /// If true, invocations of `sum` will wait for cancellation before
/// they exit. /// they exit.
pub(crate) sum_await_cancellation: Cell<bool>, pub(crate) sum_wait_for_cancellation: Cell<bool>,
/// Invocations of `sum` will await this stage prior to exiting. /// Invocations of `sum` will wait for this stage prior to exiting.
pub(crate) sum_await_on_exit: Cell<usize>, pub(crate) sum_wait_for_on_exit: Cell<usize>,
/// Invocations of `sum` will signal this stage prior to exiting. /// Invocations of `sum` will signal this stage prior to exiting.
pub(crate) sum_signal_on_exit: Cell<usize>, pub(crate) sum_signal_on_exit: Cell<usize>,
@ -96,8 +96,8 @@ impl Signal {
/// Waits until the given condition is true; the fn is invoked /// Waits until the given condition is true; the fn is invoked
/// with the current stage. /// with the current stage.
pub(crate) fn await(&self, stage: usize) { pub(crate) fn wait_for(&self, stage: usize) {
log::debug!("await({})", stage); log::debug!("wait_for({})", stage);
// As above, avoid lock if clearly a no-op. // As above, avoid lock if clearly a no-op.
if stage > 0 { if stage > 0 {
@ -114,14 +114,14 @@ fn sum(db: &impl ParDatabase, key: &'static str) -> usize {
db.signal(db.knobs().sum_signal_on_entry.get()); db.signal(db.knobs().sum_signal_on_entry.get());
db.await(db.knobs().sum_await_on_entry.get()); db.wait_for(db.knobs().sum_wait_for_on_entry.get());
for ch in key.chars() { for ch in key.chars() {
sum += db.input(ch); sum += db.input(ch);
} }
if db.knobs().sum_await_cancellation.get() { if db.knobs().sum_wait_for_cancellation.get() {
log::debug!("awaiting cancellation"); log::debug!("waiting for cancellation");
while !db.salsa_runtime().is_current_revision_canceled() { while !db.salsa_runtime().is_current_revision_canceled() {
std::thread::yield_now(); std::thread::yield_now();
} }
@ -129,7 +129,7 @@ fn sum(db: &impl ParDatabase, key: &'static str) -> usize {
return std::usize::MAX; // when we are cancelled, we return usize::MAX. return std::usize::MAX; // when we are cancelled, we return usize::MAX.
} }
db.await(db.knobs().sum_await_on_exit.get()); db.wait_for(db.knobs().sum_wait_for_on_exit.get());
db.signal(db.knobs().sum_signal_on_exit.get()); db.signal(db.knobs().sum_signal_on_exit.get());
@ -166,8 +166,8 @@ impl Knobs for ParDatabaseImpl {
self.knobs.signal.signal(stage); self.knobs.signal.signal(stage);
} }
fn await(&self, stage: usize) { fn wait_for(&self, stage: usize) {
self.knobs.signal.await(stage); self.knobs.signal.wait_for(stage);
} }
} }

View file

@ -18,18 +18,20 @@ fn true_parallel_different_keys() {
let db = db.fork(); let db = db.fork();
move || { move || {
let v = db.knobs().sum_signal_on_entry.with_value(1, || { let v = db.knobs().sum_signal_on_entry.with_value(1, || {
db.knobs().sum_await_on_exit.with_value(2, || db.sum("a")) db.knobs()
.sum_wait_for_on_exit
.with_value(2, || db.sum("a"))
}); });
v v
} }
}); });
// Thread 2 will await stage 1 when it enters and signal stage 2 // Thread 2 will wait_for stage 1 when it enters and signal stage 2
// when it leaves. // when it leaves.
let thread2 = std::thread::spawn({ let thread2 = std::thread::spawn({
let db = db.fork(); let db = db.fork();
move || { move || {
let v = db.knobs().sum_await_on_entry.with_value(1, || { let v = db.knobs().sum_wait_for_on_entry.with_value(1, || {
db.knobs().sum_signal_on_exit.with_value(2, || db.sum("b")) db.knobs().sum_signal_on_exit.with_value(2, || db.sum("b"))
}); });
v v
@ -51,13 +53,13 @@ fn true_parallel_same_keys() {
db.query(Input).set('b', 010); db.query(Input).set('b', 010);
db.query(Input).set('c', 001); db.query(Input).set('c', 001);
// Thread 1 will await a barrier in the start of `sum` // Thread 1 will wait_for a barrier in the start of `sum`
let thread1 = std::thread::spawn({ let thread1 = std::thread::spawn({
let db = db.fork(); let db = db.fork();
move || { move || {
let v = db.knobs().sum_signal_on_entry.with_value(1, || { let v = db.knobs().sum_signal_on_entry.with_value(1, || {
db.knobs() db.knobs()
.sum_await_on_entry .sum_wait_for_on_entry
.with_value(2, || db.sum("abc")) .with_value(2, || db.sum("abc"))
}); });
v v
@ -69,7 +71,7 @@ fn true_parallel_same_keys() {
let thread2 = std::thread::spawn({ let thread2 = std::thread::spawn({
let db = db.fork(); let db = db.fork();
move || { move || {
db.knobs().signal.await(1); db.knobs().signal.wait_for(1);
db.knobs().signal.signal(2); db.knobs().signal.signal(2);
db.sum("abc") db.sum("abc")
} }