-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Use non-poisoning locks engine-wide #20901
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
Open
james7132
wants to merge
15
commits into
bevyengine:main
Choose a base branch
from
james7132:no-poison
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
+416
−453
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
458da24
to
5e61c4f
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
A-Cross-Cutting
Impacts the entire engine
C-Code-Quality
A section of code that is hard to understand or change
D-Straightforward
Simple bug fixes and API improvements, docs, test and examples
M-Needs-Migration-Guide
A breaking change to Bevy's public API that needs to be noted in a migration guide
S-Needs-Review
Needs reviewer attention (from anyone!) to move forward
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Objective
Across the engine, we're regularly calling
mutex.lock().unwrap()
, ormutex.lock().unwarp_or_else(PoisonError::into_inner)
. It's clear that Bevy, as an project cares little about handling the poisoning. It'd be great if that state could be cleaned up.Partner PR to #20630. Partially addresses #12660.
Solution
Wrap
std::sync
locks to expose an infallible interface for both Mutex and RwLock. Unlikeparking_lot
, these wrappers do not panic upon trying to lock a poisoned lock, and it instead just swallows thePoisonError
and silence the poison. This mirrors the current heavy use ofuwnrap_or_else(PoisonError::into_error)
. This is a strong assertion that either all code interacting with the Mutex/RwLock either never panics while a guard is held, or that any panic that may occur leaves the data held by the Mutex/RwLock to be never be left in an inconsistent state where logical (not safety) invariants remain unbroken. This doesn't seem to be an issue with any of our current uses.As a separate cleanup...
TypeRegistryArc
andFunctionRegistryArc
have been removed, as users ofTypeRegistry
andFunctionRegistry
can implement their own without too much workDrawFunctions
as, opting for aDeref
derive instead.AppTypeRegistry
andAppFunctionRegistry
are no longerpub
and no longer implementsDerefMut
as it just wraps anArc
and it makes no sense to implement.SceneLoader
just wraps a clone ofAppTypeRegistry
instead.SyncCell
instead ofMutex
where reasonable.This does result in
bevy_platform::sync
deviating fromstd::sync
, so alternatively, we can jump the gun and providestd::sys::nopoison
before that becomes stabilized and expose these wrapper separately from the poisoning locks.Testing
Local CI run.