From 226aac6cac0c41cc353f7fa37772de830306f512 Mon Sep 17 00:00:00 2001 From: hrydgard Date: Fri, 20 Mar 2009 22:51:59 +0000 Subject: [PATCH] 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 --- Source/Core/DolphinWX/Src/LogWindow.cpp | 9 +++++++++ Source/Core/DolphinWX/Src/LogWindow.h | 3 +++ 2 files changed, 12 insertions(+) diff --git a/Source/Core/DolphinWX/Src/LogWindow.cpp b/Source/Core/DolphinWX/Src/LogWindow.cpp index 83888d74e5..e38d9ce172 100644 --- a/Source/Core/DolphinWX/Src/LogWindow.cpp +++ b/Source/Core/DolphinWX/Src/LogWindow.cpp @@ -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)level, wxString::FromAscii(text))); + m_logSection.Leave(); } diff --git a/Source/Core/DolphinWX/Src/LogWindow.h b/Source/Core/DolphinWX/Src/LogWindow.h index 83b6111370..45dfa782a5 100644 --- a/Source/Core/DolphinWX/Src/LogWindow.h +++ b/Source/Core/DolphinWX/Src/LogWindow.h @@ -20,6 +20,7 @@ #include "Main.h" // for wxGetApp #include "LogManager.h" #include "IniFile.h" +#include "Thread.h" #include enum @@ -65,6 +66,8 @@ private: LogManager *m_logManager; std::queue > msgQueue; + Common::CriticalSection m_logSection; + DECLARE_EVENT_TABLE() void CreateGUIControls();