tests updated to no more pin innit
This commit is contained in:
parent
04496aa7e2
commit
9f776183c4
|
@ -953,6 +953,10 @@ mod job {
|
||||||
Self { result }
|
Self { result }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn into_inner(self) -> std::thread::Result<T> {
|
||||||
|
self.result
|
||||||
|
}
|
||||||
|
|
||||||
// unwraps the result, propagating panics
|
// unwraps the result, propagating panics
|
||||||
pub fn into_result(self) -> T {
|
pub fn into_result(self) -> T {
|
||||||
match self.result {
|
match self.result {
|
||||||
|
|
|
@ -1,4 +1,7 @@
|
||||||
use std::{mem::MaybeUninit, pin::Pin};
|
use std::{
|
||||||
|
mem::MaybeUninit,
|
||||||
|
pin::{pin, Pin},
|
||||||
|
};
|
||||||
|
|
||||||
use super::{util::TaggedAtomicPtr, *};
|
use super::{util::TaggedAtomicPtr, *};
|
||||||
|
|
||||||
|
@ -11,11 +14,11 @@ fn pin_ptr<T>(pin: &Pin<&mut T>) -> NonNull<T> {
|
||||||
fn new_job() {
|
fn new_job() {
|
||||||
let mut list = JobList::new();
|
let mut list = JobList::new();
|
||||||
|
|
||||||
let stack = pin!(StackJob::new(|_: &Scope| 3 + 3));
|
let stack = StackJob::new(|| 3 + 3, crate::latch::MutexLatch::new());
|
||||||
|
|
||||||
let job = pin!(stack.as_ref().as_job());
|
let job = stack.as_job();
|
||||||
unsafe {
|
unsafe {
|
||||||
list.push_front(job.as_ref());
|
list.push_front(&job);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
|
@ -24,7 +27,7 @@ fn new_job() {
|
||||||
|
|
||||||
_ = stack.unwrap();
|
_ = stack.unwrap();
|
||||||
job_ref.complete(Ok(6));
|
job_ref.complete(Ok(6));
|
||||||
let result = job_ref.wait();
|
let result = job_ref.wait().into_inner();
|
||||||
assert_eq!(result.ok(), Some(6));
|
assert_eq!(result.ok(), Some(6));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,14 +40,14 @@ fn job_list_pop_back() {
|
||||||
let c = pin!(Job::empty());
|
let c = pin!(Job::empty());
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
list.push_front(a.as_ref());
|
list.push_front(&a);
|
||||||
list.push_front(b.as_ref());
|
list.push_front(&b);
|
||||||
list.push_back(c.as_ref());
|
list.push_back(&c);
|
||||||
}
|
}
|
||||||
|
|
||||||
assert_eq!(list.pop_back(), Some(pin_ptr(&c)));
|
assert_eq!(list.pop_back(), Some(pin_ptr(&c)));
|
||||||
unsafe {
|
unsafe {
|
||||||
list.push_front(c.as_ref());
|
list.push_front(&c);
|
||||||
}
|
}
|
||||||
assert_eq!(list.pop_back(), Some(pin_ptr(&a)));
|
assert_eq!(list.pop_back(), Some(pin_ptr(&a)));
|
||||||
assert_eq!(list.pop_back(), Some(pin_ptr(&b)));
|
assert_eq!(list.pop_back(), Some(pin_ptr(&b)));
|
||||||
|
@ -61,14 +64,14 @@ fn job_list_pop_front() {
|
||||||
let c = pin!(Job::<()>::empty());
|
let c = pin!(Job::<()>::empty());
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
list.push_front(a.as_ref());
|
list.push_front(&a);
|
||||||
list.push_front(b.as_ref());
|
list.push_front(&b);
|
||||||
list.push_back(c.as_ref());
|
list.push_back(&c);
|
||||||
}
|
}
|
||||||
|
|
||||||
assert_eq!(list.pop_front(), Some(pin_ptr(&b)));
|
assert_eq!(list.pop_front(), Some(pin_ptr(&b)));
|
||||||
unsafe {
|
unsafe {
|
||||||
list.push_back(b.as_ref());
|
list.push_back(&b);
|
||||||
}
|
}
|
||||||
assert_eq!(list.pop_front(), Some(pin_ptr(&a)));
|
assert_eq!(list.pop_front(), Some(pin_ptr(&a)));
|
||||||
assert_eq!(list.pop_front(), Some(pin_ptr(&c)));
|
assert_eq!(list.pop_front(), Some(pin_ptr(&c)));
|
||||||
|
@ -85,9 +88,9 @@ fn unlink_job_middle() {
|
||||||
let c = pin!(Job::<()>::empty());
|
let c = pin!(Job::<()>::empty());
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
list.push_front(a.as_ref());
|
list.push_front(&a);
|
||||||
list.push_front(b.as_ref());
|
list.push_front(&b);
|
||||||
list.push_front(c.as_ref());
|
list.push_front(&c);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
|
@ -108,9 +111,9 @@ fn unlink_job_front() {
|
||||||
let c = pin!(Job::<()>::empty());
|
let c = pin!(Job::<()>::empty());
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
list.push_front(a.as_ref());
|
list.push_front(&a);
|
||||||
list.push_front(b.as_ref());
|
list.push_front(&b);
|
||||||
list.push_front(c.as_ref());
|
list.push_front(&c);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
|
@ -131,9 +134,9 @@ fn unlink_job_back() {
|
||||||
let c = pin!(Job::<()>::empty());
|
let c = pin!(Job::<()>::empty());
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
list.push_front(a.as_ref());
|
list.push_front(&a);
|
||||||
list.push_front(b.as_ref());
|
list.push_front(&b);
|
||||||
list.push_front(c.as_ref());
|
list.push_front(&c);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
|
@ -152,7 +155,7 @@ fn unlink_job_single() {
|
||||||
let a = pin!(Job::<()>::empty());
|
let a = pin!(Job::<()>::empty());
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
list.push_front(a.as_ref());
|
list.push_front(&a);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
|
@ -342,7 +345,7 @@ fn job_list_pop_back_emptied() {
|
||||||
let a = pin!(Job::<()>::empty());
|
let a = pin!(Job::<()>::empty());
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
list.push_front(a.as_ref());
|
list.push_front(&a);
|
||||||
}
|
}
|
||||||
|
|
||||||
assert_eq!(list.pop_back(), Some(pin_ptr(&a)));
|
assert_eq!(list.pop_back(), Some(pin_ptr(&a)));
|
||||||
|
@ -357,7 +360,7 @@ fn job_list_pop_front_emptied() {
|
||||||
let a = pin!(Job::<()>::empty());
|
let a = pin!(Job::<()>::empty());
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
list.push_front(a.as_ref());
|
list.push_front(&a);
|
||||||
}
|
}
|
||||||
|
|
||||||
assert_eq!(list.pop_front(), Some(pin_ptr(&a)));
|
assert_eq!(list.pop_front(), Some(pin_ptr(&a)));
|
||||||
|
@ -367,9 +370,27 @@ fn job_list_pop_front_emptied() {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
#[tracing_test::traced_test]
|
||||||
fn spawn() {
|
fn spawn() {
|
||||||
let pool = ThreadPool::new();
|
let pool = ThreadPool::new();
|
||||||
|
|
||||||
|
let mut x = 0;
|
||||||
|
pool.scope(|s| {
|
||||||
|
tracing::info!("scope");
|
||||||
|
s.spawn(|_| {
|
||||||
|
tracing::info!("spawn");
|
||||||
|
x += 1;
|
||||||
|
tracing::info!("x: {x}");
|
||||||
|
});
|
||||||
|
tracing::info!("~scope");
|
||||||
|
});
|
||||||
|
|
||||||
|
eprintln!("x: {x}");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn rayon_spawn() {
|
||||||
|
let pool = rayon::ThreadPoolBuilder::new().build().unwrap();
|
||||||
let mut x = 0;
|
let mut x = 0;
|
||||||
pool.scope(|s| {
|
pool.scope(|s| {
|
||||||
s.spawn(|_| {
|
s.spawn(|_| {
|
||||||
|
|
Loading…
Reference in a new issue