[RFC] Add Optional Safe-to-Use Flavours of Mutex
/CondVar
#376
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.
Request For Comments Only
Note that I am NOT proposing any changes to Binder
Our
Mutex
andCondVar
abstractions push a lot ofPin
reasoning and unsafe blocks onto its users. This creates plenty of rope for less experienced driver writers to hang themselves, and is therefore not necessarily an improvement over C.Try this one on for size:
linux/samples/rust/rust_miscdev.rs
Lines 40 to 56 in 5dd07d5
The proposed Optional Safe-to-Use flavours reduce this complexity, without requiring code changes anywhere else:
(actually code complexity will be reduced further, as there is no longer a need to
Pin
the returned structure)The downside here is, obviously, the extra heap allocations, heap dereferences and loss of cache locality. But we only guess these are problematic. How can we verify that in the real world?
Turns out that @wedsonaf's proposed Binder ping benchmark appears quite sensitive to
Mutex
performance, as witnessed by the fact that we can measure a regression when adding one extra function call overhead toMutex::lock
. See:#346 (comment)
#346 (comment)
So I regression tested Wedson's benchmark on arm 32-bit (cortex-a9 + Raspberri Pi Zero) and... no apparent change in performance.
Perhaps we will see a performance regression on x86 or RISC-V? If so, are the safety gains worth it?