Use std::shared_mutex for locking worker access.

This commit is contained in:
Bartosz Taudul 2019-05-28 19:21:53 +02:00
parent 145ca30df9
commit 845f3a2ddf
3 changed files with 13 additions and 13 deletions

View File

@ -756,7 +756,7 @@ bool View::DrawImpl()
ImGui::Begin( tmp, keepOpenPtr, ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoBringToFrontOnFocus );
#endif
std::lock_guard<TracyMutex> lock( m_worker.GetDataLock() );
std::lock_guard<std::shared_mutex> lock( m_worker.GetDataLock() );
if( !m_worker.IsDataStatic() )
{
if( m_worker.IsConnected() )
@ -966,7 +966,7 @@ bool View::DrawConnection()
const auto cs = ty * 0.9f;
{
std::lock_guard<TracyMutex> lock( m_worker.GetMbpsDataLock() );
std::lock_guard<std::shared_mutex> lock( m_worker.GetMbpsDataLock() );
char tmp[2048];
sprintf( tmp, "%s###Connection", m_worker.GetAddr().c_str() );
ImGui::Begin( tmp, nullptr, ImGuiWindowFlags_AlwaysAutoResize );
@ -993,7 +993,7 @@ bool View::DrawConnection()
const auto wpos = ImGui::GetWindowPos() + ImGui::GetWindowContentRegionMin();
ImGui::GetWindowDrawList()->AddCircleFilled( wpos + ImVec2( 1 + cs * 0.5, 3 + ty * 0.5 ), cs * 0.5, m_worker.IsConnected() ? 0xFF2222CC : 0xFF444444, 10 );
std::lock_guard<TracyMutex> lock( m_worker.GetDataLock() );
std::lock_guard<std::shared_mutex> lock( m_worker.GetDataLock() );
{
const auto sz = m_worker.GetFrameCount( *m_frames );
if( sz > 1 )

View File

@ -1237,7 +1237,7 @@ finishLoading:
#endif
}
{
std::lock_guard<TracyMutex> lock( m_data.lock );
std::lock_guard<std::shared_mutex> lock( m_data.lock );
m_data.sourceLocationZonesReady = true;
}
if( reconstructMemAllocPlot ) ReconstructMemAllocPlot();
@ -1784,7 +1784,7 @@ void Worker::Exec()
const char* end = buf + sz;
{
std::lock_guard<TracyMutex> lock( m_data.lock );
std::lock_guard<std::shared_mutex> lock( m_data.lock );
while( ptr < end )
{
auto ev = (const QueueItem*)ptr;
@ -1810,7 +1810,7 @@ void Worker::Exec()
enum { MbpsUpdateTime = 200 };
if( td > MbpsUpdateTime )
{
std::lock_guard<TracyMutex> lock( m_mbpsData.lock );
std::lock_guard<std::shared_mutex> lock( m_mbpsData.lock );
m_mbpsData.mbps.erase( m_mbpsData.mbps.begin() );
m_mbpsData.mbps.emplace_back( bytes / ( td * 125.f ) );
m_mbpsData.compRatio = float( bytes ) / decBytes;
@ -3576,7 +3576,7 @@ void Worker::ReconstructMemAllocPlot()
PlotData* plot;
{
std::lock_guard<TracyMutex> lock( m_data.lock );
std::lock_guard<std::shared_mutex> lock( m_data.lock );
plot = m_slab.AllocInit<PlotData>();
}
@ -3659,7 +3659,7 @@ void Worker::ReconstructMemAllocPlot()
plot->min = 0;
plot->max = max;
std::lock_guard<TracyMutex> lock( m_data.lock );
std::lock_guard<std::shared_mutex> lock( m_data.lock );
m_data.plots.Data().insert( m_data.plots.Data().begin(), plot );
m_data.memory.plot = plot;
}

View File

@ -3,6 +3,7 @@
#include <atomic>
#include <limits>
#include <shared_mutex>
#include <stdexcept>
#include <string>
#include <thread>
@ -10,7 +11,6 @@
#include "../common/tracy_lz4.hpp"
#include "../common/TracyForceInline.hpp"
#include "../common/TracyMutex.hpp"
#include "../common/TracyQueue.hpp"
#include "../common/TracyProtocol.hpp"
#include "../common/TracySocket.hpp"
@ -137,7 +137,7 @@ private:
{
DataBlock() : zonesCnt( 0 ), lastTime( 0 ), frameOffset( 0 ), threadLast( std::numeric_limits<uint64_t>::max(), 0 ) {}
TracyMutex lock;
std::shared_mutex lock;
StringDiscovery<FrameData*> frames;
FrameData* framesBase;
Vector<GpuCtxData*> gpuData;
@ -188,7 +188,7 @@ private:
{
MbpsBlock() : mbps( 64 ), compRatio( 1.0 ), queue( 0 ) {}
TracyMutex lock;
std::shared_mutex lock;
std::vector<float> mbps;
float compRatio;
size_t queue;
@ -243,7 +243,7 @@ public:
int64_t GetDelay() const { return m_delay; }
int64_t GetResolution() const { return m_resolution; }
TracyMutex& GetDataLock() { return m_data.lock; }
std::shared_mutex& GetDataLock() { return m_data.lock; }
size_t GetFrameCount( const FrameData& fd ) const { return fd.frames.size(); }
size_t GetFullFrameCount( const FrameData& fd ) const;
int64_t GetTimeBegin() const { return GetFrameBegin( *m_data.framesBase, 0 ); }
@ -315,7 +315,7 @@ public:
}
tracy_force_inline uint64_t DecompressThread( uint16_t thread ) const { assert( thread < m_data.threadExpand.size() ); return m_data.threadExpand[thread]; }
TracyMutex& GetMbpsDataLock() { return m_mbpsData.lock; }
std::shared_mutex& GetMbpsDataLock() { return m_mbpsData.lock; }
const std::vector<float>& GetMbpsData() const { return m_mbpsData.mbps; }
float GetCompRatio() const { return m_mbpsData.compRatio; }
size_t GetSendQueueSize() const { return m_mbpsData.queue; }