From cb5029f8267ed32bd108a32797ce92d220a12e0c Mon Sep 17 00:00:00 2001 From: Dennis Klein Date: Fri, 11 Mar 2022 16:44:56 +0100 Subject: [PATCH] fix(Device): Spawn rate logger thread only if needed --- fairmq/Device.cxx | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/fairmq/Device.cxx b/fairmq/Device.cxx index 1ce5ed1c..a473ae90 100644 --- a/fairmq/Device.cxx +++ b/fairmq/Device.cxx @@ -6,14 +6,14 @@ * copied verbatim in the file "LICENSE" * ********************************************************************************/ -#include // std::max +#include // std::max, std::any_of #include // join/split #include #include #include -#include #include #include +#include // std::make_unique #include #include @@ -434,8 +434,15 @@ void Device::RunWrapper() { LOG(info) << "fair::mq::Device running..."; - // start the rate logger thread - future rateLogger = async(launch::async, &Device::LogSocketRates, this); + unique_ptr rateLogger; + // Check if rate logging thread is needed + const bool rateLogging = any_of(fChannels.cbegin(), fChannels.cend(), [](auto ch) { + return any_of(ch.second.cbegin(), ch.second.cend(), [](auto sub) { return sub.fRateLogging > 0; }); + }); + + if (rateLogging) { + rateLogger = make_unique(&Device::LogSocketRates, this); + } // notify transports to resume transfers for (auto& t : fTransports) { @@ -479,7 +486,9 @@ void Device::RunWrapper() cod.disable(); - rateLogger.get(); + if (rateLogging && rateLogger->joinable()) { + rateLogger->join(); + } } void Device::HandleSingleChannelInput()