mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-03-01 10:13:38 +00:00
PerformanceTracker: Use shared_mutex instead of mutex so multiple threads can read at the same time.
This commit is contained in:
parent
9143eb00fb
commit
bc46089ab0
@ -5,8 +5,10 @@
|
|||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <implot.h>
|
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
|
#include <implot.h>
|
||||||
|
|
||||||
#include "Common/CommonTypes.h"
|
#include "Common/CommonTypes.h"
|
||||||
#include "Common/FileUtil.h"
|
#include "Common/FileUtil.h"
|
||||||
@ -36,7 +38,7 @@ PerformanceTracker::~PerformanceTracker()
|
|||||||
|
|
||||||
void PerformanceTracker::Reset()
|
void PerformanceTracker::Reset()
|
||||||
{
|
{
|
||||||
std::lock_guard lock{m_mutex};
|
std::unique_lock lock{m_mutex};
|
||||||
|
|
||||||
QueueClear();
|
QueueClear();
|
||||||
m_last_time = Clock::now();
|
m_last_time = Clock::now();
|
||||||
@ -47,7 +49,7 @@ void PerformanceTracker::Reset()
|
|||||||
|
|
||||||
void PerformanceTracker::Count()
|
void PerformanceTracker::Count()
|
||||||
{
|
{
|
||||||
std::lock_guard lock{m_mutex};
|
std::unique_lock lock{m_mutex};
|
||||||
|
|
||||||
if (m_paused)
|
if (m_paused)
|
||||||
return;
|
return;
|
||||||
@ -97,19 +99,19 @@ DT PerformanceTracker::GetSampleWindow() const
|
|||||||
|
|
||||||
double PerformanceTracker::GetHzAvg() const
|
double PerformanceTracker::GetHzAvg() const
|
||||||
{
|
{
|
||||||
std::lock_guard lock{m_mutex};
|
std::shared_lock lock{m_mutex};
|
||||||
return m_hz_avg;
|
return m_hz_avg;
|
||||||
}
|
}
|
||||||
|
|
||||||
DT PerformanceTracker::GetDtAvg() const
|
DT PerformanceTracker::GetDtAvg() const
|
||||||
{
|
{
|
||||||
std::lock_guard lock{m_mutex};
|
std::shared_lock lock{m_mutex};
|
||||||
return m_dt_avg;
|
return m_dt_avg;
|
||||||
}
|
}
|
||||||
|
|
||||||
DT PerformanceTracker::GetDtStd() const
|
DT PerformanceTracker::GetDtStd() const
|
||||||
{
|
{
|
||||||
std::lock_guard lock{m_mutex};
|
std::unique_lock lock{m_mutex};
|
||||||
|
|
||||||
if (m_dt_std)
|
if (m_dt_std)
|
||||||
return *m_dt_std;
|
return *m_dt_std;
|
||||||
@ -130,7 +132,7 @@ DT PerformanceTracker::GetDtStd() const
|
|||||||
|
|
||||||
DT PerformanceTracker::GetLastRawDt() const
|
DT PerformanceTracker::GetLastRawDt() const
|
||||||
{
|
{
|
||||||
std::lock_guard lock{m_mutex};
|
std::shared_lock lock{m_mutex};
|
||||||
|
|
||||||
if (QueueEmpty())
|
if (QueueEmpty())
|
||||||
return DT::zero();
|
return DT::zero();
|
||||||
@ -142,7 +144,7 @@ void PerformanceTracker::ImPlotPlotLines(const char* label) const
|
|||||||
{
|
{
|
||||||
static std::array<float, MAX_DT_QUEUE_SIZE + 2> x, y;
|
static std::array<float, MAX_DT_QUEUE_SIZE + 2> x, y;
|
||||||
|
|
||||||
std::lock_guard lock{m_mutex};
|
std::shared_lock lock{m_mutex};
|
||||||
|
|
||||||
if (QueueEmpty())
|
if (QueueEmpty())
|
||||||
return;
|
return;
|
||||||
@ -238,7 +240,7 @@ void PerformanceTracker::LogRenderTimeToFile(DT val)
|
|||||||
|
|
||||||
void PerformanceTracker::SetPaused(bool paused)
|
void PerformanceTracker::SetPaused(bool paused)
|
||||||
{
|
{
|
||||||
std::lock_guard lock{m_mutex};
|
std::unique_lock lock{m_mutex};
|
||||||
|
|
||||||
m_paused = paused;
|
m_paused = paused;
|
||||||
if (m_paused)
|
if (m_paused)
|
||||||
|
@ -6,8 +6,8 @@
|
|||||||
#include <array>
|
#include <array>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <mutex>
|
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
#include <shared_mutex>
|
||||||
|
|
||||||
#include "Common/CommonTypes.h"
|
#include "Common/CommonTypes.h"
|
||||||
|
|
||||||
@ -100,5 +100,5 @@ private: // Functions for managing dt queue
|
|||||||
mutable std::optional<DT> m_dt_std = std::nullopt;
|
mutable std::optional<DT> m_dt_std = std::nullopt;
|
||||||
|
|
||||||
// Used to enable thread safety with the performance tracker
|
// Used to enable thread safety with the performance tracker
|
||||||
mutable std::mutex m_mutex;
|
mutable std::shared_mutex m_mutex;
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user