Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 22 additions & 7 deletions rayon-compat/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,25 +80,40 @@ where
// -----------------------------------------------------------------------------
// Scope

pub use forte::Scope;
pub struct Scope<'scope, 'env> {
inner_scope: &'scope forte::Scope<'scope, 'env>,
}

impl<'scope, 'env> Scope<'scope, 'env> {
pub fn spawn<F>(self, f: F)
where
F: FnOnce(Scope<'scope, 'env>) + Send + 'scope,
{
forte::Worker::with_current(|worker| {
let worker = worker.unwrap();
let inner_scope = self.inner_scope;
inner_scope.spawn_on(worker, |_| f(Scope { inner_scope }))
});
}
}

#[inline(always)]
pub fn scope<'scope, OP, R>(op: OP) -> R
pub fn scope<'env, OP, R>(op: OP) -> R
where
OP: FnOnce(&Scope<'scope>) -> R + Send,
OP: for<'scope> FnOnce(Scope<'scope, 'env>) -> R + Send,
R: Send,
{
ensure_started();
forte::scope(op)
forte::scope(|inner_scope| op(Scope { inner_scope }))
}

#[inline(always)]
pub fn in_place_scope<'scope, OP, R>(op: OP) -> R
pub fn in_place_scope<'env, OP, R>(op: OP) -> R
where
OP: FnOnce(&Scope<'scope>) -> R,
OP: for<'scope> FnOnce(Scope<'scope, 'env>) -> R,
{
ensure_started();
forte::scope(op)
forte::scope(|inner_scope| op(Scope { inner_scope }))
}

// -----------------------------------------------------------------------------
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ mod platform {
pub use alloc::sync::Arc;
pub use alloc::sync::Weak;
pub use core::sync::atomic::AtomicBool;
pub use core::sync::atomic::AtomicPtr;
pub use core::sync::atomic::AtomicU32;
pub use core::sync::atomic::Ordering;
pub use std::sync::Barrier;
Expand All @@ -95,6 +96,7 @@ mod platform {
pub use shuttle::sync::Mutex;
pub use shuttle::sync::Weak;
pub use shuttle::sync::atomic::AtomicBool;
pub use shuttle::sync::atomic::AtomicPtr;
pub use shuttle::sync::atomic::AtomicU32;
pub use shuttle::sync::atomic::Ordering;
pub use shuttle::thread::Builder as ThreadBuilder;
Expand Down
Loading
Loading