mirror of
https://github.com/citra-emu/citra.git
synced 2024-11-23 22:20:10 +00:00
Thread: Move ResumeThreadFromWait into member function
This commit is contained in:
parent
eae3d8e6d8
commit
ce6b967f4e
@ -88,7 +88,9 @@ ResultCode SignalEvent(const Handle handle) {
|
||||
// Resume threads waiting for event to signal
|
||||
bool event_caught = false;
|
||||
for (size_t i = 0; i < evt->waiting_threads.size(); ++i) {
|
||||
ResumeThreadFromWait( evt->waiting_threads[i]);
|
||||
Thread* thread = Kernel::g_handle_table.Get<Thread>(evt->waiting_threads[i]);
|
||||
if (thread != nullptr)
|
||||
thread->ResumeFromWait();
|
||||
|
||||
// If any thread is signalled awake by this event, assume the event was "caught" and reset
|
||||
// the event. This will result in the next thread waiting on the event to block. Otherwise,
|
||||
|
@ -45,9 +45,12 @@ void MutexAcquireLock(Mutex* mutex, Handle thread = GetCurrentThread()->GetHandl
|
||||
mutex->lock_thread = thread;
|
||||
}
|
||||
|
||||
bool ReleaseMutexForThread(Mutex* mutex, Handle thread) {
|
||||
MutexAcquireLock(mutex, thread);
|
||||
Kernel::ResumeThreadFromWait(thread);
|
||||
bool ReleaseMutexForThread(Mutex* mutex, Handle thread_handle) {
|
||||
MutexAcquireLock(mutex, thread_handle);
|
||||
|
||||
Thread* thread = Kernel::g_handle_table.Get<Thread>(thread_handle);
|
||||
if (thread != nullptr)
|
||||
thread->ResumeFromWait();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -84,7 +84,9 @@ ResultCode ReleaseSemaphore(s32* count, Handle handle, s32 release_count) {
|
||||
// Notify some of the threads that the semaphore has been released
|
||||
// stop once the semaphore is full again or there are no more waiting threads
|
||||
while (!semaphore->waiting_threads.empty() && semaphore->IsAvailable()) {
|
||||
Kernel::ResumeThreadFromWait(semaphore->waiting_threads.front());
|
||||
Thread* thread = Kernel::g_handle_table.Get<Thread>(semaphore->waiting_threads.front());
|
||||
if (thread != nullptr)
|
||||
thread->ResumeFromWait();
|
||||
semaphore->waiting_threads.pop();
|
||||
--semaphore->available_count;
|
||||
}
|
||||
|
@ -131,7 +131,7 @@ void Thread::Stop(const char* reason) {
|
||||
Thread* waiting_thread = g_handle_table.Get<Thread>(waiting_handle);
|
||||
|
||||
if (CheckWaitType(waiting_thread, WAITTYPE_THREADEND, GetHandle()))
|
||||
ResumeThreadFromWait(waiting_handle);
|
||||
waiting_thread->ResumeFromWait();
|
||||
}
|
||||
waiting_threads.clear();
|
||||
|
||||
@ -177,8 +177,11 @@ Handle ArbitrateHighestPriorityThread(u32 arbiter, u32 address) {
|
||||
}
|
||||
}
|
||||
// If a thread was arbitrated, resume it
|
||||
if (0 != highest_priority_thread)
|
||||
ResumeThreadFromWait(highest_priority_thread);
|
||||
if (0 != highest_priority_thread) {
|
||||
Thread* thread = Kernel::g_handle_table.Get<Thread>(highest_priority_thread);
|
||||
if (thread != nullptr)
|
||||
thread->ResumeFromWait();
|
||||
}
|
||||
|
||||
return highest_priority_thread;
|
||||
}
|
||||
@ -191,7 +194,7 @@ void ArbitrateAllThreads(u32 arbiter, u32 address) {
|
||||
Thread* thread = g_handle_table.Get<Thread>(handle);
|
||||
|
||||
if (CheckWaitType(thread, WAITTYPE_ARB, arbiter, address))
|
||||
ResumeThreadFromWait(handle);
|
||||
thread->ResumeFromWait();
|
||||
}
|
||||
}
|
||||
|
||||
@ -257,15 +260,12 @@ void WaitCurrentThread(WaitType wait_type, Handle wait_handle, VAddr wait_addres
|
||||
}
|
||||
|
||||
/// Resumes a thread from waiting by marking it as "ready"
|
||||
void ResumeThreadFromWait(Handle handle) {
|
||||
Thread* thread = Kernel::g_handle_table.Get<Thread>(handle);
|
||||
if (thread) {
|
||||
thread->status &= ~THREADSTATUS_WAIT;
|
||||
thread->wait_handle = 0;
|
||||
thread->wait_type = WAITTYPE_NONE;
|
||||
if (!(thread->status & (THREADSTATUS_WAITSUSPEND | THREADSTATUS_DORMANT | THREADSTATUS_DEAD))) {
|
||||
ChangeReadyState(thread, true);
|
||||
}
|
||||
void Thread::ResumeFromWait() {
|
||||
status &= ~THREADSTATUS_WAIT;
|
||||
wait_handle = 0;
|
||||
wait_type = WAITTYPE_NONE;
|
||||
if (!(status & (THREADSTATUS_WAITSUSPEND | THREADSTATUS_DORMANT | THREADSTATUS_DEAD))) {
|
||||
ChangeReadyState(this, true);
|
||||
}
|
||||
}
|
||||
|
||||
@ -416,7 +416,7 @@ void Reschedule() {
|
||||
// will immediately be placed back in the queue for execution.
|
||||
|
||||
if (CheckWaitType(prev, WAITTYPE_SLEEP))
|
||||
ResumeThreadFromWait(prev->GetHandle());
|
||||
prev->ResumeFromWait();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -76,6 +76,8 @@ public:
|
||||
u32 GetThreadId() const { return thread_id; }
|
||||
|
||||
void Stop(const char* reason);
|
||||
/// Resumes a thread from waiting by marking it as "ready".
|
||||
void ResumeFromWait();
|
||||
|
||||
Core::ThreadContext context;
|
||||
|
||||
@ -109,9 +111,6 @@ Thread* SetupMainThread(s32 priority, int stack_size = Kernel::DEFAULT_STACK_SIZ
|
||||
/// Reschedules to the next available thread (call after current thread is suspended)
|
||||
void Reschedule();
|
||||
|
||||
/// Resumes a thread from waiting by marking it as "ready"
|
||||
void ResumeThreadFromWait(Handle handle);
|
||||
|
||||
/// Arbitrate the highest priority thread that is waiting
|
||||
Handle ArbitrateHighestPriorityThread(u32 arbiter, u32 address);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user