Skip to content
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 manual padding of instance_map_shard #5200

Merged
merged 4 commits into from
Jun 26, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions include/pybind11/detail/internals.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,18 +148,14 @@ struct override_hash {

using instance_map = std::unordered_multimap<const void *, instance *>;

// ignore: structure was padded due to alignment specifier
PYBIND11_WARNING_PUSH
PYBIND11_WARNING_DISABLE_MSVC(4324)

// Instance map shards are used to reduce mutex contention in free-threaded Python.
struct alignas(64) instance_map_shard {
struct instance_map_shard {
std::mutex mutex;
instance_map registered_instances;
// alignas(64) would be better, but causes compile errors in macOS before 10.14
henryiii marked this conversation as resolved.
Show resolved Hide resolved
char padding[64 - (sizeof(std::mutex) + sizeof(instance_map)) % 64];
henryiii marked this conversation as resolved.
Show resolved Hide resolved
};

PYBIND11_WARNING_POP

/// Internal data structure used to track registered instances and types.
/// Whenever binary incompatible changes are made to this structure,
/// `PYBIND11_INTERNALS_VERSION` must be incremented.
Expand Down
Loading