aboutsummaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorlizzie <lizzie@eden-emu.dev>2026-07-09 03:46:06 +0200
committercrueter <crueter@eden-emu.dev>2026-07-09 03:46:06 +0200
commitc2e74a93804f0ba4e7e87a95e8881bbe817aa0a4 (patch)
tree43e99e5f3f385c3301cbe77e0919ec50f52a00d8 /src/common
parente401414aabb37c903b4f02018d5a7fba3d767321 (diff)
[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 <lizzie@eden-emu.dev> Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/4096 Reviewed-by: CamilleLaVey <camillelavey99@gmail.com> Reviewed-by: MaranBr <maranbr@eden-emu.dev>
Diffstat (limited to 'src/common')
-rw-r--r--src/common/CMakeLists.txt2
-rw-r--r--src/common/detached_tasks.cpp41
-rw-r--r--src/common/detached_tasks.h39
3 files changed, 0 insertions, 82 deletions
diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt
index 7bb4c3aa4a..87c4642f04 100644
--- a/src/common/CMakeLists.txt
+++ b/src/common/CMakeLists.txt
@@ -40,8 +40,6 @@ add_library(
container_hash.h
demangle.cpp
demangle.h
- detached_tasks.cpp
- detached_tasks.h
device_power_state.cpp
device_power_state.h
div_ceil.h
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 <thread>
-#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<void()> 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
diff --git a/src/common/detached_tasks.h b/src/common/detached_tasks.h
deleted file mode 100644
index 416a2d7f3d..0000000000
--- a/src/common/detached_tasks.h
+++ /dev/null
@@ -1,39 +0,0 @@
-// SPDX-FileCopyrightText: 2018 Citra Emulator Project
-// SPDX-License-Identifier: GPL-2.0-or-later
-
-#pragma once
-
-#include <condition_variable>
-#include <functional>
-
-namespace Common {
-
-/**
- * A background manager which ensures that all detached task is finished before program exits.
- *
- * Some tasks, telemetry submission for example, prefer executing asynchronously and don't care
- * about the result. These tasks are suitable for std::thread::detach(). However, this is unsafe if
- * the task is launched just before the program exits (which is a common case for telemetry), so we
- * need to block on these tasks on program exit.
- *
- * To make detached task safe, a single DetachedTasks object should be placed in the main(), and
- * call WaitForAllTasks() after all program execution but before global/static variable destruction.
- * Any potentially unsafe detached task should be executed via DetachedTasks::AddTask.
- */
-class DetachedTasks {
-public:
- DetachedTasks();
- ~DetachedTasks();
- void WaitForAllTasks();
-
- static void AddTask(std::function<void()> task);
-
-private:
- static DetachedTasks* instance;
-
- std::condition_variable cv;
- std::mutex mutex;
- int count = 0;
-};
-
-} // namespace Common