Thread: Reduce use of Handles and move some funcs to inside the class.

This commit is contained in:
Yuri Kunde Schlesner 2014-12-22 11:07:22 -02:00
parent ba72208cd4
commit 9bf8462b96
11 changed files with 222 additions and 302 deletions

View file

@ -40,14 +40,21 @@ static MutexMap g_mutex_held_locks;
* @param mutex Mutex that is to be 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()));
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) {
LOG_ERROR(Kernel, "Called with invalid handle: %08X", thread_handle);
return false;
}
thread->ResumeFromWait();
return true;
}
@ -168,8 +175,8 @@ Handle CreateMutex(bool initial_locked, const std::string& name) {
ResultVal<bool> Mutex::WaitSynchronization() {
bool wait = locked;
if (locked) {
waiting_threads.push_back(GetCurrentThreadHandle());
Kernel::WaitCurrentThread(WAITTYPE_MUTEX, GetHandle());
waiting_threads.push_back(GetCurrentThread()->GetHandle());
Kernel::WaitCurrentThread(WAITTYPE_MUTEX, this);
} else {
// Lock the mutex when the first thread accesses it
locked = true;