CtrlCore: TryEnterGuiMutex

git-svn-id: svn://ultimatepp.org/upp/trunk@11908 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2018-04-23 16:02:09 +00:00
parent 2347bfd911
commit 3dbc3b4e31
2 changed files with 11 additions and 0 deletions

View file

@ -42,6 +42,7 @@ INITIALIZE(CtrlCore)
#ifdef _MULTITHREADED
void EnterGuiMutex();
bool TryEnterGuiMutex();
void LeaveGuiMutex();
int LeaveGuiMutexAll();
@ -51,6 +52,7 @@ bool ThreadHasGuiLock();
#else
inline void EnterGuiMutex() {}
inline void LeaveGuiMutex() {}
inline bool TryEnterGuiMutex() { return true; }
inline int LeaveGuiMutexAll() { return 0; }
inline void EnterGuiMutex(int) {}

View file

@ -29,6 +29,15 @@ void EnterGuiMutex(int n)
LLOG("EnterGuiMutex " << sGLockLevel << ' ' << IsMainThread());
}
bool TryEnterGuiMutex()
{
if(sGLockLevel == 0 && sGLock.TryEnter()) {
sGLockLevel++;
return true;
}
return false;
}
void LeaveGuiMutex()
{
LLOG(">LeaveGuiMutex " << sGLockLevel << ' ' << IsMainThread());