mirror of
https://github.com/Lime3DS/Lime3DS
synced 2024-12-26 09:02:44 -06:00
Merge pull request #225 from bunnei/fix-release-mutex
Mutex: Changed behavior to always release mutex for all threads.
This commit is contained in:
commit
e3d1ffff4b
1 changed files with 7 additions and 8 deletions
|
@ -88,20 +88,19 @@ bool ReleaseMutexForThread(Mutex* mutex, Handle thread) {
|
||||||
|
|
||||||
bool ReleaseMutex(Mutex* mutex) {
|
bool ReleaseMutex(Mutex* mutex) {
|
||||||
MutexEraseLock(mutex);
|
MutexEraseLock(mutex);
|
||||||
bool woke_threads = false;
|
|
||||||
|
|
||||||
// Find the next waiting thread for the mutex...
|
// Find the next waiting thread for the mutex...
|
||||||
while (!woke_threads && !mutex->waiting_threads.empty()) {
|
while (!mutex->waiting_threads.empty()) {
|
||||||
std::vector<Handle>::iterator iter = mutex->waiting_threads.begin();
|
std::vector<Handle>::iterator iter = mutex->waiting_threads.begin();
|
||||||
woke_threads |= ReleaseMutexForThread(mutex, *iter);
|
ReleaseMutexForThread(mutex, *iter);
|
||||||
mutex->waiting_threads.erase(iter);
|
mutex->waiting_threads.erase(iter);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset mutex lock thread handle, nothing is waiting
|
// Reset mutex lock thread handle, nothing is waiting
|
||||||
if (!woke_threads) {
|
mutex->locked = false;
|
||||||
mutex->locked = false;
|
mutex->lock_thread = -1;
|
||||||
mutex->lock_thread = -1;
|
|
||||||
}
|
return true;
|
||||||
return woke_threads;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue