fixed CriticalSectionLocker (thanks to Nukem)

This commit is contained in:
Mr. eXoDia 2014-12-22 23:22:59 +01:00
parent 29f8973700
commit f04f96e83d
2 changed files with 7 additions and 1 deletions

View File

@ -30,20 +30,25 @@ CriticalSectionLocker::CriticalSectionLocker(CriticalSectionLock lock)
{ {
CriticalSectionInitializeLocks(); //initialize critical sections CriticalSectionInitializeLocks(); //initialize critical sections
gLock = lock; gLock = lock;
EnterCriticalSection(&locks[gLock]); EnterCriticalSection(&locks[gLock]);
Locked = true;
} }
CriticalSectionLocker::~CriticalSectionLocker() CriticalSectionLocker::~CriticalSectionLocker()
{ {
LeaveCriticalSection(&locks[gLock]); if(Locked)
LeaveCriticalSection(&locks[gLock]);
} }
void CriticalSectionLocker::unlock() void CriticalSectionLocker::unlock()
{ {
Locked = false;
LeaveCriticalSection(&locks[gLock]); LeaveCriticalSection(&locks[gLock]);
} }
void CriticalSectionLocker::relock() void CriticalSectionLocker::relock()
{ {
EnterCriticalSection(&locks[gLock]); EnterCriticalSection(&locks[gLock]);
Locked = true;
} }

View File

@ -25,6 +25,7 @@ public:
private: private:
CriticalSectionLock gLock; CriticalSectionLock gLock;
bool Locked;
}; };
#endif //_GLOBAL_ENGINE_THREADING_H #endif //_GLOBAL_ENGINE_THREADING_H