Simplify shared timer reference counting in wxEventLoop for wxQT

This commit is contained in:
Graham Dawes 2019-01-25 16:44:23 +00:00
parent 9cd566789d
commit e40323d312

View File

@ -81,7 +81,7 @@ void wxQtIdleTimer::idle()
namespace namespace
{ {
wxQtIdleTimer *gs_idleTimer = NULL; wxObjectDataPtr<wxQtIdleTimer> gs_idleTimer;
} }
void wxQtIdleTimer::ScheduleIdleCheck() void wxQtIdleTimer::ScheduleIdleCheck()
@ -95,13 +95,7 @@ wxQtEventLoopBase::wxQtEventLoopBase()
{ {
// Create an idle timer to run each time there are no events (timeout = 0) // Create an idle timer to run each time there are no events (timeout = 0)
if ( !gs_idleTimer ) if ( !gs_idleTimer )
{ gs_idleTimer.reset(new wxQtIdleTimer());
gs_idleTimer = new wxQtIdleTimer();
}
else
{
gs_idleTimer->IncRef();
}
m_qtIdleTimer = gs_idleTimer; m_qtIdleTimer = gs_idleTimer;
m_qtEventLoop = new QEventLoop; m_qtEventLoop = new QEventLoop;
@ -109,8 +103,9 @@ wxQtEventLoopBase::wxQtEventLoopBase()
wxQtEventLoopBase::~wxQtEventLoopBase() wxQtEventLoopBase::~wxQtEventLoopBase()
{ {
if ( gs_idleTimer->GetRefCount() <= 1 ) //Clear the shared timer if this is the only external reference to it
gs_idleTimer = NULL; if ( gs_idleTimer->GetRefCount() <= 2 )
gs_idleTimer.reset(NULL);
delete m_qtEventLoop; delete m_qtEventLoop;
} }