kernel/Thread: move thread wake up table and callback handle into the manager
This commit is contained in:
parent
0478bc3dee
commit
7fc61920cc
|
@ -22,7 +22,6 @@ KernelSystem::KernelSystem(u32 system_mode) {
|
||||||
|
|
||||||
resource_limits = std::make_unique<ResourceLimitList>(*this);
|
resource_limits = std::make_unique<ResourceLimitList>(*this);
|
||||||
thread_manager = std::make_unique<ThreadManager>();
|
thread_manager = std::make_unique<ThreadManager>();
|
||||||
Kernel::ThreadingInit();
|
|
||||||
Kernel::TimersInit();
|
Kernel::TimersInit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,6 @@
|
||||||
#include "core/arm/arm_interface.h"
|
#include "core/arm/arm_interface.h"
|
||||||
#include "core/arm/skyeye_common/armstate.h"
|
#include "core/arm/skyeye_common/armstate.h"
|
||||||
#include "core/core.h"
|
#include "core/core.h"
|
||||||
#include "core/core_timing.h"
|
|
||||||
#include "core/hle/kernel/errors.h"
|
#include "core/hle/kernel/errors.h"
|
||||||
#include "core/hle/kernel/handle_table.h"
|
#include "core/hle/kernel/handle_table.h"
|
||||||
#include "core/hle/kernel/kernel.h"
|
#include "core/hle/kernel/kernel.h"
|
||||||
|
@ -26,9 +25,6 @@
|
||||||
|
|
||||||
namespace Kernel {
|
namespace Kernel {
|
||||||
|
|
||||||
/// Event type for the thread wake up event
|
|
||||||
static CoreTiming::EventType* ThreadWakeupEventType = nullptr;
|
|
||||||
|
|
||||||
bool Thread::ShouldWait(Thread* thread) const {
|
bool Thread::ShouldWait(Thread* thread) const {
|
||||||
return status != ThreadStatus::Dead;
|
return status != ThreadStatus::Dead;
|
||||||
}
|
}
|
||||||
|
@ -37,8 +33,6 @@ void Thread::Acquire(Thread* thread) {
|
||||||
ASSERT_MSG(!ShouldWait(thread), "object unavailable!");
|
ASSERT_MSG(!ShouldWait(thread), "object unavailable!");
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::unordered_map<u64, Thread*> wakeup_callback_table;
|
|
||||||
|
|
||||||
// Lists all thread ids that aren't deleted/etc.
|
// Lists all thread ids that aren't deleted/etc.
|
||||||
static std::vector<SharedPtr<Thread>> thread_list;
|
static std::vector<SharedPtr<Thread>> thread_list;
|
||||||
|
|
||||||
|
@ -57,8 +51,8 @@ Thread* ThreadManager::GetCurrentThread() const {
|
||||||
|
|
||||||
void Thread::Stop() {
|
void Thread::Stop() {
|
||||||
// Cancel any outstanding wakeup events for this thread
|
// Cancel any outstanding wakeup events for this thread
|
||||||
CoreTiming::UnscheduleEvent(ThreadWakeupEventType, thread_id);
|
CoreTiming::UnscheduleEvent(thread_manager.ThreadWakeupEventType, thread_id);
|
||||||
wakeup_callback_table.erase(thread_id);
|
thread_manager.wakeup_callback_table.erase(thread_id);
|
||||||
|
|
||||||
// Clean up thread from ready queue
|
// Clean up thread from ready queue
|
||||||
// This is only needed when the thread is termintated forcefully (SVC TerminateProcess)
|
// This is only needed when the thread is termintated forcefully (SVC TerminateProcess)
|
||||||
|
@ -162,12 +156,7 @@ void ThreadManager::ExitCurrentThread() {
|
||||||
thread_list.end());
|
thread_list.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
void ThreadManager::ThreadWakeupCallback(u64 thread_id, s64 cycles_late) {
|
||||||
* Callback that will wake up the thread it was scheduled for
|
|
||||||
* @param thread_id The ID of the thread that's been awoken
|
|
||||||
* @param cycles_late The number of CPU cycles that have passed since the desired wakeup time
|
|
||||||
*/
|
|
||||||
static void ThreadWakeupCallback(u64 thread_id, s64 cycles_late) {
|
|
||||||
SharedPtr<Thread> thread = wakeup_callback_table.at(thread_id);
|
SharedPtr<Thread> thread = wakeup_callback_table.at(thread_id);
|
||||||
if (thread == nullptr) {
|
if (thread == nullptr) {
|
||||||
LOG_CRITICAL(Kernel, "Callback fired for invalid thread {:08X}", thread_id);
|
LOG_CRITICAL(Kernel, "Callback fired for invalid thread {:08X}", thread_id);
|
||||||
|
@ -196,7 +185,8 @@ void Thread::WakeAfterDelay(s64 nanoseconds) {
|
||||||
if (nanoseconds == -1)
|
if (nanoseconds == -1)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
CoreTiming::ScheduleEvent(nsToCycles(nanoseconds), ThreadWakeupEventType, thread_id);
|
CoreTiming::ScheduleEvent(nsToCycles(nanoseconds), thread_manager.ThreadWakeupEventType,
|
||||||
|
thread_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Thread::ResumeFromWait() {
|
void Thread::ResumeFromWait() {
|
||||||
|
@ -334,7 +324,7 @@ ResultVal<SharedPtr<Thread>> KernelSystem::CreateThread(std::string name, VAddr
|
||||||
thread->wait_objects.clear();
|
thread->wait_objects.clear();
|
||||||
thread->wait_address = 0;
|
thread->wait_address = 0;
|
||||||
thread->name = std::move(name);
|
thread->name = std::move(name);
|
||||||
wakeup_callback_table[thread->thread_id] = thread.get();
|
thread_manager->wakeup_callback_table[thread->thread_id] = thread.get();
|
||||||
thread->owner_process = &owner_process;
|
thread->owner_process = &owner_process;
|
||||||
|
|
||||||
// Find the next available TLS index, and mark it as used
|
// Find the next available TLS index, and mark it as used
|
||||||
|
@ -476,8 +466,11 @@ VAddr Thread::GetCommandBufferAddress() const {
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void ThreadingInit() {
|
ThreadManager::ThreadManager() {
|
||||||
ThreadWakeupEventType = CoreTiming::RegisterEvent("ThreadWakeupCallback", ThreadWakeupCallback);
|
ThreadWakeupEventType =
|
||||||
|
CoreTiming::RegisterEvent("ThreadWakeupCallback", [this](u64 thread_id, s64 cycle_late) {
|
||||||
|
ThreadWakeupCallback(thread_id, cycle_late);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void ThreadingShutdown() {
|
void ThreadingShutdown() {
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
#include "common/common_types.h"
|
#include "common/common_types.h"
|
||||||
#include "common/thread_queue_list.h"
|
#include "common/thread_queue_list.h"
|
||||||
#include "core/arm/arm_interface.h"
|
#include "core/arm/arm_interface.h"
|
||||||
|
#include "core/core_timing.h"
|
||||||
#include "core/hle/kernel/object.h"
|
#include "core/hle/kernel/object.h"
|
||||||
#include "core/hle/kernel/wait_object.h"
|
#include "core/hle/kernel/wait_object.h"
|
||||||
#include "core/hle/result.h"
|
#include "core/hle/result.h"
|
||||||
|
@ -56,6 +57,8 @@ enum class ThreadWakeupReason {
|
||||||
|
|
||||||
class ThreadManager {
|
class ThreadManager {
|
||||||
public:
|
public:
|
||||||
|
ThreadManager();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new thread ID
|
* Creates a new thread ID
|
||||||
* @return The new thread ID
|
* @return The new thread ID
|
||||||
|
@ -105,9 +108,20 @@ private:
|
||||||
*/
|
*/
|
||||||
Thread* PopNextReadyThread();
|
Thread* PopNextReadyThread();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Callback that will wake up the thread it was scheduled for
|
||||||
|
* @param thread_id The ID of the thread that's been awoken
|
||||||
|
* @param cycles_late The number of CPU cycles that have passed since the desired wakeup time
|
||||||
|
*/
|
||||||
|
void ThreadWakeupCallback(u64 thread_id, s64 cycles_late);
|
||||||
|
|
||||||
u32 next_thread_id = 1;
|
u32 next_thread_id = 1;
|
||||||
SharedPtr<Thread> current_thread;
|
SharedPtr<Thread> current_thread;
|
||||||
Common::ThreadQueueList<Thread*, ThreadPrioLowest + 1> ready_queue;
|
Common::ThreadQueueList<Thread*, ThreadPrioLowest + 1> ready_queue;
|
||||||
|
std::unordered_map<u64, Thread*> wakeup_callback_table;
|
||||||
|
|
||||||
|
/// Event type for the thread wake up event
|
||||||
|
CoreTiming::EventType* ThreadWakeupEventType = nullptr;
|
||||||
|
|
||||||
friend class Thread;
|
friend class Thread;
|
||||||
friend class KernelSystem;
|
friend class KernelSystem;
|
||||||
|
@ -286,11 +300,6 @@ private:
|
||||||
SharedPtr<Thread> SetupMainThread(KernelSystem& kernel, u32 entry_point, u32 priority,
|
SharedPtr<Thread> SetupMainThread(KernelSystem& kernel, u32 entry_point, u32 priority,
|
||||||
SharedPtr<Process> owner_process);
|
SharedPtr<Process> owner_process);
|
||||||
|
|
||||||
/**
|
|
||||||
* Initialize threading
|
|
||||||
*/
|
|
||||||
void ThreadingInit();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Shutdown threading
|
* Shutdown threading
|
||||||
*/
|
*/
|
||||||
|
|
Reference in New Issue