mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-04-10 06:44:29 +00:00
Move statics into cpp and properly guard buffer from race conditions
This commit is contained in:
parent
e0936b04c0
commit
952999153c
@ -8,6 +8,8 @@
|
|||||||
#include <components/debug/debugging.hpp>
|
#include <components/debug/debugging.hpp>
|
||||||
#include <components/settings/settings.hpp>
|
#include <components/settings/settings.hpp>
|
||||||
|
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
#ifndef BT_NO_PROFILE
|
#ifndef BT_NO_PROFILE
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
@ -103,9 +105,10 @@ namespace MWGui
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<char> DebugWindow::sLogCircularBuffer;
|
static std::vector<char> sLogCircularBuffer;
|
||||||
int64_t DebugWindow::sLogStartIndex = 0;
|
static std::mutex sBufferMutex;
|
||||||
int64_t DebugWindow::sLogEndIndex = 0;
|
static int64_t sLogStartIndex;
|
||||||
|
static int64_t sLogEndIndex;
|
||||||
|
|
||||||
void DebugWindow::startLogRecording()
|
void DebugWindow::startLogRecording()
|
||||||
{
|
{
|
||||||
@ -125,6 +128,7 @@ namespace MWGui
|
|||||||
default: color = "#FFFFFF";
|
default: color = "#FFFFFF";
|
||||||
}
|
}
|
||||||
bool bufferOverflow = false;
|
bool bufferOverflow = false;
|
||||||
|
std::lock_guard lock(sBufferMutex);
|
||||||
const int64_t bufSize = sLogCircularBuffer.size();
|
const int64_t bufSize = sLogCircularBuffer.size();
|
||||||
auto addChar = [&](char c)
|
auto addChar = [&](char c)
|
||||||
{
|
{
|
||||||
@ -153,6 +157,8 @@ namespace MWGui
|
|||||||
|
|
||||||
void DebugWindow::updateLogView()
|
void DebugWindow::updateLogView()
|
||||||
{
|
{
|
||||||
|
std::lock_guard lock(sBufferMutex);
|
||||||
|
|
||||||
if (!mLogView || sLogCircularBuffer.empty() || sLogStartIndex == sLogEndIndex)
|
if (!mLogView || sLogCircularBuffer.empty() || sLogStartIndex == sLogEndIndex)
|
||||||
return;
|
return;
|
||||||
if (mLogView->isTextSelection())
|
if (mLogView->isTextSelection())
|
||||||
@ -161,8 +167,6 @@ namespace MWGui
|
|||||||
std::string addition;
|
std::string addition;
|
||||||
const int64_t bufSize = sLogCircularBuffer.size();
|
const int64_t bufSize = sLogCircularBuffer.size();
|
||||||
{
|
{
|
||||||
// Log object is only required for locking at this point.
|
|
||||||
Log log(Debug::Debug);
|
|
||||||
if (sLogStartIndex < sLogEndIndex)
|
if (sLogStartIndex < sLogEndIndex)
|
||||||
addition = std::string(sLogCircularBuffer.data() + sLogStartIndex, sLogEndIndex - sLogStartIndex);
|
addition = std::string(sLogCircularBuffer.data() + sLogStartIndex, sLogEndIndex - sLogStartIndex);
|
||||||
else
|
else
|
||||||
|
@ -20,13 +20,7 @@ namespace MWGui
|
|||||||
void updateBulletProfile();
|
void updateBulletProfile();
|
||||||
|
|
||||||
MyGUI::TabControl* mTabControl;
|
MyGUI::TabControl* mTabControl;
|
||||||
|
|
||||||
MyGUI::EditBox* mLogView;
|
MyGUI::EditBox* mLogView;
|
||||||
|
|
||||||
static std::vector<char> sLogCircularBuffer;
|
|
||||||
static int64_t sLogStartIndex;
|
|
||||||
static int64_t sLogEndIndex;
|
|
||||||
|
|
||||||
MyGUI::EditBox* mBulletProfilerEdit;
|
MyGUI::EditBox* mBulletProfilerEdit;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user