Compare commits
No commits in common. "a2112b9ef5747cfe8d20638898065e9c4857d801" and "3458a900ee8fbd536f74a7201963dee06933b76f" have entirely different histories.
a2112b9ef5
...
3458a900ee
|
@ -39,7 +39,6 @@ thiserror = "2.0"
|
||||||
bitflags = "2.6"
|
bitflags = "2.6"
|
||||||
core_affinity = "0.8.1"
|
core_affinity = "0.8.1"
|
||||||
parking_lot_core = "0.9.10"
|
parking_lot_core = "0.9.10"
|
||||||
cfg-if = "1.0.0"
|
|
||||||
# derive_more = "1.0.0"
|
# derive_more = "1.0.0"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
|
|
|
@ -56,7 +56,7 @@ mod tree {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const TREE_SIZE: usize = 13;
|
const TREE_SIZE: usize = 16;
|
||||||
|
|
||||||
#[bench]
|
#[bench]
|
||||||
fn join_melange(b: &mut Bencher) {
|
fn join_melange(b: &mut Bencher) {
|
||||||
|
@ -93,7 +93,6 @@ fn join_melange(b: &mut Bencher) {
|
||||||
|
|
||||||
#[bench]
|
#[bench]
|
||||||
fn join_praetor(b: &mut Bencher) {
|
fn join_praetor(b: &mut Bencher) {
|
||||||
tracing_subscriber::fmt().with_test_writer().init();
|
|
||||||
use executor::praetor::Scope;
|
use executor::praetor::Scope;
|
||||||
let pool = executor::praetor::ThreadPool::global();
|
let pool = executor::praetor::ThreadPool::global();
|
||||||
|
|
||||||
|
@ -122,7 +121,6 @@ fn join_praetor(b: &mut Bencher) {
|
||||||
|
|
||||||
#[bench]
|
#[bench]
|
||||||
fn join_sync(b: &mut Bencher) {
|
fn join_sync(b: &mut Bencher) {
|
||||||
tracing_subscriber::fmt().with_test_writer().init();
|
|
||||||
let tree = tree::Tree::new(TREE_SIZE, 1u32);
|
let tree = tree::Tree::new(TREE_SIZE, 1u32);
|
||||||
|
|
||||||
fn sum(tree: &tree::Tree<u32>, node: usize) -> u32 {
|
fn sum(tree: &tree::Tree<u32>, node: usize) -> u32 {
|
||||||
|
|
45
src/lib.rs
45
src/lib.rs
|
@ -5,8 +5,6 @@
|
||||||
cell_update,
|
cell_update,
|
||||||
cold_path,
|
cold_path,
|
||||||
fn_align,
|
fn_align,
|
||||||
box_vec_non_null,
|
|
||||||
atomic_try_update,
|
|
||||||
let_chains
|
let_chains
|
||||||
)]
|
)]
|
||||||
|
|
||||||
|
@ -165,7 +163,6 @@ pub mod task {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub mod latch {
|
pub mod latch {
|
||||||
use core::marker::PhantomData;
|
|
||||||
use std::{
|
use std::{
|
||||||
sync::{
|
sync::{
|
||||||
atomic::{AtomicBool, AtomicUsize, Ordering},
|
atomic::{AtomicBool, AtomicUsize, Ordering},
|
||||||
|
@ -286,48 +283,6 @@ pub mod latch {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct LatchRef<'a, L: Latch> {
|
|
||||||
inner: *const L,
|
|
||||||
_marker: PhantomData<&'a L>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a, L: Latch> LatchRef<'a, L> {
|
|
||||||
#[inline]
|
|
||||||
pub const fn new(latch: &'a L) -> Self {
|
|
||||||
Self {
|
|
||||||
inner: latch,
|
|
||||||
_marker: PhantomData,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a, L: Latch> Latch for LatchRef<'a, L> {
|
|
||||||
#[inline]
|
|
||||||
unsafe fn set_raw(this: *const Self) {
|
|
||||||
let this = &*this;
|
|
||||||
Latch::set_raw(this.inner);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a, L: Latch + Probe> Probe for LatchRef<'a, L> {
|
|
||||||
#[inline]
|
|
||||||
fn probe(&self) -> bool {
|
|
||||||
unsafe {
|
|
||||||
let this = &*self.inner;
|
|
||||||
Probe::probe(this)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct NopLatch;
|
|
||||||
|
|
||||||
impl Latch for NopLatch {
|
|
||||||
#[inline]
|
|
||||||
unsafe fn set_raw(_this: *const Self) {
|
|
||||||
// do nothing
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct MutexLatch {
|
pub struct MutexLatch {
|
||||||
mutex: Mutex<bool>,
|
mutex: Mutex<bool>,
|
||||||
signal: Condvar,
|
signal: Condvar,
|
||||||
|
|
1019
src/praetor/mod.rs
1019
src/praetor/mod.rs
File diff suppressed because it is too large
Load diff
|
@ -1,9 +1,4 @@
|
||||||
use std::{
|
use std::{mem::MaybeUninit, pin::Pin};
|
||||||
mem::MaybeUninit,
|
|
||||||
pin::{pin, Pin},
|
|
||||||
};
|
|
||||||
|
|
||||||
use tracing_test::traced_test;
|
|
||||||
|
|
||||||
use super::{util::TaggedAtomicPtr, *};
|
use super::{util::TaggedAtomicPtr, *};
|
||||||
|
|
||||||
|
@ -16,11 +11,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 = StackJob::new(|| 3 + 3, crate::latch::MutexLatch::new());
|
let stack = pin!(StackJob::new(|_: &Scope| 3 + 3));
|
||||||
|
|
||||||
let job = stack.as_job();
|
let job = pin!(stack.as_ref().as_job());
|
||||||
unsafe {
|
unsafe {
|
||||||
list.push_front(&job);
|
list.push_front(job.as_ref());
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
|
@ -29,7 +24,7 @@ fn new_job() {
|
||||||
|
|
||||||
_ = stack.unwrap();
|
_ = stack.unwrap();
|
||||||
job_ref.complete(Ok(6));
|
job_ref.complete(Ok(6));
|
||||||
let result = job_ref.wait().into_inner();
|
let result = job_ref.wait();
|
||||||
assert_eq!(result.ok(), Some(6));
|
assert_eq!(result.ok(), Some(6));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,14 +37,14 @@ fn job_list_pop_back() {
|
||||||
let c = pin!(Job::empty());
|
let c = pin!(Job::empty());
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
list.push_front(&a);
|
list.push_front(a.as_ref());
|
||||||
list.push_front(&b);
|
list.push_front(b.as_ref());
|
||||||
list.push_back(&c);
|
list.push_back(c.as_ref());
|
||||||
}
|
}
|
||||||
|
|
||||||
assert_eq!(list.pop_back(), Some(pin_ptr(&c)));
|
assert_eq!(list.pop_back(), Some(pin_ptr(&c)));
|
||||||
unsafe {
|
unsafe {
|
||||||
list.push_front(&c);
|
list.push_front(c.as_ref());
|
||||||
}
|
}
|
||||||
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)));
|
||||||
|
@ -66,14 +61,14 @@ fn job_list_pop_front() {
|
||||||
let c = pin!(Job::<()>::empty());
|
let c = pin!(Job::<()>::empty());
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
list.push_front(&a);
|
list.push_front(a.as_ref());
|
||||||
list.push_front(&b);
|
list.push_front(b.as_ref());
|
||||||
list.push_back(&c);
|
list.push_back(c.as_ref());
|
||||||
}
|
}
|
||||||
|
|
||||||
assert_eq!(list.pop_front(), Some(pin_ptr(&b)));
|
assert_eq!(list.pop_front(), Some(pin_ptr(&b)));
|
||||||
unsafe {
|
unsafe {
|
||||||
list.push_back(&b);
|
list.push_back(b.as_ref());
|
||||||
}
|
}
|
||||||
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)));
|
||||||
|
@ -90,9 +85,9 @@ fn unlink_job_middle() {
|
||||||
let c = pin!(Job::<()>::empty());
|
let c = pin!(Job::<()>::empty());
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
list.push_front(&a);
|
list.push_front(a.as_ref());
|
||||||
list.push_front(&b);
|
list.push_front(b.as_ref());
|
||||||
list.push_front(&c);
|
list.push_front(c.as_ref());
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
|
@ -113,9 +108,9 @@ fn unlink_job_front() {
|
||||||
let c = pin!(Job::<()>::empty());
|
let c = pin!(Job::<()>::empty());
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
list.push_front(&a);
|
list.push_front(a.as_ref());
|
||||||
list.push_front(&b);
|
list.push_front(b.as_ref());
|
||||||
list.push_front(&c);
|
list.push_front(c.as_ref());
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
|
@ -136,9 +131,9 @@ fn unlink_job_back() {
|
||||||
let c = pin!(Job::<()>::empty());
|
let c = pin!(Job::<()>::empty());
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
list.push_front(&a);
|
list.push_front(a.as_ref());
|
||||||
list.push_front(&b);
|
list.push_front(b.as_ref());
|
||||||
list.push_front(&c);
|
list.push_front(c.as_ref());
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
|
@ -157,7 +152,7 @@ fn unlink_job_single() {
|
||||||
let a = pin!(Job::<()>::empty());
|
let a = pin!(Job::<()>::empty());
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
list.push_front(&a);
|
list.push_front(a.as_ref());
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
|
@ -347,7 +342,7 @@ fn job_list_pop_back_emptied() {
|
||||||
let a = pin!(Job::<()>::empty());
|
let a = pin!(Job::<()>::empty());
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
list.push_front(&a);
|
list.push_front(a.as_ref());
|
||||||
}
|
}
|
||||||
|
|
||||||
assert_eq!(list.pop_back(), Some(pin_ptr(&a)));
|
assert_eq!(list.pop_back(), Some(pin_ptr(&a)));
|
||||||
|
@ -362,7 +357,7 @@ fn job_list_pop_front_emptied() {
|
||||||
let a = pin!(Job::<()>::empty());
|
let a = pin!(Job::<()>::empty());
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
list.push_front(&a);
|
list.push_front(a.as_ref());
|
||||||
}
|
}
|
||||||
|
|
||||||
assert_eq!(list.pop_front(), Some(pin_ptr(&a)));
|
assert_eq!(list.pop_front(), Some(pin_ptr(&a)));
|
||||||
|
@ -372,27 +367,9 @@ 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(|_| {
|
||||||
|
@ -448,35 +425,6 @@ fn join() {
|
||||||
eprintln!("x: {x}");
|
eprintln!("x: {x}");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
#[traced_test]
|
|
||||||
fn join_many() {
|
|
||||||
use crate::util::tree::{Tree, TREE_SIZE};
|
|
||||||
|
|
||||||
let pool = ThreadPool::new();
|
|
||||||
|
|
||||||
let tree = Tree::new(16, 1u32);
|
|
||||||
|
|
||||||
fn sum(tree: &Tree<u32>, node: usize, scope: &Scope) -> u32 {
|
|
||||||
let node = tree.get(node);
|
|
||||||
let (l, r) = scope.join_heartbeat(
|
|
||||||
|s| node.left.map(|node| sum(tree, node, s)).unwrap_or_default(),
|
|
||||||
|s| {
|
|
||||||
node.right
|
|
||||||
.map(|node| sum(tree, node, s))
|
|
||||||
.unwrap_or_default()
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
// eprintln!("node: {node:?}, l: {l}, r: {r}");
|
|
||||||
|
|
||||||
node.leaf + l + r
|
|
||||||
}
|
|
||||||
|
|
||||||
let sum = pool.scope(|s| sum(&tree, tree.root().unwrap(), s));
|
|
||||||
eprintln!("{sum}");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn rebox() {
|
fn rebox() {
|
||||||
struct A(u32);
|
struct A(u32);
|
||||||
|
|
68
src/util.rs
68
src/util.rs
|
@ -65,71 +65,3 @@ impl XorShift64Star {
|
||||||
(self.next() % n as u64) as usize
|
(self.next() % n as u64) as usize
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[macro_export]
|
|
||||||
macro_rules! cfg_miri {
|
|
||||||
(
|
|
||||||
@miri => { $($tokens:tt)* }$(,)?
|
|
||||||
_ => { $($tokens2:tt)* }
|
|
||||||
) => {
|
|
||||||
#[cfg(miri)]
|
|
||||||
{
|
|
||||||
$($tokens)*
|
|
||||||
}
|
|
||||||
#[cfg(not(miri))]
|
|
||||||
{
|
|
||||||
$($tokens2)*
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
pub mod tree {
|
|
||||||
|
|
||||||
pub struct Tree<T> {
|
|
||||||
nodes: Box<[Node<T>]>,
|
|
||||||
root: Option<usize>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
|
||||||
pub struct Node<T> {
|
|
||||||
pub leaf: T,
|
|
||||||
pub left: Option<usize>,
|
|
||||||
pub right: Option<usize>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T> Tree<T> {
|
|
||||||
pub fn new(depth: usize, t: T) -> Tree<T>
|
|
||||||
where
|
|
||||||
T: Copy,
|
|
||||||
{
|
|
||||||
let mut nodes = Vec::with_capacity((0..depth).sum());
|
|
||||||
let root = Self::build_node(&mut nodes, depth, t);
|
|
||||||
Self {
|
|
||||||
nodes: nodes.into_boxed_slice(),
|
|
||||||
root: Some(root),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn root(&self) -> Option<usize> {
|
|
||||||
self.root
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get(&self, index: usize) -> &Node<T> {
|
|
||||||
&self.nodes[index]
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn build_node(nodes: &mut Vec<Node<T>>, depth: usize, t: T) -> usize
|
|
||||||
where
|
|
||||||
T: Copy,
|
|
||||||
{
|
|
||||||
let node = Node {
|
|
||||||
leaf: t,
|
|
||||||
left: (depth != 0).then(|| Self::build_node(nodes, depth - 1, t)),
|
|
||||||
right: (depth != 0).then(|| Self::build_node(nodes, depth - 1, t)),
|
|
||||||
};
|
|
||||||
nodes.push(node);
|
|
||||||
nodes.len() - 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pub const TREE_SIZE: usize = 16;
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue