mirror of
https://github.com/salsa-rs/salsa.git
synced 2025-01-12 16:35:21 +00:00
replace use of await
, which is a keyword in Rust 2018
This commit is contained in:
parent
60e5221a69
commit
e58702ebd0
3 changed files with 26 additions and 24 deletions
|
@ -18,7 +18,7 @@ fn in_par_get_set_cancellation() {
|
|||
move || {
|
||||
let v1 = db.knobs().sum_signal_on_entry.with_value(1, || {
|
||||
db.knobs()
|
||||
.sum_await_cancellation
|
||||
.sum_wait_for_cancellation
|
||||
.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
|
||||
// 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
|
||||
// in particular that we re-compute the sum of `"abc"`
|
||||
|
@ -41,7 +41,7 @@ fn in_par_get_set_cancellation() {
|
|||
let db = db.fork();
|
||||
move || {
|
||||
// Wait until we have entered `sum` in the other thread.
|
||||
db.await(1);
|
||||
db.wait_for(1);
|
||||
|
||||
db.query(Input).set('d', 1000);
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ pub(crate) trait Knobs {
|
|||
|
||||
fn signal(&self, stage: usize);
|
||||
|
||||
fn await(&self, stage: usize);
|
||||
fn wait_for(&self, stage: usize);
|
||||
}
|
||||
|
||||
pub(crate) trait WithValue<T> {
|
||||
|
@ -56,15 +56,15 @@ pub(crate) struct KnobsStruct {
|
|||
/// Invocations of `sum` will signal this stage on entry.
|
||||
pub(crate) sum_signal_on_entry: Cell<usize>,
|
||||
|
||||
/// Invocations of `sum` will await this stage on entry.
|
||||
pub(crate) sum_await_on_entry: Cell<usize>,
|
||||
/// Invocations of `sum` will wait for this stage on entry.
|
||||
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.
|
||||
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.
|
||||
pub(crate) sum_await_on_exit: Cell<usize>,
|
||||
/// Invocations of `sum` will wait for this stage prior to exiting.
|
||||
pub(crate) sum_wait_for_on_exit: Cell<usize>,
|
||||
|
||||
/// Invocations of `sum` will signal this stage prior to exiting.
|
||||
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
|
||||
/// with the current stage.
|
||||
pub(crate) fn await(&self, stage: usize) {
|
||||
log::debug!("await({})", stage);
|
||||
pub(crate) fn wait_for(&self, stage: usize) {
|
||||
log::debug!("wait_for({})", stage);
|
||||
|
||||
// As above, avoid lock if clearly a no-op.
|
||||
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.await(db.knobs().sum_await_on_entry.get());
|
||||
db.wait_for(db.knobs().sum_wait_for_on_entry.get());
|
||||
|
||||
for ch in key.chars() {
|
||||
sum += db.input(ch);
|
||||
}
|
||||
|
||||
if db.knobs().sum_await_cancellation.get() {
|
||||
log::debug!("awaiting cancellation");
|
||||
if db.knobs().sum_wait_for_cancellation.get() {
|
||||
log::debug!("waiting for cancellation");
|
||||
while !db.salsa_runtime().is_current_revision_canceled() {
|
||||
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.
|
||||
}
|
||||
|
||||
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());
|
||||
|
||||
|
@ -166,8 +166,8 @@ impl Knobs for ParDatabaseImpl {
|
|||
self.knobs.signal.signal(stage);
|
||||
}
|
||||
|
||||
fn await(&self, stage: usize) {
|
||||
self.knobs.signal.await(stage);
|
||||
fn wait_for(&self, stage: usize) {
|
||||
self.knobs.signal.wait_for(stage);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -18,18 +18,20 @@ fn true_parallel_different_keys() {
|
|||
let db = db.fork();
|
||||
move || {
|
||||
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
|
||||
}
|
||||
});
|
||||
|
||||
// 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.
|
||||
let thread2 = std::thread::spawn({
|
||||
let db = db.fork();
|
||||
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"))
|
||||
});
|
||||
v
|
||||
|
@ -51,13 +53,13 @@ fn true_parallel_same_keys() {
|
|||
db.query(Input).set('b', 010);
|
||||
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 db = db.fork();
|
||||
move || {
|
||||
let v = db.knobs().sum_signal_on_entry.with_value(1, || {
|
||||
db.knobs()
|
||||
.sum_await_on_entry
|
||||
.sum_wait_for_on_entry
|
||||
.with_value(2, || db.sum("abc"))
|
||||
});
|
||||
v
|
||||
|
@ -69,7 +71,7 @@ fn true_parallel_same_keys() {
|
|||
let thread2 = std::thread::spawn({
|
||||
let db = db.fork();
|
||||
move || {
|
||||
db.knobs().signal.await(1);
|
||||
db.knobs().signal.wait_for(1);
|
||||
db.knobs().signal.signal(2);
|
||||
db.sum("abc")
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue