-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Move spin
to bevy_platform_support
out of other crates
#17470
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Marking as |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks pretty good. I'm impressed with how much progress is being made and I like how it makes engine development easier by making the code less noisy with feature gates.
#[cfg(feature = "std")] | ||
let set = self.0.read().unwrap_or_else(PoisonError::into_inner); | ||
|
||
#[cfg(not(feature = "std"))] | ||
let set = self.0.read(); | ||
|
||
if let Some(value) = set.get(value) { | ||
return Interned(*value); | ||
} | ||
} | ||
|
||
{ | ||
#[cfg(feature = "std")] | ||
let mut set = self.0.write().unwrap_or_else(PoisonError::into_inner); | ||
|
||
#[cfg(not(feature = "std"))] | ||
let mut set = self.0.write(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like how this cleans up
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's exactly my goal here. It's technically more lines of code total, but it's far easier to reason about.
crates/bevy_tasks/src/usages.rs
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So clean!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implementation is cleanly done, love it! 👍
Most importantly, highlighting which items _would_ be in `std` which _aren't_ available. Co-Authored-By: BD103 <[email protected]> Co-Authored-By: Benjamin Brienen <[email protected]>
…e#17470) # Objective - Contributes to bevyengine#16877 ## Solution - Expanded `bevy_platform_support::sync` module to provide API-compatible replacements for `std` items such as `RwLock`, `Mutex`, and `OnceLock`. - Removed `spin` from all crates except `bevy_platform_support`. ## Testing - CI --- ## Notes - The sync primitives, while verbose, entirely rely on `spin` for their implementation requiring no `unsafe` and not changing the status-quo on _how_ locks actually work within Bevy. This is just a refactoring to consolidate the "hacks" and workarounds required to get a consistent experience when either using `std::sync` or `spin`. - I have opted to rely on `std::sync` for `std` compatible locks, maintaining the status quo. However, now that we have these locks factored out into the own module, it would be trivial to investigate alternate locking backends, such as `parking_lot`. - API for these locking types is entirely based on `std`. I have implemented methods and types which aren't currently in use within Bevy (e.g., `LazyLock` and `Once`) for the sake of completeness. As the standard library is highly stable, I don't expect the Bevy and `std` implementations to drift apart much if at all. --------- Co-authored-by: BD103 <[email protected]> Co-authored-by: Benjamin Brienen <[email protected]>
Objective
Solution
bevy_platform_support::sync
module to provide API-compatible replacements forstd
items such asRwLock
,Mutex
, andOnceLock
.spin
from all crates exceptbevy_platform_support
.Testing
Notes
spin
for their implementation requiring nounsafe
and not changing the status-quo on how locks actually work within Bevy. This is just a refactoring to consolidate the "hacks" and workarounds required to get a consistent experience when either usingstd::sync
orspin
.std::sync
forstd
compatible locks, maintaining the status quo. However, now that we have these locks factored out into the own module, it would be trivial to investigate alternate locking backends, such asparking_lot
.std
. I have implemented methods and types which aren't currently in use within Bevy (e.g.,LazyLock
andOnce
) for the sake of completeness. As the standard library is highly stable, I don't expect the Bevy andstd
implementations to drift apart much if at all.