From 1399e6f6b9646782614c69bf667b9fe7e95a4cf5 Mon Sep 17 00:00:00 2001 From: alexey Date: Wed, 28 Jun 2023 15:34:00 +0700 Subject: [PATCH] fix broken gltest Order of deletion was changed, default behaviour became erroneous. --- src/gtests/gtests_globalstate.cpp | 3 ++- src/searchd.cpp | 4 +--- src/threadutils.cpp | 10 +++++++++- src/threadutils.h | 1 + 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/gtests/gtests_globalstate.cpp b/src/gtests/gtests_globalstate.cpp index f122226f5e..1e8be018a9 100644 --- a/src/gtests/gtests_globalstate.cpp +++ b/src/gtests/gtests_globalstate.cpp @@ -66,8 +66,8 @@ class Environment : public ::testing::Environment auto iThreads = GetNumLogicalCPUs(); // iThreads = 1; // uncomment if want to run all coro tests in single thread SetMaxChildrenThreads ( iThreads ); - WipeGlobalSchedulerOnShutdownAndFork(); StartGlobalWorkPool(); + WipeGlobalSchedulerOnShutdownAndFork(); #if _WIN32 // init WSA on Windows WSADATA wsa_data; @@ -85,6 +85,7 @@ class Environment : public ::testing::Environment { unlink ( g_sTmpfile ); unlink ( g_sMagickTmpfile ); + StopGlobalWorkPool(); } }; diff --git a/src/searchd.cpp b/src/searchd.cpp index 95d7cc1275..2561127615 100644 --- a/src/searchd.cpp +++ b/src/searchd.cpp @@ -761,9 +761,7 @@ void Shutdown () REQUIRES ( MainThread ) NO_THREAD_SAFETY_ANALYSIS Detached::ShutdownAllAlones(); SHUTINFO << "Shutdown main work pool ..."; - auto pPool = GlobalWorkPool(); - if ( pPool ) - pPool->StopAll(); + StopGlobalWorkPool(); SHUTINFO << "Remove local tables list ..."; g_pLocalIndexes.reset(); diff --git a/src/threadutils.cpp b/src/threadutils.cpp index 0fb80ff0dd..d59bc17039 100644 --- a/src/threadutils.cpp +++ b/src/threadutils.cpp @@ -1133,6 +1133,14 @@ void StartGlobalWorkPool () pPool = new ThreadPool_c ( g_iMaxChildrenThreads, "work" ); } +void StopGlobalWorkPool() +{ + sphLogDebug ( "StopGlobalWorkPool" ); + WorkerSharedPtr_t& pPool = GlobalPoolSingletone(); + if ( pPool ) + pPool->StopAll(); +} + void SetMaxChildrenThreads ( int iThreads ) { sphLogDebug ( "SetMaxChildrenThreads to %d", iThreads ); @@ -1276,7 +1284,7 @@ bool OperationsQueue_c::IsEmpty() const namespace { // static -class IterationHandler_c : public Threads::details::SchedulerOperation_t + class IterationHandler_c : public Threads::details::SchedulerOperation_t { ThreadIteratorFN m_Handler; diff --git a/src/threadutils.h b/src/threadutils.h index 641769e454..cf441c3112 100644 --- a/src/threadutils.h +++ b/src/threadutils.h @@ -264,6 +264,7 @@ namespace CrashLogger Threads::Worker_i* GlobalWorkPool (); void SetMaxChildrenThreads ( int iThreads ); void StartGlobalWorkPool (); +void StopGlobalWorkPool(); /// schedule stop of the global thread pool void WipeGlobalSchedulerOnShutdownAndFork ();