Thread: Move more helper functions into members
This commit is contained in:
parent
d1b7587647
commit
333557152c
6 changed files with 16 additions and 36 deletions
|
@ -33,7 +33,7 @@ public:
|
||||||
ResultVal<bool> WaitSynchronization() override {
|
ResultVal<bool> WaitSynchronization() override {
|
||||||
bool wait = locked;
|
bool wait = locked;
|
||||||
if (locked) {
|
if (locked) {
|
||||||
Handle thread = GetCurrentThreadHandle();
|
Handle thread = GetCurrentThread()->GetHandle();
|
||||||
if (std::find(waiting_threads.begin(), waiting_threads.end(), thread) == waiting_threads.end()) {
|
if (std::find(waiting_threads.begin(), waiting_threads.end(), thread) == waiting_threads.end()) {
|
||||||
waiting_threads.push_back(thread);
|
waiting_threads.push_back(thread);
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,7 +40,7 @@ static MutexMap g_mutex_held_locks;
|
||||||
* @param mutex Mutex that is to be acquired
|
* @param mutex Mutex that is to be acquired
|
||||||
* @param thread Thread that will acquired
|
* @param thread Thread that will acquired
|
||||||
*/
|
*/
|
||||||
void MutexAcquireLock(Mutex* mutex, Handle thread = GetCurrentThreadHandle()) {
|
void MutexAcquireLock(Mutex* mutex, Handle thread = GetCurrentThread()->GetHandle()) {
|
||||||
g_mutex_held_locks.insert(std::make_pair(thread, mutex->GetHandle()));
|
g_mutex_held_locks.insert(std::make_pair(thread, mutex->GetHandle()));
|
||||||
mutex->lock_thread = thread;
|
mutex->lock_thread = thread;
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,7 @@ public:
|
||||||
|
|
||||||
if (wait) {
|
if (wait) {
|
||||||
Kernel::WaitCurrentThread(WAITTYPE_SEMA, GetHandle());
|
Kernel::WaitCurrentThread(WAITTYPE_SEMA, GetHandle());
|
||||||
waiting_threads.push(GetCurrentThreadHandle());
|
waiting_threads.push(GetCurrentThread()->GetHandle());
|
||||||
} else {
|
} else {
|
||||||
--available_count;
|
--available_count;
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,7 @@ namespace Kernel {
|
||||||
ResultVal<bool> Thread::WaitSynchronization() {
|
ResultVal<bool> Thread::WaitSynchronization() {
|
||||||
const bool wait = status != THREADSTATUS_DORMANT;
|
const bool wait = status != THREADSTATUS_DORMANT;
|
||||||
if (wait) {
|
if (wait) {
|
||||||
Handle thread = GetCurrentThreadHandle();
|
Handle thread = GetCurrentThread()->GetHandle();
|
||||||
if (std::find(waiting_threads.begin(), waiting_threads.end(), thread) == waiting_threads.end()) {
|
if (std::find(waiting_threads.begin(), waiting_threads.end(), thread) == waiting_threads.end()) {
|
||||||
waiting_threads.push_back(thread);
|
waiting_threads.push_back(thread);
|
||||||
}
|
}
|
||||||
|
@ -50,11 +50,6 @@ Thread* GetCurrentThread() {
|
||||||
return current_thread;
|
return current_thread;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Gets the current thread handle
|
|
||||||
Handle GetCurrentThreadHandle() {
|
|
||||||
return GetCurrentThread()->GetHandle();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets the current thread
|
/// Sets the current thread
|
||||||
inline void SetCurrentThread(Thread* t) {
|
inline void SetCurrentThread(Thread* t) {
|
||||||
current_thread = t;
|
current_thread = t;
|
||||||
|
@ -285,7 +280,7 @@ void DebugThreadQueue() {
|
||||||
if (!thread) {
|
if (!thread) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
LOG_DEBUG(Kernel, "0x%02X 0x%08X (current)", thread->current_priority, GetCurrentThreadHandle());
|
LOG_DEBUG(Kernel, "0x%02X 0x%08X (current)", thread->current_priority, GetCurrentThread()->GetHandle());
|
||||||
for (u32 i = 0; i < thread_queue.size(); i++) {
|
for (u32 i = 0; i < thread_queue.size(); i++) {
|
||||||
Handle handle = thread_queue[i];
|
Handle handle = thread_queue[i];
|
||||||
s32 priority = thread_ready_queue.contains(handle);
|
s32 priority = thread_ready_queue.contains(handle);
|
||||||
|
@ -429,17 +424,6 @@ void Reschedule() {
|
||||||
ResumeThreadFromWait(prev->GetHandle());
|
ResumeThreadFromWait(prev->GetHandle());
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultCode GetThreadId(u32* thread_id, Handle handle) {
|
|
||||||
Thread* thread = g_handle_table.Get<Thread>(handle);
|
|
||||||
if (thread == nullptr)
|
|
||||||
return ResultCode(ErrorDescription::InvalidHandle, ErrorModule::OS,
|
|
||||||
ErrorSummary::WrongArgument, ErrorLevel::Permanent);
|
|
||||||
|
|
||||||
*thread_id = thread->thread_id;
|
|
||||||
|
|
||||||
return RESULT_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void ThreadingInit() {
|
void ThreadingInit() {
|
||||||
|
|
|
@ -73,6 +73,8 @@ public:
|
||||||
s32 GetPriority() const { return current_priority; }
|
s32 GetPriority() const { return current_priority; }
|
||||||
void SetPriority(s32 priority);
|
void SetPriority(s32 priority);
|
||||||
|
|
||||||
|
u32 GetThreadId() const { return thread_id; }
|
||||||
|
|
||||||
Core::ThreadContext context;
|
Core::ThreadContext context;
|
||||||
|
|
||||||
u32 thread_id;
|
u32 thread_id;
|
||||||
|
@ -108,14 +110,6 @@ void Reschedule();
|
||||||
/// Stops the current thread
|
/// Stops the current thread
|
||||||
ResultCode StopThread(Handle thread, const char* reason);
|
ResultCode StopThread(Handle thread, const char* reason);
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieves the ID of the specified thread handle
|
|
||||||
* @param thread_id Will contain the output thread id
|
|
||||||
* @param handle Handle to the thread we want
|
|
||||||
* @return Whether the function was successful or not
|
|
||||||
*/
|
|
||||||
ResultCode GetThreadId(u32* thread_id, Handle handle);
|
|
||||||
|
|
||||||
/// Resumes a thread from waiting by marking it as "ready"
|
/// Resumes a thread from waiting by marking it as "ready"
|
||||||
void ResumeThreadFromWait(Handle handle);
|
void ResumeThreadFromWait(Handle handle);
|
||||||
|
|
||||||
|
@ -128,15 +122,12 @@ void ArbitrateAllThreads(u32 arbiter, u32 address);
|
||||||
/// Gets the current thread
|
/// Gets the current thread
|
||||||
Thread* GetCurrentThread();
|
Thread* GetCurrentThread();
|
||||||
|
|
||||||
/// Gets the current thread handle
|
|
||||||
Handle GetCurrentThreadHandle();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Puts the current thread in the wait state for the given type
|
* Puts the current thread in the wait state for the given type
|
||||||
* @param wait_type Type of wait
|
* @param wait_type Type of wait
|
||||||
* @param wait_handle Handle of Kernel object that we are waiting on, defaults to current thread
|
* @param wait_handle Handle of Kernel object that we are waiting on, defaults to current thread
|
||||||
*/
|
*/
|
||||||
void WaitCurrentThread(WaitType wait_type, Handle wait_handle=GetCurrentThreadHandle());
|
void WaitCurrentThread(WaitType wait_type, Handle wait_handle = GetCurrentThread()->GetHandle());
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Puts the current thread in the wait state for the given type
|
* Puts the current thread in the wait state for the given type
|
||||||
|
|
|
@ -245,7 +245,7 @@ static Result CreateThread(u32 priority, u32 entry_point, u32 arg, u32 stack_top
|
||||||
|
|
||||||
/// Called when a thread exits
|
/// Called when a thread exits
|
||||||
static u32 ExitThread() {
|
static u32 ExitThread() {
|
||||||
Handle thread = Kernel::GetCurrentThreadHandle();
|
Handle thread = Kernel::GetCurrentThread()->GetHandle();
|
||||||
|
|
||||||
LOG_TRACE(Kernel_SVC, "called, pc=0x%08X", Core::g_app_core->GetPC()); // PC = 0x0010545C
|
LOG_TRACE(Kernel_SVC, "called, pc=0x%08X", Core::g_app_core->GetPC()); // PC = 0x0010545C
|
||||||
|
|
||||||
|
@ -292,8 +292,13 @@ static Result ReleaseMutex(Handle handle) {
|
||||||
/// Get the ID for the specified thread.
|
/// Get the ID for the specified thread.
|
||||||
static Result GetThreadId(u32* thread_id, Handle handle) {
|
static Result GetThreadId(u32* thread_id, Handle handle) {
|
||||||
LOG_TRACE(Kernel_SVC, "called thread=0x%08X", handle);
|
LOG_TRACE(Kernel_SVC, "called thread=0x%08X", handle);
|
||||||
ResultCode result = Kernel::GetThreadId(thread_id, handle);
|
|
||||||
return result.raw;
|
const Kernel::Thread* thread = Kernel::g_handle_table.Get<Kernel::Thread>(handle);
|
||||||
|
if (thread == nullptr)
|
||||||
|
return InvalidHandle(ErrorModule::Kernel).raw;
|
||||||
|
|
||||||
|
*thread_id = thread->GetThreadId();
|
||||||
|
return RESULT_SUCCESS.raw;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a semaphore
|
/// Creates a semaphore
|
||||||
|
|
Loading…
Reference in a new issue