From c2e74a93804f0ba4e7e87a95e8881bbe817aa0a4 Mon Sep 17 00:00:00 2001 From: lizzie Date: Thu, 9 Jul 2026 03:46:06 +0200 Subject: [common] remove DetachedTasks object usage (#4096) this was only ever used for announce room json on one single instance this object is pretty much a danger to society and shouldnt exist, especially since its: a) a singleton b) spawns objects out of thin air c) doesn't respect RAII and can outlive its parent objects (big no no) generally we shouldnt endorse objects like these in the future, but alas, it existed, now it has to begone additionally there is a similar object in KWorkerTaskManager but it's not as egregious as this one. check that this didnt break the usual announce room json logic Signed-off-by: lizzie Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/4096 Reviewed-by: CamilleLaVey Reviewed-by: MaranBr --- src/common/detached_tasks.cpp | 41 ----------------------------------------- 1 file changed, 41 deletions(-) delete mode 100644 src/common/detached_tasks.cpp (limited to 'src/common/detached_tasks.cpp') diff --git a/src/common/detached_tasks.cpp b/src/common/detached_tasks.cpp deleted file mode 100644 index f2ed795cc2..0000000000 --- a/src/common/detached_tasks.cpp +++ /dev/null @@ -1,41 +0,0 @@ -// SPDX-FileCopyrightText: 2018 Citra Emulator Project -// SPDX-License-Identifier: GPL-2.0-or-later - -#include -#include "common/assert.h" -#include "common/detached_tasks.h" - -namespace Common { - -DetachedTasks* DetachedTasks::instance = nullptr; - -DetachedTasks::DetachedTasks() { - ASSERT(instance == nullptr); - instance = this; -} - -void DetachedTasks::WaitForAllTasks() { - std::unique_lock lock{mutex}; - cv.wait(lock, [this]() { return count == 0; }); -} - -DetachedTasks::~DetachedTasks() { - WaitForAllTasks(); - - std::unique_lock lock{mutex}; - ASSERT(count == 0); - instance = nullptr; -} - -void DetachedTasks::AddTask(std::function task) { - std::unique_lock lock{instance->mutex}; - ++instance->count; - std::thread([task_{std::move(task)}]() { - task_(); - std::unique_lock thread_lock{instance->mutex}; - --instance->count; - std::notify_all_at_thread_exit(instance->cv, std::move(thread_lock)); - }).detach(); -} - -} // namespace Common -- cgit v1.2.3