Added wxCriticalSection::TryEnter() method.
This is similar to wxMutex::TryLock() and useful for the same reasons. Closes #13638. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@69883 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -40,6 +40,8 @@
|
||||
|
||||
#include "wx/except.h"
|
||||
|
||||
#include "wx/dynlib.h"
|
||||
|
||||
// must have this symbol defined to get _beginthread/_endthread declarations
|
||||
#ifndef _MT
|
||||
#define _MT
|
||||
@@ -163,6 +165,25 @@ void wxCriticalSection::Enter()
|
||||
::EnterCriticalSection((CRITICAL_SECTION *)m_buffer);
|
||||
}
|
||||
|
||||
bool wxCriticalSection::TryEnter()
|
||||
{
|
||||
#if wxUSE_DYNLIB_CLASS
|
||||
typedef BOOL
|
||||
(WINAPI *TryEnterCriticalSection_t)(LPCRITICAL_SECTION lpCriticalSection);
|
||||
|
||||
static TryEnterCriticalSection_t
|
||||
pfnTryEnterCriticalSection = (TryEnterCriticalSection_t)
|
||||
wxDynamicLibrary(wxT("kernel32.dll")).
|
||||
GetSymbol(wxT("TryEnterCriticalSection"));
|
||||
|
||||
return pfnTryEnterCriticalSection
|
||||
? (*pfnTryEnterCriticalSection)((CRITICAL_SECTION *)m_buffer) != 0
|
||||
: false;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
void wxCriticalSection::Leave()
|
||||
{
|
||||
::LeaveCriticalSection((CRITICAL_SECTION *)m_buffer);
|
||||
|
Reference in New Issue
Block a user