Implement bn::base::{mutex, recursive_mutex} for Windows and Linux - #8479
Open
bdash wants to merge 2 commits into
Open
Implement bn::base::{mutex, recursive_mutex} for Windows and Linux#8479bdash wants to merge 2 commits into
bdash wants to merge 2 commits into
Conversation
On Windows, `mutex` wraps a `std::shared_mutex`, which unlike `std::mutex` is a thin wrapper around `SRWLOCK`, so it is both fast and compact. On Linux, it is modeled after `mutex3` from Drepper's "Futexes are Tricky". A `std::atomic<int>` holds the state, and blocking is handled via `platform_wait`, a thin abstraction over futex wait/wake that also has `__ulock` and `WaitOnAddress` backends for macOS and Windows. `recursive_mutex` is a wrapper around `mutex` that tracks the owning thread and recursion count. These are comparable in performance to the equivalent standard library types, but they're significantly smaller (on Windows 8 bytes vs 80, on Linux 4 bytes vs 40).
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
On Windows,
mutexwraps astd::shared_mutex, which unlikestd::mutexis a thin wrapper aroundSRWLOCK, so it is both fast and compact.On Linux, it is modeled after
mutex3from Drepper's "Futexes are Tricky". Astd::atomic<int>holds the state, and blocking is handled viaplatform_wait, a thin abstraction over futex wait/wake that also has__ulockandWaitOnAddressbackends for macOS and Windows.recursive_mutexis a wrapper aroundmutexthat tracks the owning thread and recursion count.These are comparable in performance to the equivalent standard library types, but they're significantly smaller (on Windows 8 bytes vs 80, on Linux 4 bytes vs 40).