From fb657915ff7a1534368b813d2ad7b00ce7ef6b89 Mon Sep 17 00:00:00 2001 From: paulbourelly999 <77466294+paulbourelly999@users.noreply.github.com> Date: Mon, 25 Mar 2024 11:31:46 -0400 Subject: [PATCH] VH-1279: Fix sonar reported bugs in MessageRouterBasic.cpp (#588) # PR Details ## Description Resolve sonar reported bugs in MessageRouterBasic.cpp (https://sonarcloud.io/project/issues?resolved=false&types=BUG&id=usdot-fhwa-ops_V2X-Hub). Removed unnecessary use of `volatile` keyword (see ThreadsafeCounter from https://en.cppreference.com/w/cpp/language/cv). ## Related Issue VH-1297 ## Motivation and Context Technical Debt ## How Has This Been Tested? ## Types of changes - [x] Defect fix (non-breaking change that fixes an issue) - [ ] New feature (non-breaking change that adds functionality) - [ ] Breaking change (fix or feature that cause existing functionality to change) ## Checklist: - [ ] I have added any new packages to the sonar-scanner.properties file - [ ] My change requires a change to the documentation. - [ ] I have updated the documentation accordingly. - [x] I have read the **CONTRIBUTING** document. [V2XHUB Contributing Guide](https://github.com/usdot-fhwa-OPS/V2X-Hub/blob/develop/Contributing.md) - [ ] I have added tests to cover my changes. - [ ] All new and existing tests passed. --- src/tmx/TmxCore/src/MessageRouterBasic.cpp | 4 +--- src/tmx/TmxCore/src/MessageRouterBasic.h | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/tmx/TmxCore/src/MessageRouterBasic.cpp b/src/tmx/TmxCore/src/MessageRouterBasic.cpp index ff7b78a5f..9545a57c9 100644 --- a/src/tmx/TmxCore/src/MessageRouterBasic.cpp +++ b/src/tmx/TmxCore/src/MessageRouterBasic.cpp @@ -50,11 +50,9 @@ void MessageRouterBasic::broadcastMessage(MessageReceiver *sender, IvpMessage *m //PerformanceTimer timer; - pthread_mutex_lock(&this->mMapLock); pthread_mutex_lock(&this->mActiveBroadcastsLock); this->mActiveBroadcasts++; pthread_mutex_unlock(&this->mActiveBroadcastsLock); - pthread_mutex_unlock(&this->mMapLock); int broadcastCount = 0; @@ -107,7 +105,7 @@ void MessageRouterBasic::broadcastMessage(MessageReceiver *sender, IvpMessage *m } } } - + pthread_mutex_lock(&this->mActiveBroadcastsLock); this->mActiveBroadcasts--; pthread_mutex_unlock(&this->mActiveBroadcastsLock); diff --git a/src/tmx/TmxCore/src/MessageRouterBasic.h b/src/tmx/TmxCore/src/MessageRouterBasic.h index 58cc10dc5..60d8fd04c 100644 --- a/src/tmx/TmxCore/src/MessageRouterBasic.h +++ b/src/tmx/TmxCore/src/MessageRouterBasic.h @@ -52,7 +52,7 @@ class MessageRouterBasic : public MessageRouter * Keeps track of how many threads are actively inside the broadcast method in a thread safe manner (using mActiveBroadcastsLock). * This is to allow concurrent execution of the broadcast, but give the register and unregister methods a way to tell when broadcasts are inactive. */ - volatile int mActiveBroadcasts; + int mActiveBroadcasts; /*! * Used to keep the mActiveBroadcast count accurate since multiple thread's may be accessing.