Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DolphinWX: Clean up some wxTimer code #2152

Merged
merged 1 commit into from
Mar 1, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 2 additions & 4 deletions Source/Core/DolphinWX/Frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -508,15 +508,13 @@ CFrame::CFrame(wxFrame* parent,
// check if game is running
m_bHotkeysInit = InitControllers();

m_poll_hotkey_timer = new wxTimer(this);
m_poll_hotkey_timer.SetOwner(this);
Bind(wxEVT_TIMER, &CFrame::PollHotkeys, this);
m_poll_hotkey_timer->Start(1000 / 60, wxTIMER_CONTINUOUS);
m_poll_hotkey_timer.Start(1000 / 60, wxTIMER_CONTINUOUS);
}
// Destructor
CFrame::~CFrame()
{
m_poll_hotkey_timer->Stop();

if (m_bHotkeysInit)
{
Wiimote::Shutdown();
Expand Down
5 changes: 2 additions & 3 deletions Source/Core/DolphinWX/Frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <wx/mstream.h>
#include <wx/panel.h>
#include <wx/string.h>
#include <wx/timer.h>
#include <wx/toplevel.h>
#include <wx/windowid.h>

Expand Down Expand Up @@ -47,8 +48,6 @@ class wxAuiNotebook;
class wxAuiNotebookEvent;
class wxListEvent;
class wxMenuItem;
class wxTimer;
class wxTimerEvent;
class wxWindow;

class CRenderFrame : public wxFrame
Expand Down Expand Up @@ -198,7 +197,7 @@ class CFrame : public CRenderFrame
EToolbar_Max
};

wxTimer* m_poll_hotkey_timer;
wxTimer m_poll_hotkey_timer;

wxBitmap m_Bitmaps[EToolbar_Max];
wxBitmap m_BitmapsMenu[EToolbar_Max];
Expand Down
19 changes: 7 additions & 12 deletions Source/Core/DolphinWX/LogWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ CLogWindow::CLogWindow(CFrame *parent, wxWindowID id, const wxPoint& pos,
const wxSize& size, long style, const wxString& name)
: wxPanel(parent, id, pos, size, style, name)
, x(0), y(0), winpos(0)
, Parent(parent), m_ignoreLogTimer(false), m_LogAccess(true)
, Parent(parent), m_LogAccess(true)
, m_Log(nullptr), m_cmdline(nullptr), m_FontChoice(nullptr)
{
Bind(wxEVT_CLOSE_WINDOW, &CLogWindow::OnClose, this);
Expand All @@ -55,8 +55,8 @@ CLogWindow::CLogWindow(CFrame *parent, wxWindowID id, const wxPoint& pos,

CreateGUIControls();

m_LogTimer = new wxTimer(this);
m_LogTimer->Start(UPDATETIME);
m_LogTimer.SetOwner(this);
m_LogTimer.Start(UPDATETIME);
}

void CLogWindow::CreateGUIControls()
Expand Down Expand Up @@ -177,8 +177,6 @@ CLogWindow::~CLogWindow()
{
m_LogManager->RemoveListener((LogTypes::LOG_TYPE)i, this);
}
m_LogTimer->Stop();
delete m_LogTimer;
}

void CLogWindow::OnClose(wxCloseEvent& event)
Expand Down Expand Up @@ -287,7 +285,7 @@ void CLogWindow::OnWrapLineCheck(wxCommandEvent& event)

void CLogWindow::OnLogTimer(wxTimerEvent& WXUNUSED(event))
{
if (!m_LogAccess || m_ignoreLogTimer)
if (!m_LogAccess)
return;

UpdateLog();
Expand All @@ -302,13 +300,10 @@ void CLogWindow::OnLogTimer(wxTimerEvent& WXUNUSED(event))

void CLogWindow::UpdateLog()
{
if (!m_LogAccess || !m_Log)
if (!m_LogAccess || !m_Log || msgQueue.empty())
return;

// m_LogTimer->Stop();
// instead of stopping the timer, let's simply ignore its calls during UpdateLog,
// because repeatedly stopping and starting a timer churns memory (and potentially leaks it).
m_ignoreLogTimer = true;
m_LogTimer.Stop();

std::lock_guard<std::mutex> lk(m_LogSection);
while (!msgQueue.empty())
Expand Down Expand Up @@ -351,7 +346,7 @@ void CLogWindow::UpdateLog()
msgQueue.pop();
}

m_ignoreLogTimer = false;
m_LogTimer.Start();
}

void CLogWindow::Log(LogTypes::LOG_LEVELS level, const char *text)
Expand Down
6 changes: 2 additions & 4 deletions Source/Core/DolphinWX/LogWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <wx/gdicmn.h>
#include <wx/panel.h>
#include <wx/string.h>
#include <wx/timer.h>
#include <wx/translation.h>
#include <wx/windowid.h>

Expand All @@ -25,8 +26,6 @@ class wxBoxSizer;
class wxCheckBox;
class wxChoice;
class wxTextCtrl;
class wxTimer;
class wxTimerEvent;

// Uses multiple inheritance - only sane because LogListener is a pure virtual interface.
class CLogWindow : public wxPanel, LogListener
Expand All @@ -50,8 +49,7 @@ class CLogWindow : public wxPanel, LogListener
CFrame* Parent;
wxFont DefaultFont, MonoSpaceFont;
std::vector<wxFont> LogFont;
wxTimer* m_LogTimer;
bool m_ignoreLogTimer;
wxTimer m_LogTimer;
LogManager* m_LogManager;
std::queue<std::pair<u8, wxString> > msgQueue;
bool m_writeFile, m_writeWindow, m_writeDebugger, m_LogAccess;
Expand Down