Merge pull request #2308 from lioncash/deduction

kernel/scheduler: Minor tidying up
This commit is contained in:
bunnei 2019-03-30 19:59:10 -04:00 committed by GitHub
commit ba3d95e550
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 12 deletions

View File

@ -29,7 +29,7 @@ Scheduler::~Scheduler() {
} }
bool Scheduler::HaveReadyThreads() const { bool Scheduler::HaveReadyThreads() const {
std::lock_guard<std::mutex> lock(scheduler_mutex); std::lock_guard lock{scheduler_mutex};
return !ready_queue.empty(); return !ready_queue.empty();
} }
@ -132,7 +132,7 @@ void Scheduler::UpdateLastContextSwitchTime(Thread* thread, Process* process) {
} }
void Scheduler::Reschedule() { void Scheduler::Reschedule() {
std::lock_guard<std::mutex> lock(scheduler_mutex); std::lock_guard lock{scheduler_mutex};
Thread* cur = GetCurrentThread(); Thread* cur = GetCurrentThread();
Thread* next = PopNextReadyThread(); Thread* next = PopNextReadyThread();
@ -148,35 +148,35 @@ void Scheduler::Reschedule() {
SwitchContext(next); SwitchContext(next);
} }
void Scheduler::AddThread(SharedPtr<Thread> thread, u32 priority) { void Scheduler::AddThread(SharedPtr<Thread> thread) {
std::lock_guard<std::mutex> lock(scheduler_mutex); std::lock_guard lock{scheduler_mutex};
thread_list.push_back(std::move(thread)); thread_list.push_back(std::move(thread));
} }
void Scheduler::RemoveThread(Thread* thread) { void Scheduler::RemoveThread(Thread* thread) {
std::lock_guard<std::mutex> lock(scheduler_mutex); std::lock_guard lock{scheduler_mutex};
thread_list.erase(std::remove(thread_list.begin(), thread_list.end(), thread), thread_list.erase(std::remove(thread_list.begin(), thread_list.end(), thread),
thread_list.end()); thread_list.end());
} }
void Scheduler::ScheduleThread(Thread* thread, u32 priority) { void Scheduler::ScheduleThread(Thread* thread, u32 priority) {
std::lock_guard<std::mutex> lock(scheduler_mutex); std::lock_guard lock{scheduler_mutex};
ASSERT(thread->GetStatus() == ThreadStatus::Ready); ASSERT(thread->GetStatus() == ThreadStatus::Ready);
ready_queue.add(thread, priority); ready_queue.add(thread, priority);
} }
void Scheduler::UnscheduleThread(Thread* thread, u32 priority) { void Scheduler::UnscheduleThread(Thread* thread, u32 priority) {
std::lock_guard<std::mutex> lock(scheduler_mutex); std::lock_guard lock{scheduler_mutex};
ASSERT(thread->GetStatus() == ThreadStatus::Ready); ASSERT(thread->GetStatus() == ThreadStatus::Ready);
ready_queue.remove(thread, priority); ready_queue.remove(thread, priority);
} }
void Scheduler::SetThreadPriority(Thread* thread, u32 priority) { void Scheduler::SetThreadPriority(Thread* thread, u32 priority) {
std::lock_guard<std::mutex> lock(scheduler_mutex); std::lock_guard lock{scheduler_mutex};
if (thread->GetPriority() == priority) { if (thread->GetPriority() == priority) {
return; return;
} }
@ -187,7 +187,7 @@ void Scheduler::SetThreadPriority(Thread* thread, u32 priority) {
} }
Thread* Scheduler::GetNextSuggestedThread(u32 core, u32 maximum_priority) const { Thread* Scheduler::GetNextSuggestedThread(u32 core, u32 maximum_priority) const {
std::lock_guard<std::mutex> lock(scheduler_mutex); std::lock_guard lock{scheduler_mutex};
const u32 mask = 1U << core; const u32 mask = 1U << core;
for (auto* thread : ready_queue) { for (auto* thread : ready_queue) {

View File

@ -38,7 +38,7 @@ public:
u64 GetLastContextSwitchTicks() const; u64 GetLastContextSwitchTicks() const;
/// Adds a new thread to the scheduler /// Adds a new thread to the scheduler
void AddThread(SharedPtr<Thread> thread, u32 priority); void AddThread(SharedPtr<Thread> thread);
/// Removes a thread from the scheduler /// Removes a thread from the scheduler
void RemoveThread(Thread* thread); void RemoveThread(Thread* thread);

View File

@ -199,7 +199,7 @@ ResultVal<SharedPtr<Thread>> Thread::Create(KernelCore& kernel, std::string name
thread->callback_handle = kernel.ThreadWakeupCallbackHandleTable().Create(thread).Unwrap(); thread->callback_handle = kernel.ThreadWakeupCallbackHandleTable().Create(thread).Unwrap();
thread->owner_process = &owner_process; thread->owner_process = &owner_process;
thread->scheduler = &system.Scheduler(processor_id); thread->scheduler = &system.Scheduler(processor_id);
thread->scheduler->AddThread(thread, priority); thread->scheduler->AddThread(thread);
thread->tls_address = thread->owner_process->MarkNextAvailableTLSSlotAsUsed(*thread); thread->tls_address = thread->owner_process->MarkNextAvailableTLSSlotAsUsed(*thread);
// TODO(peachum): move to ScheduleThread() when scheduler is added so selected core is used // TODO(peachum): move to ScheduleThread() when scheduler is added so selected core is used
@ -352,7 +352,7 @@ void Thread::ChangeScheduler() {
if (*new_processor_id != processor_id) { if (*new_processor_id != processor_id) {
// Remove thread from previous core's scheduler // Remove thread from previous core's scheduler
scheduler->RemoveThread(this); scheduler->RemoveThread(this);
next_scheduler.AddThread(this, current_priority); next_scheduler.AddThread(this);
} }
processor_id = *new_processor_id; processor_id = *new_processor_id;