-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
fix: use PyMutex instead of std::mutex in free-threaded build #5219
Conversation
PyMutex is now part of the public C API as of 3.13.0b3 and generally has slightly less overhead than std::mutex.
include/pybind11/detail/internals.h
Outdated
// 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]; |
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.
Oversight? — Was this meant to be sizeof(pymutex)
here?
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.
Yes, thanks.
@@ -148,20 +148,35 @@ struct override_hash { | |||
|
|||
using instance_map = std::unordered_multimap<const void *, instance *>; | |||
|
|||
#ifdef Py_GIL_DISABLED | |||
// Wrapper around PyMutex to provide BasicLockable semantics |
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.
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.)
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.
We still need it for std::unique_lock
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.
Oh, ok, thanks.
* 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>
* 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>
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: