diff options
author | bunnei <bunneidev@gmail.com> | 2022-01-15 01:24:59 +0100 |
---|---|---|
committer | bunnei <bunneidev@gmail.com> | 2022-01-15 01:43:59 +0100 |
commit | bf32fcc817a0f3fcbe90e8e5b5ba325ef0480d3f (patch) | |
tree | cab10043311fb326552461417e7fe7f47e71ff47 /src/core/hle/kernel | |
parent | common: fiber: YieldTo: Avoid hard crash on nullptr previous_fiber. (diff) | |
download | yuzu-bf32fcc817a0f3fcbe90e8e5b5ba325ef0480d3f.tar yuzu-bf32fcc817a0f3fcbe90e8e5b5ba325ef0480d3f.tar.gz yuzu-bf32fcc817a0f3fcbe90e8e5b5ba325ef0480d3f.tar.bz2 yuzu-bf32fcc817a0f3fcbe90e8e5b5ba325ef0480d3f.tar.lz yuzu-bf32fcc817a0f3fcbe90e8e5b5ba325ef0480d3f.tar.xz yuzu-bf32fcc817a0f3fcbe90e8e5b5ba325ef0480d3f.tar.zst yuzu-bf32fcc817a0f3fcbe90e8e5b5ba325ef0480d3f.zip |
Diffstat (limited to 'src/core/hle/kernel')
-rw-r--r-- | src/core/hle/kernel/k_worker_task.h | 18 | ||||
-rw-r--r-- | src/core/hle/kernel/k_worker_task_manager.cpp | 42 | ||||
-rw-r--r-- | src/core/hle/kernel/k_worker_task_manager.h | 33 |
3 files changed, 93 insertions, 0 deletions
diff --git a/src/core/hle/kernel/k_worker_task.h b/src/core/hle/kernel/k_worker_task.h new file mode 100644 index 000000000..b7794c6a8 --- /dev/null +++ b/src/core/hle/kernel/k_worker_task.h @@ -0,0 +1,18 @@ +// Copyright 2022 yuzu Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include "core/hle/kernel/k_synchronization_object.h" + +namespace Kernel { + +class KWorkerTask : public KSynchronizationObject { +public: + explicit KWorkerTask(KernelCore& kernel_); + + void DoWorkerTask(); +}; + +} // namespace Kernel diff --git a/src/core/hle/kernel/k_worker_task_manager.cpp b/src/core/hle/kernel/k_worker_task_manager.cpp new file mode 100644 index 000000000..785e08111 --- /dev/null +++ b/src/core/hle/kernel/k_worker_task_manager.cpp @@ -0,0 +1,42 @@ +// Copyright 2022 yuzu Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#include "common/assert.h" +#include "core/hle/kernel/k_process.h" +#include "core/hle/kernel/k_thread.h" +#include "core/hle/kernel/k_worker_task.h" +#include "core/hle/kernel/k_worker_task_manager.h" +#include "core/hle/kernel/kernel.h" + +namespace Kernel { + +KWorkerTask::KWorkerTask(KernelCore& kernel_) : KSynchronizationObject{kernel_} {} + +void KWorkerTask::DoWorkerTask() { + if (auto* const thread = this->DynamicCast<KThread*>(); thread != nullptr) { + return thread->DoWorkerTaskImpl(); + } else { + auto* const process = this->DynamicCast<KProcess*>(); + ASSERT(process != nullptr); + + return process->DoWorkerTaskImpl(); + } +} + +KWorkerTaskManager::KWorkerTaskManager() : m_waiting_thread(1, "yuzu:KWorkerTaskManager") {} + +void KWorkerTaskManager::AddTask(KernelCore& kernel, WorkerType type, KWorkerTask* task) { + ASSERT(type <= WorkerType::Count); + kernel.WorkerTaskManager().AddTask(kernel, task); +} + +void KWorkerTaskManager::AddTask(KernelCore& kernel, KWorkerTask* task) { + KScopedSchedulerLock sl(kernel); + m_waiting_thread.QueueWork([task]() { + // Do the task. + task->DoWorkerTask(); + }); +} + +} // namespace Kernel diff --git a/src/core/hle/kernel/k_worker_task_manager.h b/src/core/hle/kernel/k_worker_task_manager.h new file mode 100644 index 000000000..43d1bfcec --- /dev/null +++ b/src/core/hle/kernel/k_worker_task_manager.h @@ -0,0 +1,33 @@ +// Copyright 2022 yuzu Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include "common/common_types.h" +#include "common/thread_worker.h" + +namespace Kernel { + +class KernelCore; +class KWorkerTask; + +class KWorkerTaskManager final { +public: + enum class WorkerType : u32 { + Exit, + Count, + }; + + KWorkerTaskManager(); + + static void AddTask(KernelCore& kernel_, WorkerType type, KWorkerTask* task); + +private: + void AddTask(KernelCore& kernel, KWorkerTask* task); + +private: + Common::ThreadWorker m_waiting_thread; +}; + +} // namespace Kernel |