Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Framework/Core/include/Framework/DriverClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
9 changes: 6 additions & 3 deletions Framework/Core/include/Framework/ServiceRegistryRef.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions Framework/Core/src/CommonServices.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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<Monitoring>();
auto& relayer = registry.get<DataRelayer>();
Expand Down
2 changes: 1 addition & 1 deletion Framework/Core/src/WSDriverClient.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::mutex> lock(mClientMutex);
Expand Down