Closed
Bug 873800
Opened 11 years ago
Closed 11 years ago
Add compare-and-swap to mfbt/Atomics.h
Categories
(Core :: MFBT, defect)
Core
MFBT
Tracking
()
RESOLVED
FIXED
mozilla24
People
(Reporter: justin.lebar+bug, Unassigned)
References
Details
Attachments
(1 file)
8.41 KB,
patch
|
froydnj
:
review+
|
Details | Diff | Splinter Review |
I've wanted a pointer-sized CAS for a while now. It returns a bool instead of returning the old value of *ptr because that's all we can do with <atomic>, afaict. Windows and GCC both give us both options.
Reporter | ||
Comment 1•11 years ago
|
||
Attachment #751404 -
Flags: review?(nfroyd)
Comment 2•11 years ago
|
||
(In reply to Justin Lebar [:jlebar] from comment #0) > I've wanted a pointer-sized CAS for a while now. > > It returns a bool instead of returning the old value of *ptr because that's > all we can do with <atomic>, afaict. Windows and GCC both give us both > options. No, that's not true. The parameter T &expected in the <atomic> compare_exchange gets set to the value of the variable if the comparison failed.
Reporter | ||
Comment 3•11 years ago
|
||
Ah, okay! I can replicate that interface in the patch, if we want. I guess I'm a bit afraid of having tricky reference params, but it's not too bad...
Comment 4•11 years ago
|
||
Comment on attachment 751404 [details] [diff] [review] Patch, v1 Review of attachment 751404 [details] [diff] [review]: ----------------------------------------------------------------- Works for me. ::: mfbt/Atomics.h @@ +550,5 @@ > return _InterlockedExchange(ptr, val); > } > + static bool compareExchange(Type* ptr, Type oldVal, Type newVal) { > + return _InterlockedCompareExchange(ptr, newVal, oldVal) == oldVal; > + } Please mention the new requirement of defining compareExchange in the block comment describing PrimitiveIntrinsics, with a brief blurb about it. @@ +818,5 @@ > return Intrinsics::exchange(mValue, aValue); > } > + bool compareExchange(T aOldValue, T aNewValue) { > + return Intrinsics::compareExchange(mValue, aOldValue, aNewValue); > + } Please add a comment here describing the interface.
Attachment #751404 -
Flags: review?(nfroyd) → review+
Reporter | ||
Comment 5•11 years ago
|
||
https://hg.mozilla.org/integration/mozilla-inbound/rev/448e9861db9f
Comment 6•11 years ago
|
||
https://hg.mozilla.org/mozilla-central/rev/448e9861db9f
Status: NEW → RESOLVED
Closed: 11 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla24
Comment 7•11 years ago
|
||
Made Win64 burn, https://tbpl.mozilla.org/php/getParsedLog.php?id=23411638&tree=Mozilla-Central, you'll probably be hearing about that eventually.
You need to log in
before you can comment on or make changes to this bug.
Description
•