mirror of
https://github.com/wolfpld/tracy.git
synced 2024-11-10 02:31:48 +00:00
Use _mm_pause() instead of std::this_thread::yield() if possible.
This commit is contained in:
parent
8b56386ccd
commit
3a460d3183
@ -184,6 +184,7 @@
|
|||||||
<ClInclude Include="..\..\..\server\TracyView.hpp" />
|
<ClInclude Include="..\..\..\server\TracyView.hpp" />
|
||||||
<ClInclude Include="..\..\..\server\TracyViewData.hpp" />
|
<ClInclude Include="..\..\..\server\TracyViewData.hpp" />
|
||||||
<ClInclude Include="..\..\..\server\TracyWorker.hpp" />
|
<ClInclude Include="..\..\..\server\TracyWorker.hpp" />
|
||||||
|
<ClInclude Include="..\..\..\server\TracyYield.hpp" />
|
||||||
<ClInclude Include="..\..\..\server\tracy_flat_hash_map.hpp" />
|
<ClInclude Include="..\..\..\server\tracy_flat_hash_map.hpp" />
|
||||||
<ClInclude Include="..\..\..\server\tracy_pdqsort.h" />
|
<ClInclude Include="..\..\..\server\tracy_pdqsort.h" />
|
||||||
<ClInclude Include="..\..\..\server\tracy_xxh3.h" />
|
<ClInclude Include="..\..\..\server\tracy_xxh3.h" />
|
||||||
|
@ -302,6 +302,9 @@
|
|||||||
<ClInclude Include="..\..\..\server\tracy_xxh3.h">
|
<ClInclude Include="..\..\..\server\tracy_xxh3.h">
|
||||||
<Filter>server</Filter>
|
<Filter>server</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\..\..\server\TracyYield.hpp">
|
||||||
|
<Filter>server</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Natvis Include="DebugVis.natvis" />
|
<Natvis Include="DebugVis.natvis" />
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
#include <thread>
|
#include <thread>
|
||||||
|
|
||||||
#include "TracyFileHeader.hpp"
|
#include "TracyFileHeader.hpp"
|
||||||
|
#include "TracyYield.hpp"
|
||||||
#include "../common/tracy_lz4.hpp"
|
#include "../common/tracy_lz4.hpp"
|
||||||
#include "../common/TracyForceInline.hpp"
|
#include "../common/TracyForceInline.hpp"
|
||||||
|
|
||||||
@ -188,7 +189,7 @@ private:
|
|||||||
{
|
{
|
||||||
if( m_exit.load( std::memory_order_relaxed ) == true ) return;
|
if( m_exit.load( std::memory_order_relaxed ) == true ) return;
|
||||||
if( m_signalSwitch.load( std::memory_order_relaxed ) == true ) break;
|
if( m_signalSwitch.load( std::memory_order_relaxed ) == true ) break;
|
||||||
std::this_thread::yield();
|
YieldThread();
|
||||||
}
|
}
|
||||||
m_signalSwitch.store( false, std::memory_order_relaxed );
|
m_signalSwitch.store( false, std::memory_order_relaxed );
|
||||||
std::swap( m_buf, m_second );
|
std::swap( m_buf, m_second );
|
||||||
@ -212,7 +213,7 @@ private:
|
|||||||
if( m_offset == BufSize )
|
if( m_offset == BufSize )
|
||||||
{
|
{
|
||||||
m_signalSwitch.store( true, std::memory_order_relaxed );
|
m_signalSwitch.store( true, std::memory_order_relaxed );
|
||||||
while( m_signalAvailable.load( std::memory_order_acquire ) == false ) { std::this_thread::yield(); }
|
while( m_signalAvailable.load( std::memory_order_acquire ) == false ) { YieldThread(); }
|
||||||
m_signalAvailable.store( false, std::memory_order_relaxed );
|
m_signalAvailable.store( false, std::memory_order_relaxed );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -231,7 +232,7 @@ private:
|
|||||||
if( m_offset == BufSize )
|
if( m_offset == BufSize )
|
||||||
{
|
{
|
||||||
m_signalSwitch.store( true, std::memory_order_relaxed );
|
m_signalSwitch.store( true, std::memory_order_relaxed );
|
||||||
while( m_signalAvailable.load( std::memory_order_acquire ) == false ) { std::this_thread::yield(); }
|
while( m_signalAvailable.load( std::memory_order_acquire ) == false ) { YieldThread(); }
|
||||||
m_signalAvailable.store( false, std::memory_order_relaxed );
|
m_signalAvailable.store( false, std::memory_order_relaxed );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,6 +34,7 @@
|
|||||||
#include "TracyTaskDispatch.hpp"
|
#include "TracyTaskDispatch.hpp"
|
||||||
#include "TracyVersion.hpp"
|
#include "TracyVersion.hpp"
|
||||||
#include "TracyWorker.hpp"
|
#include "TracyWorker.hpp"
|
||||||
|
#include "TracyYield.hpp"
|
||||||
|
|
||||||
#include "tracy_flat_hash_map.hpp"
|
#include "tracy_flat_hash_map.hpp"
|
||||||
|
|
||||||
@ -1384,7 +1385,7 @@ Worker::Worker( FileRead& f, EventType::Type eventMask, bool bgTasks )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if( idx >= 0 ) break;
|
if( idx >= 0 ) break;
|
||||||
std::this_thread::yield();
|
YieldThread();
|
||||||
}
|
}
|
||||||
|
|
||||||
if( data[idx].bufsz < sz )
|
if( data[idx].bufsz < sz )
|
||||||
|
26
server/TracyYield.hpp
Normal file
26
server/TracyYield.hpp
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
#ifndef __TRACYYIELD_HPP__
|
||||||
|
#define __TRACYYIELD_HPP__
|
||||||
|
|
||||||
|
#if defined __SSE2__ || defined _M_AMD64 || _M_IX86_FP == 2
|
||||||
|
# include <emmintrin.h>
|
||||||
|
#else
|
||||||
|
# include <thread>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "../common/TracyForceInline.hpp"
|
||||||
|
|
||||||
|
namespace tracy
|
||||||
|
{
|
||||||
|
|
||||||
|
static tracy_force_inline void YieldThread()
|
||||||
|
{
|
||||||
|
#if defined __SSE2__ || defined _M_AMD64 || _M_IX86_FP == 2
|
||||||
|
_mm_pause();
|
||||||
|
#else
|
||||||
|
std::this_thread::yield();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in New Issue
Block a user