diff --git a/profiler/src/main.cpp b/profiler/src/main.cpp index e8ad3294..a287bff2 100644 --- a/profiler/src/main.cpp +++ b/profiler/src/main.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -123,7 +124,7 @@ static ImFont* fixedWidth; static char addr[1024] = { "127.0.0.1" }; static std::unordered_map connHistMap; static std::vector::const_iterator> connHistVec; -static ViewShutdown viewShutdown = ViewShutdown::False; +static std::atomic viewShutdown { ViewShutdown::False }; static double animTime = 0; static float dpiScale = 1.f; static ImGuiTextFilter addrFilter, portFilter, progFilter; @@ -794,7 +795,7 @@ static void DrawContents() view->NotifyRootWindowSize( display_w, display_h ); if( !view->Draw() ) { - viewShutdown = ViewShutdown::True; + viewShutdown.store( ViewShutdown::True, std::memory_order_relaxed ); reconnect = view->ReconnectRequested(); if( reconnect ) { @@ -803,7 +804,7 @@ static void DrawContents() } loadThread = std::thread( [view = std::move( view )] () mutable { view.reset(); - viewShutdown = ViewShutdown::Join; + viewShutdown.store( ViewShutdown::Join, std::memory_order_relaxed ); } ); } } @@ -880,14 +881,14 @@ static void DrawContents() } ImGui::EndPopup(); } - switch( viewShutdown ) + switch( viewShutdown.load( std::memory_order_relaxed ) ) { case ViewShutdown::True: ImGui::OpenPopup( "Capture cleanup..." ); break; case ViewShutdown::Join: loadThread.join(); - viewShutdown = ViewShutdown::False; + viewShutdown.store( ViewShutdown::False, std::memory_order_relaxed ); if( reconnect ) { view = std::make_unique( reconnectAddr.c_str(), reconnectPort, fixedWidth, smallFont, bigFont, SetWindowTitleCallback ); @@ -898,7 +899,7 @@ static void DrawContents() } 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 ); animTime += ImGui::GetIO().DeltaTime; tracy::DrawWaitingDots( animTime );