Kernel: Corrections to TimeManager, Scheduler and Mutex.

This commit is contained in:
Fernando Sahmkow 2020-03-08 16:20:05 -04:00
parent 6515c6e8c6
commit 9e9c287f8b
3 changed files with 5 additions and 5 deletions

View File

@ -35,8 +35,6 @@ static std::pair<std::shared_ptr<Thread>, u32> GetHighestPriorityMutexWaitingThr
if (thread->GetMutexWaitAddress() != mutex_addr) if (thread->GetMutexWaitAddress() != mutex_addr)
continue; continue;
ASSERT(thread->GetStatus() == ThreadStatus::WaitMutex);
++num_waiters; ++num_waiters;
if (highest_priority_thread == nullptr || if (highest_priority_thread == nullptr ||
thread->GetPriority() < highest_priority_thread->GetPriority()) { thread->GetPriority() < highest_priority_thread->GetPriority()) {
@ -50,6 +48,7 @@ static std::pair<std::shared_ptr<Thread>, u32> GetHighestPriorityMutexWaitingThr
/// Update the mutex owner field of all threads waiting on the mutex to point to the new owner. /// Update the mutex owner field of all threads waiting on the mutex to point to the new owner.
static void TransferMutexOwnership(VAddr mutex_addr, std::shared_ptr<Thread> current_thread, static void TransferMutexOwnership(VAddr mutex_addr, std::shared_ptr<Thread> current_thread,
std::shared_ptr<Thread> new_owner) { std::shared_ptr<Thread> new_owner) {
current_thread->RemoveMutexWaiter(new_owner);
const auto threads = current_thread->GetMutexWaitingThreads(); const auto threads = current_thread->GetMutexWaitingThreads();
for (const auto& thread : threads) { for (const auto& thread : threads) {
if (thread->GetMutexWaitAddress() != mutex_addr) if (thread->GetMutexWaitAddress() != mutex_addr)

View File

@ -93,7 +93,7 @@ u32 GlobalScheduler::SelectThreads() {
iter++; iter++;
s32 suggested_core_id = suggested->GetProcessorID(); s32 suggested_core_id = suggested->GetProcessorID();
Thread* top_thread = Thread* top_thread =
suggested_core_id > 0 ? top_threads[suggested_core_id] : nullptr; suggested_core_id >= 0 ? top_threads[suggested_core_id] : nullptr;
if (top_thread != suggested) { if (top_thread != suggested) {
if (top_thread != nullptr && if (top_thread != nullptr &&
top_thread->GetPriority() < THREADPRIO_MAX_CORE_MIGRATION) { top_thread->GetPriority() < THREADPRIO_MAX_CORE_MIGRATION) {

View File

@ -32,8 +32,9 @@ void TimeManager::ScheduleTimeEvent(Handle& event_handle, Thread* timetask, s64
event_handle = timetask->GetGlobalHandle(); event_handle = timetask->GetGlobalHandle();
if (nanoseconds > 0) { if (nanoseconds > 0) {
ASSERT(timetask); ASSERT(timetask);
const s64 cycles = Core::Timing::nsToCycles(std::chrono::nanoseconds{nanoseconds}); ASSERT(timetask->GetStatus() != ThreadStatus::Ready);
system.CoreTiming().ScheduleEvent(cycles, time_manager_event_type, event_handle); ASSERT(timetask->GetStatus() != ThreadStatus::WaitMutex);
system.CoreTiming().ScheduleEvent(nanoseconds, time_manager_event_type, event_handle);
} else { } else {
event_handle = InvalidHandle; event_handle = InvalidHandle;
} }