Allow forceful insertion into main thread queue.

This is useful to run some tasks outside of the main render job.
This commit is contained in:
Bartosz Taudul 2021-11-18 22:46:59 +01:00
parent 89ca010146
commit 902de497dc
No known key found for this signature in database
GPG Key ID: B7FE2008B7575DF3
5 changed files with 11 additions and 11 deletions

View File

@ -130,9 +130,9 @@ static uint32_t updateVersion = 0;
static bool showReleaseNotes = false; static bool showReleaseNotes = false;
static std::string releaseNotes; static std::string releaseNotes;
void RunOnMainThread( std::function<void()> cb ) void RunOnMainThread( std::function<void()> cb, bool forceDelay = false )
{ {
if( std::this_thread::get_id() == mainThread ) if( !forceDelay && std::this_thread::get_id() == mainThread )
{ {
cb(); cb();
} }

View File

@ -22,10 +22,10 @@ void* MakeTexture()
return (void*)(intptr_t)tex; return (void*)(intptr_t)tex;
} }
void FreeTexture( void* _tex, void(*runOnMainThread)(std::function<void()>) ) void FreeTexture( void* _tex, void(*runOnMainThread)(std::function<void()>, bool) )
{ {
auto tex = (GLuint)(intptr_t)_tex; auto tex = (GLuint)(intptr_t)_tex;
runOnMainThread( [tex] { glDeleteTextures( 1, &tex ); } ); runOnMainThread( [tex] { glDeleteTextures( 1, &tex ); }, false );
} }
void UpdateTexture( void* _tex, const char* data, int w, int h ) void UpdateTexture( void* _tex, const char* data, int w, int h )

View File

@ -7,7 +7,7 @@ namespace tracy
{ {
void* MakeTexture(); void* MakeTexture();
void FreeTexture( void* tex, void(*runOnMainThread)(std::function<void()>) ); void FreeTexture( void* tex, void(*runOnMainThread)(std::function<void()>, bool) );
void UpdateTexture( void* tex, const char* data, int w, int h ); void UpdateTexture( void* tex, const char* data, int w, int h );
} }

View File

@ -134,7 +134,7 @@ enum { MinFrameSize = 5 };
static View* s_instance = nullptr; static View* s_instance = nullptr;
View::View( void(*cbMainThread)(std::function<void()>), const char* addr, uint16_t port, ImFont* fixedWidth, ImFont* smallFont, ImFont* bigFont, SetTitleCallback stcb, GetWindowCallback gwcb, SetScaleCallback sscb ) View::View( void(*cbMainThread)(std::function<void()>, bool), const char* addr, uint16_t port, ImFont* fixedWidth, ImFont* smallFont, ImFont* bigFont, SetTitleCallback stcb, GetWindowCallback gwcb, SetScaleCallback sscb )
: m_worker( addr, port ) : m_worker( addr, port )
, m_staticView( false ) , m_staticView( false )
, m_viewMode( ViewMode::LastFrames ) , m_viewMode( ViewMode::LastFrames )
@ -160,7 +160,7 @@ View::View( void(*cbMainThread)(std::function<void()>), const char* addr, uint16
InitTextEditor( fixedWidth ); InitTextEditor( fixedWidth );
} }
View::View( void(*cbMainThread)(std::function<void()>), FileRead& f, ImFont* fixedWidth, ImFont* smallFont, ImFont* bigFont, SetTitleCallback stcb, GetWindowCallback gwcb, SetScaleCallback sscb ) View::View( void(*cbMainThread)(std::function<void()>, bool), FileRead& f, ImFont* fixedWidth, ImFont* smallFont, ImFont* bigFont, SetTitleCallback stcb, GetWindowCallback gwcb, SetScaleCallback sscb )
: m_worker( f ) : m_worker( f )
, m_filename( f.GetFilename() ) , m_filename( f.GetFilename() )
, m_staticView( true ) , m_staticView( true )

View File

@ -92,9 +92,9 @@ public:
using GetWindowCallback = void*(*)(); using GetWindowCallback = void*(*)();
using SetScaleCallback = void(*)( float, ImFont*&, ImFont*&, ImFont*& ); using SetScaleCallback = void(*)( float, ImFont*&, ImFont*&, ImFont*& );
View( void(*cbMainThread)(std::function<void()>), ImFont* fixedWidth = nullptr, ImFont* smallFont = nullptr, ImFont* bigFont = nullptr, SetTitleCallback stcb = nullptr, GetWindowCallback gwcb = nullptr, SetScaleCallback sscb = nullptr ) : View( cbMainThread, "127.0.0.1", 8086, fixedWidth, smallFont, bigFont, stcb, gwcb, sscb ) {} View( void(*cbMainThread)(std::function<void()>, bool), ImFont* fixedWidth = nullptr, ImFont* smallFont = nullptr, ImFont* bigFont = nullptr, SetTitleCallback stcb = nullptr, GetWindowCallback gwcb = nullptr, SetScaleCallback sscb = nullptr ) : View( cbMainThread, "127.0.0.1", 8086, fixedWidth, smallFont, bigFont, stcb, gwcb, sscb ) {}
View( void(*cbMainThread)(std::function<void()>), const char* addr, uint16_t port, ImFont* fixedWidth = nullptr, ImFont* smallFont = nullptr, ImFont* bigFont = nullptr, SetTitleCallback stcb = nullptr, GetWindowCallback gwcb = nullptr, SetScaleCallback sscb = nullptr ); View( void(*cbMainThread)(std::function<void()>, bool), const char* addr, uint16_t port, ImFont* fixedWidth = nullptr, ImFont* smallFont = nullptr, ImFont* bigFont = nullptr, SetTitleCallback stcb = nullptr, GetWindowCallback gwcb = nullptr, SetScaleCallback sscb = nullptr );
View( void(*cbMainThread)(std::function<void()>), FileRead& f, ImFont* fixedWidth = nullptr, ImFont* smallFont = nullptr, ImFont* bigFont = nullptr, SetTitleCallback stcb = nullptr, GetWindowCallback gwcb = nullptr, SetScaleCallback sscb = nullptr ); View( void(*cbMainThread)(std::function<void()>, bool), FileRead& f, ImFont* fixedWidth = nullptr, ImFont* smallFont = nullptr, ImFont* bigFont = nullptr, SetTitleCallback stcb = nullptr, GetWindowCallback gwcb = nullptr, SetScaleCallback sscb = nullptr );
~View(); ~View();
static bool Draw(); static bool Draw();
@ -531,7 +531,7 @@ private:
unordered_flat_map<int16_t, StatisticsCache> m_statCache; unordered_flat_map<int16_t, StatisticsCache> m_statCache;
void(*m_cbMainThread)(std::function<void()>); void(*m_cbMainThread)(std::function<void()>, bool);
struct FindZone { struct FindZone {
enum : uint64_t { Unselected = std::numeric_limits<uint64_t>::max() - 1 }; enum : uint64_t { Unselected = std::numeric_limits<uint64_t>::max() - 1 };