-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
these increment/decrement the task's reference count and can drop the task if the dropped `TaskRef` is the last ref. this required some changes to reference counting via poll state transitions. will be needed for #184 depends on #188 Signed-off-by: Eliza Weisman <eliza@buoyant.io>
- Loading branch information
Showing
3 changed files
with
127 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#[cfg(loom)] | ||
mod loom { | ||
use crate::loom::{self, alloc::Track}; | ||
use crate::task::*; | ||
|
||
#[derive(Clone)] | ||
struct NopScheduler; | ||
|
||
impl crate::scheduler::Schedule for NopScheduler { | ||
fn schedule(&self, task: TaskRef) { | ||
unimplemented!( | ||
"nop scheduler should not actually schedule tasks (tried to schedule {task:?})" | ||
) | ||
} | ||
} | ||
|
||
#[test] | ||
fn taskref_deallocates() { | ||
loom::model(|| { | ||
let track = Track::new(()); | ||
let task = TaskRef::new(NopScheduler, async move { | ||
drop(track); | ||
}); | ||
|
||
// if the task is not deallocated by dropping the `TaskRef`, the | ||
// `Track` will be leaked. | ||
drop(task); | ||
}); | ||
} | ||
|
||
#[test] | ||
fn taskref_clones_deallocate() { | ||
loom::model(|| { | ||
let track = Track::new(()); | ||
let task = TaskRef::new(NopScheduler, async move { | ||
drop(track); | ||
}); | ||
|
||
let mut threads = (0..2) | ||
.map(|_| { | ||
let task = task.clone(); | ||
loom::thread::spawn(move || { | ||
drop(task); | ||
}) | ||
}) | ||
.collect::<Vec<_>>(); | ||
|
||
drop(task); | ||
|
||
for thread in threads.drain(..) { | ||
thread.join().unwrap(); | ||
} | ||
}); | ||
} | ||
} |