1
0
mirror of https://github.com/wolfpld/tracy synced 2025-04-29 20:33:52 +00:00

Keep viewShutdown in atomic.

This commit is contained in:
Bartosz Taudul 2020-05-13 19:20:20 +02:00
parent 1fdae70cf8
commit b166451750

View File

@ -1,5 +1,6 @@
#include <algorithm> #include <algorithm>
#include <assert.h> #include <assert.h>
#include <atomic>
#include <chrono> #include <chrono>
#include <inttypes.h> #include <inttypes.h>
#include <imgui.h> #include <imgui.h>
@ -123,7 +124,7 @@ static ImFont* fixedWidth;
static char addr[1024] = { "127.0.0.1" }; static char addr[1024] = { "127.0.0.1" };
static std::unordered_map<std::string, uint64_t> connHistMap; static std::unordered_map<std::string, uint64_t> connHistMap;
static std::vector<std::unordered_map<std::string, uint64_t>::const_iterator> connHistVec; static std::vector<std::unordered_map<std::string, uint64_t>::const_iterator> connHistVec;
static ViewShutdown viewShutdown = ViewShutdown::False; static std::atomic<ViewShutdown> viewShutdown { ViewShutdown::False };
static double animTime = 0; static double animTime = 0;
static float dpiScale = 1.f; static float dpiScale = 1.f;
static ImGuiTextFilter addrFilter, portFilter, progFilter; static ImGuiTextFilter addrFilter, portFilter, progFilter;
@ -794,7 +795,7 @@ static void DrawContents()
view->NotifyRootWindowSize( display_w, display_h ); view->NotifyRootWindowSize( display_w, display_h );
if( !view->Draw() ) if( !view->Draw() )
{ {
viewShutdown = ViewShutdown::True; viewShutdown.store( ViewShutdown::True, std::memory_order_relaxed );
reconnect = view->ReconnectRequested(); reconnect = view->ReconnectRequested();
if( reconnect ) if( reconnect )
{ {
@ -803,7 +804,7 @@ static void DrawContents()
} }
loadThread = std::thread( [view = std::move( view )] () mutable { loadThread = std::thread( [view = std::move( view )] () mutable {
view.reset(); view.reset();
viewShutdown = ViewShutdown::Join; viewShutdown.store( ViewShutdown::Join, std::memory_order_relaxed );
} ); } );
} }
} }
@ -880,14 +881,14 @@ static void DrawContents()
} }
ImGui::EndPopup(); ImGui::EndPopup();
} }
switch( viewShutdown ) switch( viewShutdown.load( std::memory_order_relaxed ) )
{ {
case ViewShutdown::True: case ViewShutdown::True:
ImGui::OpenPopup( "Capture cleanup..." ); ImGui::OpenPopup( "Capture cleanup..." );
break; break;
case ViewShutdown::Join: case ViewShutdown::Join:
loadThread.join(); loadThread.join();
viewShutdown = ViewShutdown::False; viewShutdown.store( ViewShutdown::False, std::memory_order_relaxed );
if( reconnect ) if( reconnect )
{ {
view = std::make_unique<tracy::View>( reconnectAddr.c_str(), reconnectPort, fixedWidth, smallFont, bigFont, SetWindowTitleCallback ); view = std::make_unique<tracy::View>( reconnectAddr.c_str(), reconnectPort, fixedWidth, smallFont, bigFont, SetWindowTitleCallback );
@ -898,7 +899,7 @@ static void DrawContents()
} }
if( ImGui::BeginPopupModal( "Capture cleanup...", nullptr, ImGuiWindowFlags_AlwaysAutoResize ) ) if( ImGui::BeginPopupModal( "Capture cleanup...", nullptr, ImGuiWindowFlags_AlwaysAutoResize ) )
{ {
if( viewShutdown != ViewShutdown::True ) ImGui::CloseCurrentPopup(); if( viewShutdown.load( std::memory_order_relaxed ) != ViewShutdown::True ) ImGui::CloseCurrentPopup();
tracy::TextCentered( ICON_FA_BROOM ); tracy::TextCentered( ICON_FA_BROOM );
animTime += ImGui::GetIO().DeltaTime; animTime += ImGui::GetIO().DeltaTime;
tracy::DrawWaitingDots( animTime ); tracy::DrawWaitingDots( animTime );