Skip to content

Commit 87f4caf

Browse files
committed
refactor: use bevy-style scopes
1 parent 5a4d1bc commit 87f4caf

File tree

4 files changed

+494
-227
lines changed

4 files changed

+494
-227
lines changed

rayon-compat/src/lib.rs

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,25 +80,40 @@ where
8080
// -----------------------------------------------------------------------------
8181
// Scope
8282

83-
pub use forte::Scope;
83+
pub struct Scope<'scope, 'env> {
84+
inner_scope: &'scope forte::Scope<'scope, 'env>,
85+
}
86+
87+
impl<'scope, 'env> Scope<'scope, 'env> {
88+
pub fn spawn<F>(self, f: F)
89+
where
90+
F: FnOnce(Scope<'scope, 'env>) + Send + 'scope,
91+
{
92+
forte::Worker::with_current(|worker| {
93+
let worker = worker.unwrap();
94+
let inner_scope = self.inner_scope;
95+
inner_scope.spawn_on(worker, |_| f(Scope { inner_scope }))
96+
});
97+
}
98+
}
8499

85100
#[inline(always)]
86-
pub fn scope<'scope, OP, R>(op: OP) -> R
101+
pub fn scope<'env, OP, R>(op: OP) -> R
87102
where
88-
OP: FnOnce(&Scope<'scope>) -> R + Send,
103+
OP: for<'scope> FnOnce(Scope<'scope, 'env>) -> R + Send,
89104
R: Send,
90105
{
91106
ensure_started();
92-
forte::scope(op)
107+
forte::scope(|inner_scope| op(Scope { inner_scope }))
93108
}
94109

95110
#[inline(always)]
96-
pub fn in_place_scope<'scope, OP, R>(op: OP) -> R
111+
pub fn in_place_scope<'env, OP, R>(op: OP) -> R
97112
where
98-
OP: FnOnce(&Scope<'scope>) -> R,
113+
OP: for<'scope> FnOnce(Scope<'scope, 'env>) -> R,
99114
{
100115
ensure_started();
101-
forte::scope(op)
116+
forte::scope(|inner_scope| op(Scope { inner_scope }))
102117
}
103118

104119
// -----------------------------------------------------------------------------

src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ mod platform {
7373
pub use alloc::sync::Arc;
7474
pub use alloc::sync::Weak;
7575
pub use core::sync::atomic::AtomicBool;
76+
pub use core::sync::atomic::AtomicPtr;
7677
pub use core::sync::atomic::AtomicU32;
7778
pub use core::sync::atomic::Ordering;
7879
pub use std::sync::Barrier;
@@ -95,6 +96,7 @@ mod platform {
9596
pub use shuttle::sync::Mutex;
9697
pub use shuttle::sync::Weak;
9798
pub use shuttle::sync::atomic::AtomicBool;
99+
pub use shuttle::sync::atomic::AtomicPtr;
98100
pub use shuttle::sync::atomic::AtomicU32;
99101
pub use shuttle::sync::atomic::Ordering;
100102
pub use shuttle::thread::Builder as ThreadBuilder;

0 commit comments

Comments
 (0)