kern: use new AtomicRef, use Atomic<bool>

This commit is contained in:
Michael Scire 2021-10-20 13:29:38 -07:00
parent aed9d3f535
commit 20716cb3de
7 changed files with 334 additions and 160 deletions

View file

@ -76,18 +76,20 @@ namespace ams::kern {
NON_MOVEABLE(KSlabHeapBase);
private:
size_t m_obj_size{};
util::Atomic<uintptr_t> m_peak{0};
uintptr_t m_peak{};
uintptr_t m_start{};
uintptr_t m_end{};
private:
ALWAYS_INLINE void UpdatePeakImpl(uintptr_t obj) {
const util::AtomicRef<uintptr_t> peak_ref(m_peak);
const uintptr_t alloc_peak = obj + this->GetObjectSize();
uintptr_t cur_peak = m_peak.Load<std::memory_order_relaxed>();
uintptr_t cur_peak = m_peak;
do {
if (alloc_peak <= cur_peak) {
break;
}
} while (!m_peak.CompareExchangeStrong(cur_peak, alloc_peak));
} while (!peak_ref.CompareExchangeStrong(cur_peak, alloc_peak));
}
public:
constexpr KSlabHeapBase() = default;
@ -110,8 +112,7 @@ namespace ams::kern {
const size_t num_obj = (memory_size / obj_size);
m_start = reinterpret_cast<uintptr_t>(memory);
m_end = m_start + num_obj * obj_size;
m_peak.Store<std::memory_order_relaxed>(m_start);
m_peak = m_start;
/* Free the objects. */
u8 *cur = reinterpret_cast<u8 *>(m_end);
@ -175,7 +176,7 @@ namespace ams::kern {
}
ALWAYS_INLINE size_t GetPeakIndex() const {
return this->GetObjectIndex(reinterpret_cast<const void *>(m_peak.Load<std::memory_order_relaxed>()));
return this->GetObjectIndex(reinterpret_cast<const void *>(m_peak));
}
ALWAYS_INLINE uintptr_t GetSlabHeapAddress() const {