Commit 5a4da390 authored by Omer Katz's avatar Omer Katz Committed by Commit Bot

heap: Use atomic version of swap.

Bug: 986235
Change-Id: Ide481dbd27b7a0531b8fe003c80d15126a405bf5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2105334
Commit-Queue: Omer Katz <omerkatz@chromium.org>
Reviewed-by: default avatarMichael Lippautz <mlippautz@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#751209}
parent 889c678a
...@@ -341,6 +341,14 @@ ALWAYS_INLINE void AtomicMemzero<3 * sizeof(size_t)>(void* buf) { ...@@ -341,6 +341,14 @@ ALWAYS_INLINE void AtomicMemzero<3 * sizeof(size_t)>(void* buf) {
->store(0, std::memory_order_relaxed); ->store(0, std::memory_order_relaxed);
} }
// Swaps values using atomic writes.
template <typename T>
ALWAYS_INLINE void AtomicWriteSwap(T& lhs, T& rhs) {
T tmp_val = rhs;
AsAtomicPtr(&rhs)->store(lhs, std::memory_order_relaxed);
AsAtomicPtr(&lhs)->store(tmp_val, std::memory_order_relaxed);
}
} // namespace WTF } // namespace WTF
// This version of placement new omits a 0 check. // This version of placement new omits a 0 check.
......
...@@ -2012,9 +2012,7 @@ void HashTable<Key, ...@@ -2012,9 +2012,7 @@ void HashTable<Key,
// race). Atomic reads are not needed here because this method is only called // race). Atomic reads are not needed here because this method is only called
// on the mutator thread, which is also the only one that writes to them, so // on the mutator thread, which is also the only one that writes to them, so
// there is *no* risk of data races when reading. // there is *no* risk of data races when reading.
Value* tmp_table = other.table_; AtomicWriteSwap(table_, other.table_);
AsAtomicPtr(&other.table_)->store(table_, std::memory_order_relaxed);
AsAtomicPtr(&table_)->store(tmp_table, std::memory_order_relaxed);
Allocator::template BackingWriteBarrierForHashTable<HashTable>(&table_); Allocator::template BackingWriteBarrierForHashTable<HashTable>(&table_);
Allocator::template BackingWriteBarrierForHashTable<HashTable>(&other.table_); Allocator::template BackingWriteBarrierForHashTable<HashTable>(&other.table_);
if (IsWeak<ValueType>::value) { if (IsWeak<ValueType>::value) {
......
...@@ -583,7 +583,7 @@ class VectorBuffer<T, 0, Allocator> : protected VectorBufferBase<T, Allocator> { ...@@ -583,7 +583,7 @@ class VectorBuffer<T, 0, Allocator> : protected VectorBufferBase<T, Allocator> {
OffsetRange other_hole) { OffsetRange other_hole) {
static_assert(VectorTraits<T>::kCanSwapUsingCopyOrMove, static_assert(VectorTraits<T>::kCanSwapUsingCopyOrMove,
"Cannot swap using copy or move."); "Cannot swap using copy or move.");
std::swap(buffer_, other.buffer_); AtomicWriteSwap(buffer_, other.buffer_);
std::swap(capacity_, other.capacity_); std::swap(capacity_, other.capacity_);
std::swap(size_, other.size_); std::swap(size_, other.size_);
Allocator::BackingWriteBarrier(&buffer_); Allocator::BackingWriteBarrier(&buffer_);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment