Browse Source

Ensure all kernel objects exist before destroying them and avoid infinite loop between Open() and Close() functions.

pull/261/head
MaranBr 7 months ago
committed by crueter
parent
commit
160cdda902
  1. 7
      src/core/hle/kernel/k_auto_object.h

7
src/core/hle/kernel/k_auto_object.h

@ -153,12 +153,15 @@ public:
// Atomically decrement the reference count, not allowing it to become negative. // Atomically decrement the reference count, not allowing it to become negative.
u32 cur_ref_count = m_ref_count.load(std::memory_order_acquire); u32 cur_ref_count = m_ref_count.load(std::memory_order_acquire);
do { do {
if (cur_ref_count == 0) {
return;
}
ASSERT(cur_ref_count > 0); ASSERT(cur_ref_count > 0);
} while (!m_ref_count.compare_exchange_weak(cur_ref_count, cur_ref_count - 1, } while (!m_ref_count.compare_exchange_weak(cur_ref_count, cur_ref_count - 1,
std::memory_order_acq_rel)); std::memory_order_acq_rel));
// If ref count hits zero, destroy the object.
if (cur_ref_count - 1 == 0) {
// If ref count hits 1, destroy the object.
if (cur_ref_count == 1) {
KernelCore& kernel = m_kernel; KernelCore& kernel = m_kernel;
this->Destroy(); this->Destroy();
KAutoObject::UnregisterWithKernel(kernel, this); KAutoObject::UnregisterWithKernel(kernel, this);

Loading…
Cancel
Save