Skip to content

Commit

Permalink
VH-1279: Fix sonar reported bugs in MessageRouterBasic.cpp (#588)
Browse files Browse the repository at this point in the history
<!-- Thanks for the contribution, this is awesome. -->

# 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).
<!--- Describe your changes in detail -->

## Related Issue
VH-1297
<!--- This project only accepts pull requests related to open issues -->
<!--- If suggesting a new feature or change, please discuss it in an
issue first -->
<!--- If fixing a bug, there should be an issue describing it with steps
to reproduce -->
<!--- Please link to the issue here: -->

## Motivation and Context
Technical Debt
<!--- Why is this change required? What problem does it solve? -->

## How Has This Been Tested?

<!--- Please describe in detail how you tested your changes. -->
<!--- Include details of your testing environment, and the tests you ran
to -->
<!--- see how your change affects other areas of the code, etc. -->

## Types of changes

<!--- What types of changes does your code introduce? Put an `x` in all
the boxes that apply: -->

- [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:

<!--- Go over all the following points, and put an `x` in all the boxes
that apply. -->
<!--- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->

- [ ] 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.
  • Loading branch information
paulbourelly999 authored Mar 25, 2024
1 parent 62875bb commit fb65791
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 4 deletions.
4 changes: 1 addition & 3 deletions src/tmx/TmxCore/src/MessageRouterBasic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -107,7 +105,7 @@ void MessageRouterBasic::broadcastMessage(MessageReceiver *sender, IvpMessage *m
}
}
}

pthread_mutex_lock(&this->mActiveBroadcastsLock);
this->mActiveBroadcasts--;
pthread_mutex_unlock(&this->mActiveBroadcastsLock);
Expand Down
2 changes: 1 addition & 1 deletion src/tmx/TmxCore/src/MessageRouterBasic.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit fb65791

Please sign in to comment.