Support multithreaded mode in OwnedSlice tests

This commit is contained in:
Maybe Waffle 2023-04-06 18:05:59 +00:00
parent e0e39caf84
commit 2733c29bb1

View File

@ -1,4 +1,10 @@
use std::{cell::Cell, ops::Deref, rc::Rc}; use std::{
ops::Deref,
sync::{
atomic::{self, AtomicBool},
Arc,
},
};
use crate::{ use crate::{
owned_slice::{slice_owned, try_slice_owned, OwnedSlice}, owned_slice::{slice_owned, try_slice_owned, OwnedSlice},
@ -47,18 +53,18 @@ fn boxed() {
} }
#[test] #[test]
fn drop() { fn drop_drops() {
let flag = Rc::new(Cell::new(false)); let flag = Arc::new(AtomicBool::new(false));
let flag_prime = Rc::clone(&flag); let flag_prime = Arc::clone(&flag);
let d = OnDrop(move || flag_prime.set(true)); let d = OnDrop(move || flag_prime.store(true, atomic::Ordering::Relaxed));
let slice = slice_owned(d, |_| &[]); let slice = slice_owned(d, |_| &[]);
assert_eq!(flag.get(), false); assert_eq!(flag.load(atomic::Ordering::Relaxed), false);
std::mem::drop(slice); drop(slice);
assert_eq!(flag.get(), true); assert_eq!(flag.load(atomic::Ordering::Relaxed), true);
} }
#[test] #[test]