Only process GUI events for the menu lock
Some weird crashes started happening after becfa86
This commit is contained in:
parent
52b9866fc8
commit
974b93432e
|
|
@ -213,7 +213,7 @@ bool pluginload(const char* pluginName, bool loadall)
|
|||
|
||||
//add plugin menus
|
||||
{
|
||||
SectionLocker<LockPluginMenuList, false> menuLock; //exclusive lock
|
||||
SectionLocker<LockPluginMenuList, false, true> menuLock; //exclusive lock
|
||||
|
||||
auto addPluginMenu = [](GUIMENUTYPE type)
|
||||
{
|
||||
|
|
@ -624,7 +624,7 @@ int pluginmenuadd(int hMenu, const char* title)
|
|||
{
|
||||
if(!title || !strlen(title))
|
||||
return -1;
|
||||
EXCLUSIVE_ACQUIRE(LockPluginMenuList);
|
||||
EXCLUSIVE_ACQUIRE_GUI(LockPluginMenuList);
|
||||
int nFound = -1;
|
||||
for(unsigned int i = 0; i < pluginMenuList.size(); i++)
|
||||
{
|
||||
|
|
@ -656,7 +656,7 @@ bool pluginmenuaddentry(int hMenu, int hEntry, const char* title)
|
|||
{
|
||||
if(!title || !strlen(title) || hEntry == -1)
|
||||
return false;
|
||||
EXCLUSIVE_ACQUIRE(LockPluginMenuList);
|
||||
EXCLUSIVE_ACQUIRE_GUI(LockPluginMenuList);
|
||||
int pluginHandle = -1;
|
||||
//find plugin handle
|
||||
for(const auto & currentMenu : pluginMenuList)
|
||||
|
|
@ -692,7 +692,7 @@ bool pluginmenuaddentry(int hMenu, int hEntry, const char* title)
|
|||
*/
|
||||
bool pluginmenuaddseparator(int hMenu)
|
||||
{
|
||||
SHARED_ACQUIRE(LockPluginMenuList);
|
||||
SHARED_ACQUIRE_GUI(LockPluginMenuList);
|
||||
for(const auto & currentMenu : pluginMenuList)
|
||||
{
|
||||
if(currentMenu.hEntryMenu == hMenu)
|
||||
|
|
@ -736,7 +736,7 @@ static void pluginmenuclear_helper(int hMenu)
|
|||
*/
|
||||
bool pluginmenuclear(int hMenu, bool erase)
|
||||
{
|
||||
EXCLUSIVE_ACQUIRE(LockPluginMenuList);
|
||||
EXCLUSIVE_ACQUIRE_GUI(LockPluginMenuList);
|
||||
pluginmenuclear_helper(hMenu);
|
||||
for(auto it = pluginMenuList.begin(); it != pluginMenuList.end(); ++it)
|
||||
{
|
||||
|
|
@ -765,7 +765,7 @@ void pluginmenucall(int hEntry)
|
|||
if(hEntry == -1)
|
||||
return;
|
||||
|
||||
SectionLocker<LockPluginMenuList, true> menuLock; //shared lock
|
||||
SectionLocker<LockPluginMenuList, true, true> menuLock; //shared lock
|
||||
auto i = pluginMenuEntryList.begin();
|
||||
while(i != pluginMenuEntryList.end())
|
||||
{
|
||||
|
|
@ -829,7 +829,7 @@ bool pluginwineventglobal(MSG* message)
|
|||
*/
|
||||
void pluginmenuseticon(int hMenu, const ICONDATA* icon)
|
||||
{
|
||||
SHARED_ACQUIRE(LockPluginMenuList);
|
||||
SHARED_ACQUIRE_GUI(LockPluginMenuList);
|
||||
for(const auto & currentMenu : pluginMenuList)
|
||||
{
|
||||
if(currentMenu.hEntryMenu == hMenu)
|
||||
|
|
@ -850,7 +850,7 @@ void pluginmenuentryseticon(int pluginHandle, int hEntry, const ICONDATA* icon)
|
|||
{
|
||||
if(hEntry == -1)
|
||||
return;
|
||||
SHARED_ACQUIRE(LockPluginMenuList);
|
||||
SHARED_ACQUIRE_GUI(LockPluginMenuList);
|
||||
for(const auto & currentMenu : pluginMenuEntryList)
|
||||
{
|
||||
if(currentMenu.pluginHandle == pluginHandle && currentMenu.hEntryPlugin == hEntry)
|
||||
|
|
@ -865,7 +865,7 @@ void pluginmenuentrysetchecked(int pluginHandle, int hEntry, bool checked)
|
|||
{
|
||||
if(hEntry == -1)
|
||||
return;
|
||||
SHARED_ACQUIRE(LockPluginMenuList);
|
||||
SHARED_ACQUIRE_GUI(LockPluginMenuList);
|
||||
for(const auto & currentMenu : pluginMenuEntryList)
|
||||
{
|
||||
if(currentMenu.pluginHandle == pluginHandle && currentMenu.hEntryPlugin == hEntry)
|
||||
|
|
@ -878,7 +878,7 @@ void pluginmenuentrysetchecked(int pluginHandle, int hEntry, bool checked)
|
|||
|
||||
void pluginmenusetvisible(int pluginHandle, int hMenu, bool visible)
|
||||
{
|
||||
SHARED_ACQUIRE(LockPluginMenuList);
|
||||
SHARED_ACQUIRE_GUI(LockPluginMenuList);
|
||||
for(const auto & currentMenu : pluginMenuList)
|
||||
{
|
||||
if(currentMenu.hEntryMenu == hMenu)
|
||||
|
|
@ -893,7 +893,7 @@ void pluginmenuentrysetvisible(int pluginHandle, int hEntry, bool visible)
|
|||
{
|
||||
if(hEntry == -1)
|
||||
return;
|
||||
SHARED_ACQUIRE(LockPluginMenuList);
|
||||
SHARED_ACQUIRE_GUI(LockPluginMenuList);
|
||||
for(const auto & currentMenu : pluginMenuEntryList)
|
||||
{
|
||||
if(currentMenu.pluginHandle == pluginHandle && currentMenu.hEntryPlugin == hEntry)
|
||||
|
|
@ -908,7 +908,7 @@ void pluginmenusetname(int pluginHandle, int hMenu, const char* name)
|
|||
{
|
||||
if(!name)
|
||||
return;
|
||||
SHARED_ACQUIRE(LockPluginMenuList);
|
||||
SHARED_ACQUIRE_GUI(LockPluginMenuList);
|
||||
for(const auto & currentMenu : pluginMenuList)
|
||||
{
|
||||
if(currentMenu.hEntryMenu == hMenu)
|
||||
|
|
@ -923,7 +923,7 @@ void pluginmenuentrysetname(int pluginHandle, int hEntry, const char* name)
|
|||
{
|
||||
if(hEntry == -1 || !name)
|
||||
return;
|
||||
SHARED_ACQUIRE(LockPluginMenuList);
|
||||
SHARED_ACQUIRE_GUI(LockPluginMenuList);
|
||||
for(const auto & currentMenu : pluginMenuEntryList)
|
||||
{
|
||||
if(currentMenu.pluginHandle == pluginHandle && currentMenu.hEntryPlugin == hEntry)
|
||||
|
|
@ -938,7 +938,7 @@ void pluginmenuentrysethotkey(int pluginHandle, int hEntry, const char* hotkey)
|
|||
{
|
||||
if(hEntry == -1 || !hotkey)
|
||||
return;
|
||||
SHARED_ACQUIRE(LockPluginMenuList);
|
||||
SHARED_ACQUIRE_GUI(LockPluginMenuList);
|
||||
for(const auto & currentMenu : pluginMenuEntryList)
|
||||
{
|
||||
if(currentMenu.pluginHandle == pluginHandle && currentMenu.hEntryPlugin == hEntry)
|
||||
|
|
@ -962,7 +962,7 @@ void pluginmenuentrysethotkey(int pluginHandle, int hEntry, const char* hotkey)
|
|||
|
||||
bool pluginmenuremove(int hMenu)
|
||||
{
|
||||
EXCLUSIVE_ACQUIRE(LockPluginMenuList);
|
||||
EXCLUSIVE_ACQUIRE_GUI(LockPluginMenuList);
|
||||
for(const auto & currentMenu : pluginMenuList)
|
||||
if(currentMenu.hEntryMenu == hMenu && currentMenu.hParentMenu < 256)
|
||||
return false;
|
||||
|
|
@ -971,7 +971,7 @@ bool pluginmenuremove(int hMenu)
|
|||
|
||||
bool pluginmenuentryremove(int pluginHandle, int hEntry)
|
||||
{
|
||||
EXCLUSIVE_ACQUIRE(LockPluginMenuList);
|
||||
EXCLUSIVE_ACQUIRE_GUI(LockPluginMenuList);
|
||||
for(auto it = pluginMenuEntryList.begin(); it != pluginMenuEntryList.end(); ++it)
|
||||
{
|
||||
const auto & currentEntry = *it;
|
||||
|
|
|
|||
|
|
@ -25,13 +25,15 @@ void waitdeinitialize();
|
|||
// Win Vista and newer: (Faster) SRW locks used
|
||||
// Win 2003 and older: (Slower) Critical sections used
|
||||
//
|
||||
#define EXCLUSIVE_ACQUIRE(Index) SectionLocker<Index, false> __ThreadLock
|
||||
#define EXCLUSIVE_REACQUIRE() __ThreadLock.Lock()
|
||||
#define EXCLUSIVE_RELEASE() __ThreadLock.Unlock()
|
||||
#define EXCLUSIVE_ACQUIRE(Index) SectionLocker<Index, false> __ThreadLock
|
||||
#define EXCLUSIVE_ACQUIRE_GUI(Index) SectionLocker<Index, false, true> __ThreadLock
|
||||
#define EXCLUSIVE_REACQUIRE() __ThreadLock.Lock()
|
||||
#define EXCLUSIVE_RELEASE() __ThreadLock.Unlock()
|
||||
|
||||
#define SHARED_ACQUIRE(Index) SectionLocker<Index, true> __SThreadLock
|
||||
#define SHARED_REACQUIRE() __SThreadLock.Lock()
|
||||
#define SHARED_RELEASE() __SThreadLock.Unlock()
|
||||
#define SHARED_ACQUIRE(Index) SectionLocker<Index, true> __SThreadLock
|
||||
#define SHARED_ACQUIRE_GUI(Index) SectionLocker<Index, true, true> __SThreadLock
|
||||
#define SHARED_REACQUIRE() __SThreadLock.Lock()
|
||||
#define SHARED_RELEASE() __SThreadLock.Unlock()
|
||||
|
||||
enum SectionLock
|
||||
{
|
||||
|
|
@ -80,7 +82,7 @@ enum SectionLock
|
|||
|
||||
class SectionLockerGlobal
|
||||
{
|
||||
template<SectionLock LockIndex, bool Shared>
|
||||
template<SectionLock LockIndex, bool Shared, bool ProcessGuiEvents>
|
||||
friend class SectionLocker;
|
||||
|
||||
public:
|
||||
|
|
@ -88,7 +90,8 @@ public:
|
|||
static void Deinitialize();
|
||||
|
||||
private:
|
||||
static inline void AcquireLock(SectionLock LockIndex, bool Shared)
|
||||
template<SectionLock LockIndex, bool Shared, bool ProcessGuiEvents>
|
||||
static void AcquireLock()
|
||||
{
|
||||
auto threadId = GetCurrentThreadId();
|
||||
if(m_SRWLocks)
|
||||
|
|
@ -100,7 +103,7 @@ private:
|
|||
if(m_owner[LockIndex].thread == threadId)
|
||||
return;
|
||||
|
||||
if(threadId == m_guiMainThreadId)
|
||||
if(ProcessGuiEvents && threadId == m_guiMainThreadId)
|
||||
{
|
||||
while(!m_TryAcquireSRWLockShared(srwLock))
|
||||
GuiProcessEvents();
|
||||
|
|
@ -149,7 +152,8 @@ private:
|
|||
}
|
||||
}
|
||||
|
||||
static inline void ReleaseLock(SectionLock LockIndex, bool Shared)
|
||||
template<SectionLock LockIndex, bool Shared>
|
||||
static void ReleaseLock()
|
||||
{
|
||||
if(m_SRWLocks)
|
||||
{
|
||||
|
|
@ -172,7 +176,9 @@ private:
|
|||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LeaveCriticalSection(&m_crLocks[LockIndex]);
|
||||
}
|
||||
}
|
||||
|
||||
typedef void (WINAPI* SRWLOCKFUNCTION)(PSRWLOCK SWRLock);
|
||||
|
|
@ -194,7 +200,7 @@ private:
|
|||
static DWORD m_guiMainThreadId;
|
||||
};
|
||||
|
||||
template<SectionLock LockIndex, bool Shared>
|
||||
template<SectionLock LockIndex, bool Shared, bool ProcessGuiEvents = false>
|
||||
class SectionLocker
|
||||
{
|
||||
public:
|
||||
|
|
@ -215,7 +221,7 @@ public:
|
|||
|
||||
inline void Lock()
|
||||
{
|
||||
Internal::AcquireLock(LockIndex, Shared);
|
||||
Internal::AcquireLock<LockIndex, Shared, ProcessGuiEvents>();
|
||||
|
||||
// We cannot recursively lock more than 255 times.
|
||||
assert(m_LockCount < 255);
|
||||
|
|
@ -230,7 +236,7 @@ public:
|
|||
|
||||
m_LockCount--;
|
||||
|
||||
Internal::ReleaseLock(LockIndex, Shared);
|
||||
Internal::ReleaseLock<LockIndex, Shared>();
|
||||
}
|
||||
|
||||
protected:
|
||||
|
|
|
|||
Loading…
Reference in New Issue