fix: use PyMutex instead of std::mutex in free-threaded build#5219
Merged
rwgk merged 3 commits intopybind:masterfrom Jul 2, 2024
Merged
fix: use PyMutex instead of std::mutex in free-threaded build#5219rwgk merged 3 commits intopybind:masterfrom
rwgk merged 3 commits intopybind:masterfrom
Conversation
PyMutex is now part of the public C API as of 3.13.0b3 and generally has slightly less overhead than std::mutex.
rwgk
reviewed
Jul 2, 2024
include/pybind11/detail/internals.h
Outdated
| pymutex mutex; | ||
| // alignas(64) would be better, but causes compile errors in macOS before 10.14 (see #5200) | ||
| char padding[64 - (sizeof(std::mutex) + sizeof(instance_map)) % 64]; | ||
| char padding[64 - (sizeof(instance_map) + sizeof(std::mutex)) % 64]; |
Collaborator
There was a problem hiding this comment.
Oversight? — Was this meant to be sizeof(pymutex) here?
rwgk
reviewed
Jul 2, 2024
| using instance_map = std::unordered_multimap<const void *, instance *>; | ||
|
|
||
| #ifdef Py_GIL_DISABLED | ||
| // Wrapper around PyMutex to provide BasicLockable semantics |
Collaborator
There was a problem hiding this comment.
Sorry I missed this when I looked before:
Could you please remove the
#include <mutex>
near the top? (I double-checked that std::mutex is not referenced anymore in this file.)
Contributor
Author
There was a problem hiding this comment.
We still need it for std::unique_lock
rwgk
approved these changes
Jul 2, 2024
wenqing
pushed a commit
to wenqing/pybind11
that referenced
this pull request
Jul 6, 2024
* Use PyMutex instead of std::mutex in free-threaded build. PyMutex is now part of the public C API as of 3.13.0b3 and generally has slightly less overhead than std::mutex. * style: pre-commit fixes * Fix instance_map_shard padding --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
henryiii
pushed a commit
that referenced
this pull request
Aug 13, 2024
* Use PyMutex instead of std::mutex in free-threaded build. PyMutex is now part of the public C API as of 3.13.0b3 and generally has slightly less overhead than std::mutex. * style: pre-commit fixes * Fix instance_map_shard padding --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
3 tasks
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.
Description
PyMutex is now part of the public C API as of 3.13.0b3 and generally has slightly less overhead than std::mutex.
See #5112
Suggested changelog entry: