-
Notifications
You must be signed in to change notification settings - Fork 6.2k
8374878: Add Atomic<T>::compare_set #29135
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 all commits
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 |
|---|---|---|
|
|
@@ -75,6 +75,7 @@ | |
| // v.release_store(x) -> void | ||
| // v.release_store_fence(x) -> void | ||
| // v.compare_exchange(x, y [, o]) -> T | ||
| // v.compare_set(x, y [, o]) -> bool | ||
| // v.exchange(x [, o]) -> T | ||
| // | ||
| // (2) All atomic types are default constructible. | ||
|
|
@@ -267,6 +268,11 @@ class AtomicImpl::CommonCore { | |
| return AtomicAccess::cmpxchg(value_ptr(), compare_value, new_value, order); | ||
| } | ||
|
|
||
| bool compare_set(T compare_value, T new_value, | ||
| atomic_memory_order order = memory_order_conservative) { | ||
| return compare_exchange(compare_value, new_value, order) == compare_value; | ||
| } | ||
|
|
||
| T exchange(T new_value, | ||
| atomic_memory_order order = memory_order_conservative) { | ||
| return AtomicAccess::xchg(this->value_ptr(), new_value, order); | ||
|
|
@@ -479,6 +485,13 @@ class AtomicImpl::Atomic<T, AtomicImpl::Category::Translated> { | |
| order)); | ||
| } | ||
|
|
||
| bool compare_set(T compare_value, T new_value, | ||
| atomic_memory_order order = memory_order_conservative) { | ||
| return _value.compare_set(decay(compare_value), | ||
| decay(new_value), | ||
| order); | ||
|
Comment on lines
+490
to
+492
Member
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. This is subtly different from what we usually did with AtomicAccess / Atomic compare_exchange on translated types. We used to check equality with the For the |
||
| } | ||
|
|
||
| T exchange(T new_value, atomic_memory_order order = memory_order_conservative) { | ||
| return recover(_value.exchange(decay(new_value), order)); | ||
| } | ||
|
|
||
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.
[pre-existing] This assertion seems weird. It is checking
newAge.top()afteralready using been installed. Maybe it is misplaced? Or maybe it is checking
the wrong thing? Needs to be investigated. I've filed
https://bugs.openjdk.org/browse/JDK-8374915