mtgs: use SysExecutor to route events back to itself for suspend operations

This commit is contained in:
Gauvain 'GovanifY' Roussel-Tarbouriech 2021-05-16 14:37:03 +02:00 committed by Kojin
parent f020ffabeb
commit d48e4cd138
1 changed files with 38 additions and 2 deletions

View File

@ -70,6 +70,42 @@ SysMtgsThread::SysMtgsThread()
// All other state vars are initialized by OnStart(). // All other state vars are initialized by OnStart().
} }
typedef void (SysMtgsThread::*FnPtr_MtgsThreadMethod)();
class SysExecEvent_InvokeMtgsThreadMethod : public SysExecEvent
{
protected:
FnPtr_MtgsThreadMethod m_method;
bool m_IsCritical;
public:
wxString GetEventName() const { return L"MtgsThreadMethod"; }
virtual ~SysExecEvent_InvokeMtgsThreadMethod() = default;
SysExecEvent_InvokeMtgsThreadMethod* Clone() const { return new SysExecEvent_InvokeMtgsThreadMethod(*this); }
bool AllowCancelOnExit() const { return false; }
bool IsCriticalEvent() const { return m_IsCritical; }
SysExecEvent_InvokeMtgsThreadMethod(FnPtr_MtgsThreadMethod method, bool critical = false)
{
m_method = method;
m_IsCritical = critical;
}
SysExecEvent_InvokeMtgsThreadMethod& Critical()
{
m_IsCritical = true;
return *this;
}
protected:
void InvokeEvent()
{
if (m_method)
(mtgsThread.*m_method)();
}
};
void SysMtgsThread::OnStart() void SysMtgsThread::OnStart()
{ {
m_Opened = false; m_Opened = false;
@ -563,7 +599,7 @@ void SysMtgsThread::CloseGS()
void SysMtgsThread::OnSuspendInThread() void SysMtgsThread::OnSuspendInThread()
{ {
CloseGS(); GetSysExecutorThread().PostEvent(new SysExecEvent_InvokeMtgsThreadMethod(&SysMtgsThread::CloseGS));
_parent::OnSuspendInThread(); _parent::OnSuspendInThread();
} }
@ -577,7 +613,7 @@ void SysMtgsThread::OnResumeInThread(bool isSuspended)
void SysMtgsThread::OnCleanupInThread() void SysMtgsThread::OnCleanupInThread()
{ {
CloseGS(); GetSysExecutorThread().PostEvent(new SysExecEvent_InvokeMtgsThreadMethod(&SysMtgsThread::CloseGS));
_parent::OnCleanupInThread(); _parent::OnCleanupInThread();
} }