Protect the log to window queue with a mutex.

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@2705 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
hrydgard 2009-03-20 22:51:59 +00:00
parent 46c0e5b659
commit 226aac6cac
2 changed files with 12 additions and 0 deletions

View File

@ -46,6 +46,7 @@ CLogWindow::CLogWindow(wxWindow* parent)
: wxDialog(parent, wxID_ANY, wxT("Log/Console"),
wxPoint(100, 700), wxSize(800, 270),
wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
, m_logSection(1)
{
m_logManager = LogManager::GetInstance();
for (int i = 0; i < LogTypes::NUMBER_OF_LOGS; ++i)
@ -210,9 +211,11 @@ void CLogWindow::OnClear(wxCommandEvent& WXUNUSED (event))
{
m_log->Clear();
m_logSection.Enter();
//msgQueue.Clear()
for (unsigned int i = 0; i < msgQueue.size(); i++)
msgQueue.pop();
m_logSection.Leave();
m_console->ClearScreen();
NOTICE_LOG(CONSOLE, "Console cleared");
@ -376,6 +379,8 @@ void CLogWindow::UpdateLog()
m_logTimer->Stop();
wxString collected_text;
// rough estimate.
m_logSection.Enter();
collected_text.reserve(100 * msgQueue.size());
int msgQueueSize = (int)msgQueue.size();
for (int i = 0; i < msgQueueSize; i++)
@ -414,6 +419,8 @@ void CLogWindow::UpdateLog()
collected_text.Append(msgQueue.front().second);
msgQueue.pop();
}
m_logSection.Leave();
if (collected_text.size()) {
m_log->AppendText(collected_text);
}
@ -422,7 +429,9 @@ void CLogWindow::UpdateLog()
void CLogWindow::Log(LogTypes::LOG_LEVELS level, const char *text)
{
m_logSection.Enter();
if (msgQueue.size() >= 100)
msgQueue.pop();
msgQueue.push(std::pair<u8, wxString>((u8)level, wxString::FromAscii(text)));
m_logSection.Leave();
}

View File

@ -20,6 +20,7 @@
#include "Main.h" // for wxGetApp
#include "LogManager.h"
#include "IniFile.h"
#include "Thread.h"
#include <queue>
enum
@ -65,6 +66,8 @@ private:
LogManager *m_logManager;
std::queue<std::pair<u8, wxString> > msgQueue;
Common::CriticalSection m_logSection;
DECLARE_EVENT_TABLE()
void CreateGUIControls();