mirror of
https://port.numenaute.org/aleajactaest/khanat-opennel-code.git
synced 2024-12-30 04:40:53 +00:00
Fixed: Potential bug in CWinThread, someone using a mutex on the stack again
--HG-- branch : sound_dev
This commit is contained in:
parent
1d0052d228
commit
268f2e247f
1 changed files with 16 additions and 5 deletions
|
@ -73,6 +73,19 @@ CWinThread::CWinThread (IRunnable *runnable, uint32 stackSize)
|
||||||
_MainThread = false;
|
_MainThread = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
class CWinCriticalSection
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
CRITICAL_SECTION cs;
|
||||||
|
public:
|
||||||
|
CWinCriticalSection() { InitializeCriticalSection(&cs); }
|
||||||
|
~CWinCriticalSection() { DeleteCriticalSection(&cs); }
|
||||||
|
inline void enter() { EnterCriticalSection(&cs); }
|
||||||
|
inline void leave() { LeaveCriticalSection(&cs); }
|
||||||
|
};
|
||||||
|
}/* anonymous namespace */
|
||||||
|
|
||||||
CWinThread::CWinThread (void* threadHandle, uint32 threadId)
|
CWinThread::CWinThread (void* threadHandle, uint32 threadId)
|
||||||
{
|
{
|
||||||
// Main thread
|
// Main thread
|
||||||
|
@ -99,14 +112,12 @@ CWinThread::CWinThread (void* threadHandle, uint32 threadId)
|
||||||
nlassert(0); // WARNING: following code has not tested! don't know if it work fo real ...
|
nlassert(0); // WARNING: following code has not tested! don't know if it work fo real ...
|
||||||
// This is just a suggestion of a possible solution, should this situation one day occur ...
|
// This is just a suggestion of a possible solution, should this situation one day occur ...
|
||||||
// Ensure that this thread don't get deleted, or we could suspend the main thread
|
// Ensure that this thread don't get deleted, or we could suspend the main thread
|
||||||
CRITICAL_SECTION cs;
|
static CWinCriticalSection cs;
|
||||||
InitializeCriticalSection(&cs);
|
cs.enter();
|
||||||
EnterCriticalSection(&cs);
|
|
||||||
// the 2 following statement must be executed atomicaly among the threads of the current process !
|
// the 2 following statement must be executed atomicaly among the threads of the current process !
|
||||||
SuspendThread(threadHandle);
|
SuspendThread(threadHandle);
|
||||||
_SuspendCount = ResumeThread(threadHandle);
|
_SuspendCount = ResumeThread(threadHandle);
|
||||||
LeaveCriticalSection(&cs);
|
cs.leave();
|
||||||
DeleteCriticalSection(&cs);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue