|
|
@ -106,28 +106,38 @@ void AddTimeData(unsigned int ip, int64 nTime); |
|
|
|
// Could use wxCriticalSection for portability, but it doesn't support TryEnterCriticalSection
|
|
|
|
// Could use wxCriticalSection for portability, but it doesn't support TryEnterCriticalSection
|
|
|
|
class CCriticalSection |
|
|
|
class CCriticalSection |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
#ifdef __WXMSW__ |
|
|
|
protected: |
|
|
|
protected: |
|
|
|
CRITICAL_SECTION cs; |
|
|
|
CRITICAL_SECTION cs; |
|
|
|
public: |
|
|
|
public: |
|
|
|
char* pszFile; |
|
|
|
|
|
|
|
int nLine; |
|
|
|
|
|
|
|
explicit CCriticalSection() { InitializeCriticalSection(&cs); } |
|
|
|
explicit CCriticalSection() { InitializeCriticalSection(&cs); } |
|
|
|
~CCriticalSection() { DeleteCriticalSection(&cs); } |
|
|
|
~CCriticalSection() { DeleteCriticalSection(&cs); } |
|
|
|
void Enter() { EnterCriticalSection(&cs); } |
|
|
|
void Enter() { EnterCriticalSection(&cs); } |
|
|
|
void Leave() { LeaveCriticalSection(&cs); } |
|
|
|
void Leave() { LeaveCriticalSection(&cs); } |
|
|
|
bool TryEnter() { return TryEnterCriticalSection(&cs); } |
|
|
|
bool TryEnter() { return TryEnterCriticalSection(&cs); } |
|
|
|
CRITICAL_SECTION* operator&() { return &cs; } |
|
|
|
#else |
|
|
|
|
|
|
|
protected: |
|
|
|
|
|
|
|
wxMutex mutex; |
|
|
|
|
|
|
|
public: |
|
|
|
|
|
|
|
explicit CCriticalSection() { } |
|
|
|
|
|
|
|
~CCriticalSection() { } |
|
|
|
|
|
|
|
void Enter() { mutex.Lock(); } |
|
|
|
|
|
|
|
void Leave() { mutex.Unlock(); } |
|
|
|
|
|
|
|
bool TryEnter() { return mutex.TryLock() == wxMUTEX_NO_ERROR; } |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
public: |
|
|
|
|
|
|
|
char* pszFile; |
|
|
|
|
|
|
|
int nLine; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
// Automatically leave critical section when leaving block, needed for exception safety
|
|
|
|
// Automatically leave critical section when leaving block, needed for exception safety
|
|
|
|
class CCriticalBlock |
|
|
|
class CCriticalBlock |
|
|
|
{ |
|
|
|
{ |
|
|
|
protected: |
|
|
|
protected: |
|
|
|
CRITICAL_SECTION* pcs; |
|
|
|
CCriticalSection* pcs; |
|
|
|
public: |
|
|
|
public: |
|
|
|
CCriticalBlock(CRITICAL_SECTION& csIn) { pcs = &csIn; EnterCriticalSection(pcs); } |
|
|
|
CCriticalBlock(CCriticalSection& csIn) { pcs = &csIn; pcs->Enter(); } |
|
|
|
CCriticalBlock(CCriticalSection& csIn) { pcs = &csIn; EnterCriticalSection(pcs); } |
|
|
|
~CCriticalBlock() { pcs->Leave(); } |
|
|
|
~CCriticalBlock() { LeaveCriticalSection(pcs); } |
|
|
|
|
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
// WARNING: This will catch continue and break!
|
|
|
|
// WARNING: This will catch continue and break!
|
|
|
@ -141,11 +151,10 @@ public: |
|
|
|
class CTryCriticalBlock |
|
|
|
class CTryCriticalBlock |
|
|
|
{ |
|
|
|
{ |
|
|
|
protected: |
|
|
|
protected: |
|
|
|
CRITICAL_SECTION* pcs; |
|
|
|
CCriticalSection* pcs; |
|
|
|
public: |
|
|
|
public: |
|
|
|
CTryCriticalBlock(CRITICAL_SECTION& csIn) { pcs = (TryEnterCriticalSection(&csIn) ? &csIn : NULL); } |
|
|
|
CTryCriticalBlock(CCriticalSection& csIn) { pcs = (csIn.TryEnter() ? &csIn : NULL); } |
|
|
|
CTryCriticalBlock(CCriticalSection& csIn) { pcs = (TryEnterCriticalSection(&csIn) ? &csIn : NULL); } |
|
|
|
~CTryCriticalBlock() { if (pcs) pcs->Leave(); } |
|
|
|
~CTryCriticalBlock() { if (pcs) LeaveCriticalSection(pcs); } |
|
|
|
|
|
|
|
bool Entered() { return pcs != NULL; } |
|
|
|
bool Entered() { return pcs != NULL; } |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|