Commit 9fca3ad7 authored by Michael Lippautz's avatar Michael Lippautz Committed by Commit Bot

[heap] Use template specialization for MarkBit accessors

BUG=chromium:694255
R=hpayer@chromium.org

Change-Id: Ie8d23ec88e9b8f97ac094630f4e46e9b31f93cc5
Reviewed-on: https://chromium-review.googlesource.com/452817Reviewed-by: 's avatarHannes Payer <hpayer@chromium.org>
Commit-Queue: Michael Lippautz <mlippautz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#43829}
parent 2b1ed944
......@@ -39,47 +39,13 @@ class MarkBit {
}
template <AccessMode mode = NON_ATOMIC>
inline bool Set() {
if (mode == ATOMIC) {
base::Atomic32 old_value;
base::Atomic32 new_value;
do {
old_value = base::NoBarrier_Load(cell_);
if (old_value & mask_) return false;
new_value = old_value | mask_;
} while (base::Release_CompareAndSwap(cell_, old_value, new_value) !=
old_value);
} else {
*cell_ |= mask_;
}
return true;
}
inline bool Set();
template <AccessMode mode = NON_ATOMIC>
inline bool Get() {
if (mode == ATOMIC) {
return (base::Acquire_Load(cell_) & mask_) != 0;
} else {
return (base::NoBarrier_Load(cell_) & mask_) != 0;
}
}
inline bool Get();
template <AccessMode mode = NON_ATOMIC>
inline bool Clear() {
if (mode == ATOMIC) {
base::Atomic32 old_value;
base::Atomic32 new_value;
do {
old_value = base::NoBarrier_Load(cell_);
if (!(old_value & mask_)) return false;
new_value = old_value & ~mask_;
} while (base::Release_CompareAndSwap(cell_, old_value, new_value) !=
old_value);
} else {
*cell_ &= ~mask_;
}
return true;
}
inline bool Clear();
base::Atomic32* cell_;
base::Atomic32 mask_;
......@@ -89,6 +55,54 @@ class MarkBit {
friend class Marking;
};
template <>
inline bool MarkBit::Set<MarkBit::NON_ATOMIC>() {
*cell_ |= mask_;
return true;
}
template <>
inline bool MarkBit::Set<MarkBit::ATOMIC>() {
base::Atomic32 old_value;
base::Atomic32 new_value;
do {
old_value = base::NoBarrier_Load(cell_);
if (old_value & mask_) return false;
new_value = old_value | mask_;
} while (base::Release_CompareAndSwap(cell_, old_value, new_value) !=
old_value);
return true;
}
template <>
inline bool MarkBit::Get<MarkBit::NON_ATOMIC>() {
return (base::NoBarrier_Load(cell_) & mask_) != 0;
}
template <>
inline bool MarkBit::Get<MarkBit::ATOMIC>() {
return (base::Acquire_Load(cell_) & mask_) != 0;
}
template <>
inline bool MarkBit::Clear<MarkBit::NON_ATOMIC>() {
*cell_ &= ~mask_;
return true;
}
template <>
inline bool MarkBit::Clear<MarkBit::ATOMIC>() {
base::Atomic32 old_value;
base::Atomic32 new_value;
do {
old_value = base::NoBarrier_Load(cell_);
if (!(old_value & mask_)) return false;
new_value = old_value & ~mask_;
} while (base::Release_CompareAndSwap(cell_, old_value, new_value) !=
old_value);
return true;
}
// Bitmap is a sequence of cells each containing fixed number of bits.
class Bitmap {
public:
......
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