summaryrefslogtreecommitdiff
path: root/src/core/hle/kernel/scheduler.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/hle/kernel/scheduler.cpp')
-rw-r--r--src/core/hle/kernel/scheduler.cpp15
1 files changed, 15 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 @@
9 9
10namespace Kernel { 10namespace Kernel {
11 11
12std::mutex Scheduler::scheduler_mutex;
13
12Scheduler::Scheduler(ARM_Interface* cpu_core) : cpu_core(cpu_core) {} 14Scheduler::Scheduler(ARM_Interface* cpu_core) : cpu_core(cpu_core) {}
13 15
14Scheduler::~Scheduler() { 16Scheduler::~Scheduler() {
@@ -18,6 +20,7 @@ Scheduler::~Scheduler() {
18} 20}
19 21
20bool Scheduler::HaveReadyThreads() { 22bool Scheduler::HaveReadyThreads() {
23 std::lock_guard<std::mutex> lock(scheduler_mutex);
21 return ready_queue.get_first() != nullptr; 24 return ready_queue.get_first() != nullptr;
22} 25}
23 26
@@ -90,6 +93,8 @@ void Scheduler::SwitchContext(Thread* new_thread) {
90} 93}
91 94
92void Scheduler::Reschedule() { 95void Scheduler::Reschedule() {
96 std::lock_guard<std::mutex> lock(scheduler_mutex);
97
93 Thread* cur = GetCurrentThread(); 98 Thread* cur = GetCurrentThread();
94 Thread* next = PopNextReadyThread(); 99 Thread* next = PopNextReadyThread();
95 100
@@ -105,26 +110,36 @@ void Scheduler::Reschedule() {
105} 110}
106 111
107void Scheduler::AddThread(SharedPtr<Thread> thread, u32 priority) { 112void Scheduler::AddThread(SharedPtr<Thread> thread, u32 priority) {
113 std::lock_guard<std::mutex> lock(scheduler_mutex);
114
108 thread_list.push_back(thread); 115 thread_list.push_back(thread);
109 ready_queue.prepare(priority); 116 ready_queue.prepare(priority);
110} 117}
111 118
112void Scheduler::RemoveThread(Thread* thread) { 119void Scheduler::RemoveThread(Thread* thread) {
120 std::lock_guard<std::mutex> lock(scheduler_mutex);
121
113 thread_list.erase(std::remove(thread_list.begin(), thread_list.end(), thread), 122 thread_list.erase(std::remove(thread_list.begin(), thread_list.end(), thread),
114 thread_list.end()); 123 thread_list.end());
115} 124}
116 125
117void Scheduler::ScheduleThread(Thread* thread, u32 priority) { 126void Scheduler::ScheduleThread(Thread* thread, u32 priority) {
127 std::lock_guard<std::mutex> lock(scheduler_mutex);
128
118 ASSERT(thread->status == THREADSTATUS_READY); 129 ASSERT(thread->status == THREADSTATUS_READY);
119 ready_queue.push_back(priority, thread); 130 ready_queue.push_back(priority, thread);
120} 131}
121 132
122void Scheduler::UnscheduleThread(Thread* thread, u32 priority) { 133void Scheduler::UnscheduleThread(Thread* thread, u32 priority) {
134 std::lock_guard<std::mutex> lock(scheduler_mutex);
135
123 ASSERT(thread->status == THREADSTATUS_READY); 136 ASSERT(thread->status == THREADSTATUS_READY);
124 ready_queue.remove(priority, thread); 137 ready_queue.remove(priority, thread);
125} 138}
126 139
127void Scheduler::SetThreadPriority(Thread* thread, u32 priority) { 140void Scheduler::SetThreadPriority(Thread* thread, u32 priority) {
141 std::lock_guard<std::mutex> lock(scheduler_mutex);
142
128 // If thread was ready, adjust queues 143 // If thread was ready, adjust queues
129 if (thread->status == THREADSTATUS_READY) 144 if (thread->status == THREADSTATUS_READY)
130 ready_queue.move(thread, thread->current_priority, priority); 145 ready_queue.move(thread, thread->current_priority, priority);