diff options
author | bunnei <bunneidev@gmail.com> | 2018-05-08 04:12:45 +0200 |
---|---|---|
committer | bunnei <bunneidev@gmail.com> | 2018-05-11 01:34:52 +0200 |
commit | 91af2f94e85e433cb8cca8648e52ac91beae7471 (patch) | |
tree | 14d80a5456ac26fee046e37beb3f18b72c4685ee /src/core/hle | |
parent | wait_tree: Add ideal core and affinity mask. (diff) | |
download | yuzu-91af2f94e85e433cb8cca8648e52ac91beae7471.tar yuzu-91af2f94e85e433cb8cca8648e52ac91beae7471.tar.gz yuzu-91af2f94e85e433cb8cca8648e52ac91beae7471.tar.bz2 yuzu-91af2f94e85e433cb8cca8648e52ac91beae7471.tar.lz yuzu-91af2f94e85e433cb8cca8648e52ac91beae7471.tar.xz yuzu-91af2f94e85e433cb8cca8648e52ac91beae7471.tar.zst yuzu-91af2f94e85e433cb8cca8648e52ac91beae7471.zip |
Diffstat (limited to 'src/core/hle')
-rw-r--r-- | src/core/hle/kernel/scheduler.cpp | 15 | ||||
-rw-r--r-- | src/core/hle/kernel/scheduler.h | 3 |
2 files changed, 18 insertions, 0 deletions
diff --git a/src/core/hle/kernel/scheduler.cpp b/src/core/hle/kernel/scheduler.cpp index ff6a0941a..9cb9e0e5c 100644 --- a/src/core/hle/kernel/scheduler.cpp +++ b/src/core/hle/kernel/scheduler.cpp @@ -9,6 +9,8 @@ namespace Kernel { +std::mutex Scheduler::scheduler_mutex; + Scheduler::Scheduler(ARM_Interface* cpu_core) : cpu_core(cpu_core) {} Scheduler::~Scheduler() { @@ -18,6 +20,7 @@ Scheduler::~Scheduler() { } bool Scheduler::HaveReadyThreads() { + std::lock_guard<std::mutex> lock(scheduler_mutex); return ready_queue.get_first() != nullptr; } @@ -90,6 +93,8 @@ void Scheduler::SwitchContext(Thread* new_thread) { } void Scheduler::Reschedule() { + std::lock_guard<std::mutex> lock(scheduler_mutex); + Thread* cur = GetCurrentThread(); Thread* next = PopNextReadyThread(); @@ -105,26 +110,36 @@ void Scheduler::Reschedule() { } void Scheduler::AddThread(SharedPtr<Thread> thread, u32 priority) { + std::lock_guard<std::mutex> lock(scheduler_mutex); + thread_list.push_back(thread); ready_queue.prepare(priority); } void Scheduler::RemoveThread(Thread* thread) { + std::lock_guard<std::mutex> lock(scheduler_mutex); + thread_list.erase(std::remove(thread_list.begin(), thread_list.end(), thread), thread_list.end()); } void Scheduler::ScheduleThread(Thread* thread, u32 priority) { + std::lock_guard<std::mutex> lock(scheduler_mutex); + ASSERT(thread->status == THREADSTATUS_READY); ready_queue.push_back(priority, thread); } void Scheduler::UnscheduleThread(Thread* thread, u32 priority) { + std::lock_guard<std::mutex> lock(scheduler_mutex); + ASSERT(thread->status == THREADSTATUS_READY); ready_queue.remove(priority, thread); } void Scheduler::SetThreadPriority(Thread* thread, u32 priority) { + std::lock_guard<std::mutex> lock(scheduler_mutex); + // If thread was ready, adjust queues if (thread->status == THREADSTATUS_READY) ready_queue.move(thread, thread->current_priority, priority); diff --git a/src/core/hle/kernel/scheduler.h b/src/core/hle/kernel/scheduler.h index 27d0247d6..a3b5fb8ca 100644 --- a/src/core/hle/kernel/scheduler.h +++ b/src/core/hle/kernel/scheduler.h @@ -4,6 +4,7 @@ #pragma once +#include <mutex> #include <vector> #include "common/common_types.h" #include "common/thread_queue_list.h" @@ -68,6 +69,8 @@ private: SharedPtr<Thread> current_thread = nullptr; ARM_Interface* cpu_core; + + static std::mutex scheduler_mutex; }; } // namespace Kernel |