From df7928ece316aea6edf05597b3362ad73e12f2cf Mon Sep 17 00:00:00 2001 From: Giulio Eulisse <10544+ktf@users.noreply.github.com> Date: Fri, 4 Dec 2026 11:59:01 +0100 Subject: [PATCH] Rename isMainThread to isGlobalContext --- Framework/Core/include/Framework/DriverClient.h | 2 +- Framework/Core/include/Framework/ServiceRegistryRef.h | 9 ++++++--- Framework/Core/src/CommonServices.cxx | 8 ++++---- Framework/Core/src/WSDriverClient.cxx | 2 +- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/Framework/Core/include/Framework/DriverClient.h b/Framework/Core/include/Framework/DriverClient.h index a0e2d3e0d1f92..120627656ea29 100644 --- a/Framework/Core/include/Framework/DriverClient.h +++ b/Framework/Core/include/Framework/DriverClient.h @@ -53,7 +53,7 @@ class DriverClient /// Note: this must be guaranteed to be called from the main thread, /// because the libuv backend cannot queue write operations on a thread /// which is not the main one. In order to do this, one should - /// have assert(mainTreadRef.isMainThread()) in the implementation. + /// have assert(mainTreadRef.isGlobalContext()) in the implementation. /// Notice also that if you want to use uv_async_send, you must make /// sure that you do not rely on having as many events as the times /// you called uv_async_send, because this is not guaranteed. diff --git a/Framework/Core/include/Framework/ServiceRegistryRef.h b/Framework/Core/include/Framework/ServiceRegistryRef.h index 8d8dbc2a4f5cf..0790f709270b8 100644 --- a/Framework/Core/include/Framework/ServiceRegistryRef.h +++ b/Framework/Core/include/Framework/ServiceRegistryRef.h @@ -64,10 +64,13 @@ class ServiceRegistryRef { } - // Wether or not this is the main thread - bool isMainThread() + // Whether this ref was made for the global context rather than for one of the + // streams -- GLOBAL_CONTEXT_SALT, i.e. streamId 0. Not a question about which + // thread is running: a stream's work can be executed on the main thread and + // still, correctly, hold a stream salt. + bool isGlobalContext() { - return mSalt.streamId == 0; + return mSalt.streamId == ServiceRegistry::GLOBAL_CONTEXT_SALT.streamId; } /// Check if service of type T is currently active. diff --git a/Framework/Core/src/CommonServices.cxx b/Framework/Core/src/CommonServices.cxx index da6b0d33135ab..0053b191816b9 100644 --- a/Framework/Core/src/CommonServices.cxx +++ b/Framework/Core/src/CommonServices.cxx @@ -903,12 +903,12 @@ O2_DECLARE_DYNAMIC_LOG(monitoring_service); /// This will flush metrics only once every second. auto flushMetrics(ServiceRegistryRef registry, DataProcessingStats& stats) -> void { - // Flushing metrics should only happen on main thread to avoid - // having to have a mutex for the communication with the driver. + // Flushing metrics needs the global context: the communication with the driver + // has no mutex around it. O2_SIGNPOST_ID_GENERATE(sid, monitoring_service); O2_SIGNPOST_START(monitoring_service, sid, "flush", "flushing metrics"); - if (registry.isMainThread() == false) { - LOGP(fatal, "Flushing metrics should only happen on the main thread."); + if (registry.isGlobalContext() == false) { + LOGP(fatal, "Flushing metrics needs a global context: it talks to the driver without a mutex."); } auto& monitoring = registry.get(); auto& relayer = registry.get(); diff --git a/Framework/Core/src/WSDriverClient.cxx b/Framework/Core/src/WSDriverClient.cxx index d539b34acb42f..03c5b63b84ffd 100644 --- a/Framework/Core/src/WSDriverClient.cxx +++ b/Framework/Core/src/WSDriverClient.cxx @@ -308,7 +308,7 @@ void WSDriverClient::awake() void WSDriverClient::flushPending(ServiceRegistryRef mainThreadRef) { - if (mainThreadRef.isMainThread() == false) { + if (mainThreadRef.isGlobalContext() == false) { LOG(error) << "flushPending not called from main thread"; } std::lock_guard lock(mClientMutex);