# HG changeset patch # User Sebastien Jodogne # Date 1754896313 -7200 # Node ID de176f458e35d46280525f01e2db5fe20660236e # Parent fb8bed996341a138b272f05c8ec613fc786a55e4 protecting HttpServer::threadCounter_ by a mutex diff -r fb8bed996341 -r de176f458e35 OrthancFramework/Sources/HttpServer/HttpServer.cpp --- a/OrthancFramework/Sources/HttpServer/HttpServer.cpp Mon Aug 11 08:56:23 2025 +0200 +++ b/OrthancFramework/Sources/HttpServer/HttpServer.cpp Mon Aug 11 09:11:53 2025 +0200 @@ -1192,10 +1192,12 @@ struct mg_connection *connection, const struct mg_request_info *request) { - bool localhost; + server.UpdateCurrentThreadName(); std::unique_ptr counter(server.CreateAvailableHttpThreadsDecounter()); + bool localhost; + #if ORTHANC_ENABLE_MONGOOSE == 1 static const long LOCALHOST = (127ll << 24) + 1ll; localhost = (request->remote_ip == LOCALHOST); @@ -1615,8 +1617,6 @@ } } - static uint16_t threadCounter = 0; - #if MONGOOSE_USE_CALLBACKS == 0 static void* Callback(enum mg_event event, struct mg_connection *connection, @@ -1639,12 +1639,6 @@ static int Callback(struct mg_connection *connection) { const struct mg_request_info *request = mg_get_request_info(connection); - - if (!Logging::HasCurrentThreadName()) - { - Logging::SetCurrentThreadName(std::string("HTTP-") + boost::lexical_cast(threadCounter++)); - } - ProtectedCallback(connection, request); return 1; // Do not let Mongoose handle the request by itself @@ -1732,7 +1726,7 @@ void HttpServer::Start() { // reset thread counter used to generate HTTP thread names. - threadCounter = 0; + threadCounter_ = 0; #if ORTHANC_ENABLE_MONGOOSE == 1 CLOG(INFO, HTTP) << "Starting embedded Web server using Mongoose"; @@ -2315,4 +2309,14 @@ return NULL; } } + + + void HttpServer::UpdateCurrentThreadName() + { + if (!Logging::HasCurrentThreadName()) + { + boost::mutex::scoped_lock lock(threadCounterMutex_); + Logging::SetCurrentThreadName(std::string("HTTP-") + boost::lexical_cast(threadCounter_++)); + } + } } diff -r fb8bed996341 -r de176f458e35 OrthancFramework/Sources/HttpServer/HttpServer.h --- a/OrthancFramework/Sources/HttpServer/HttpServer.h Mon Aug 11 08:56:23 2025 +0200 +++ b/OrthancFramework/Sources/HttpServer/HttpServer.h Mon Aug 11 09:11:53 2025 +0200 @@ -117,6 +117,9 @@ unsigned int requestTimeout_; // In seconds std::unique_ptr availableHttpThreadsMetrics_; // New in Orthanc 1.12.9 + boost::mutex threadCounterMutex_; // New in Orthanc 1.12.9 + uint16_t threadCounter_ = 0; // Introduced as a global, static variable in Orthanc 1.12.2 + #if ORTHANC_ENABLE_PUGIXML == 1 WebDavBuckets webDavBuckets_; #endif @@ -236,5 +239,7 @@ // Can return NULL if SetMetricsRegistry() was not call beforehand MetricsRegistry::AvailableResourcesDecounter* CreateAvailableHttpThreadsDecounter(); + + void UpdateCurrentThreadName(); }; }