-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[libc++] Increase atomic_ref's required alignment for small types
#99654
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
Changes from 3 commits
8d1fc92
8545aeb
6027a62
056d4af
e3b95d4
edeef46
976dbd9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -95,10 +95,14 @@ struct __atomic_ref_base { | |
|
|
||
| friend struct __atomic_waitable_traits<__atomic_ref_base<_Tp>>; | ||
|
|
||
| // require types that are 1, 2, 4, 8, or 16 bytes in length to be aligned to at least their size to be potentially | ||
| // used lock-free | ||
| static constexpr bool __min_alignment = (sizeof(_Tp) & (sizeof(_Tp) - 1)) || (sizeof(_Tp) > 16) ? 0 : sizeof(_Tp); | ||
|
|
||
| public: | ||
| using value_type = _Tp; | ||
|
|
||
| static constexpr size_t required_alignment = alignof(_Tp); | ||
| static constexpr size_t required_alignment = alignof(_Tp) > __min_alignment ? alignof(_Tp) : __min_alignment; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should calculate the alignment using something like this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I really like this, I think this directly translates to what we are actually trying to achieve (which is to calculate the smallest alignment that allows us to be lockfree). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That is not a valid implementation, because it causes the ABI of the type to change depending on the microarchitecture selection. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TIL |
||
|
|
||
| // The __atomic_always_lock_free builtin takes into account the alignment of the pointer if provided, | ||
| // so we create a fake pointer with a suitable alignment when querying it. Note that we are guaranteed | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.