From 0ec32d97c0f3b9ee1034f6fd53e075dd8b99a178 Mon Sep 17 00:00:00 2001 From: Sergey Linev <S.Linev@gsi.de> Date: Tue, 2 Mar 2021 10:59:00 +0100 Subject: [PATCH] [webgui] let reassign main thread id If application runs in special thread, one should call RWebWindowManager::AssignMainThrd() to indicate this --- gui/webdisplay/inc/ROOT/RWebWindowsManager.hxx | 5 +++-- gui/webdisplay/src/RWebWindowsManager.cxx | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/gui/webdisplay/inc/ROOT/RWebWindowsManager.hxx b/gui/webdisplay/inc/ROOT/RWebWindowsManager.hxx index 10ac72cacc9..a774db752ae 100644 --- a/gui/webdisplay/inc/ROOT/RWebWindowsManager.hxx +++ b/gui/webdisplay/inc/ROOT/RWebWindowsManager.hxx @@ -60,8 +60,6 @@ private: int WaitFor(RWebWindow &win, WebWindowWaitFunc_t check, bool timed = false, double tm = -1); - static bool IsMainThrd(); - std::string GetUrl(const RWebWindow &win, bool remote = false); bool CreateServer(bool with_http = false); @@ -82,6 +80,9 @@ public: std::shared_ptr<RWebWindow> CreateWindow(); void Terminate(); + + static bool IsMainThrd(); + static void AssignMainThrd(); }; } // namespace Experimental diff --git a/gui/webdisplay/src/RWebWindowsManager.cxx b/gui/webdisplay/src/RWebWindowsManager.cxx index c4ca16e97bc..d46587db49b 100644 --- a/gui/webdisplay/src/RWebWindowsManager.cxx +++ b/gui/webdisplay/src/RWebWindowsManager.cxx @@ -69,12 +69,28 @@ static std::thread::id gWebWinMainThrd = std::this_thread::get_id(); ////////////////////////////////////////////////////////////////////////////////////////// /// Returns true when called from main process /// Main process recognized at the moment when library is loaded +/// It supposed to be a thread where gApplication->Run() will be called +/// If application runs in separate thread, one have to use AssignMainThrd() method +/// to let RWebWindowsManager correctly recognize such situation bool ROOT::Experimental::RWebWindowsManager::IsMainThrd() { return std::this_thread::get_id() == gWebWinMainThrd; } +////////////////////////////////////////////////////////////////////////////////////////// +/// Re-assigns main thread id +/// Normally main thread id recognized at the moment when library is loaded +/// It supposed to be a thread where gApplication->Run() will be called +/// If application runs in separate thread, one have to call this method +/// to let RWebWindowsManager correctly recognize such situation + +void ROOT::Experimental::RWebWindowsManager::AssignMainThrd() +{ + gWebWinMainThrd = std::this_thread::get_id(); +} + + ////////////////////////////////////////////////////////////////////////////////////////// /// window manager constructor /// Required here for correct usage of unique_ptr<THttpServer> -- GitLab