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