mirror of
https://git.eden-emu.dev/eden-emu/eden.git
synced 2026-10-06 14:09:58 +00:00
[kernel] Ensure all kernel objects exist before destroying them and avoid infinite loop between Open() and Close() functions (#261)
This ensures that all kernel objects exist before destroying them and prevents an infinite loop between the Open() and Close() functions. Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/261 Reviewed-by: Shinmegumi <shinmegumi@eden-emu.dev> Co-authored-by: MaranBr <maranbr@outlook.com> Co-committed-by: MaranBr <maranbr@outlook.com>
This commit is contained in:
@@ -1,5 +1,8 @@
|
|||||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
|
||||||
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
@@ -153,12 +156,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 ref count hits 1, destroy the object.
|
||||||
if (cur_ref_count - 1 == 0) {
|
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);
|
||||||
|
|||||||
Reference in New Issue
Block a user