Skip to content

Commit

Permalink
thread safety
Browse files Browse the repository at this point in the history
  • Loading branch information
ssdetlab committed Nov 12, 2024
1 parent 8d43d18 commit 1ff8d2c
Showing 1 changed file with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <concepts>
#include <map>
#include <memory>
#include <mutex>
#include <stdexcept>
#include <type_traits>
#include <utility>
Expand Down Expand Up @@ -90,6 +91,8 @@ class TrackParamsLookupAccumulator {
void addTrack(const TrackParameters& ipTrackParameters,
const TrackParameters& refTrackParameters,
const Vector2& position) {
std::lock_guard<std::mutex> lock(m_gridMutex);

auto bin = m_grid.localBinsFromPosition(position);

if (m_countGrid[bin] == 0) {
Expand Down Expand Up @@ -208,6 +211,9 @@ class TrackParamsLookupAccumulator {
/// layer track parameters
LookupGrid m_grid;

/// Mutex for protecting grid access
std::mutex m_gridMutex;

/// Map to keep the accumulation count
/// in the occupied grid bins
std::map<std::array<std::size_t, LookupGrid::DIM>, std::size_t> m_countGrid;
Expand Down

0 comments on commit 1ff8d2c

Please sign in to comment.