From 4471843f8bb3c17a508288c0b8e22182c24d6af3 Mon Sep 17 00:00:00 2001 From: Dan Paulat Date: Wed, 20 Nov 2024 19:39:32 -0600 Subject: [PATCH] Lock the level 2 product record mutex before searching for records --- .../scwx/qt/manager/radar_product_manager.cpp | 35 +++++++++++-------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/scwx-qt/source/scwx/qt/manager/radar_product_manager.cpp b/scwx-qt/source/scwx/qt/manager/radar_product_manager.cpp index f6df6237..4659f079 100644 --- a/scwx-qt/source/scwx/qt/manager/radar_product_manager.cpp +++ b/scwx-qt/source/scwx/qt/manager/radar_product_manager.cpp @@ -1164,26 +1164,31 @@ RadarProductManagerImpl::GetLevel2ProductRecords( // Ensure Level 2 product records are updated PopulateLevel2ProductTimes(time); - if (!level2ProductRecords_.empty() && - time == std::chrono::system_clock::time_point {}) { - // If a default-initialized time point is given, return the latest record - recordPtrs.push_back(&(*level2ProductRecords_.rbegin())); - } - else - { - // Get the requested record - auto recordIt = - scwx::util::GetBoundedElementIterator(level2ProductRecords_, time); + std::shared_lock lock {level2ProductRecordMutex_}; - if (recordIt != level2ProductRecords_.cend()) + if (!level2ProductRecords_.empty() && + time == std::chrono::system_clock::time_point {}) { - recordPtrs.push_back(&(*(recordIt))); + // If a default-initialized time point is given, return the latest + // record + recordPtrs.push_back(&(*level2ProductRecords_.rbegin())); + } + else + { + // Get the requested record + auto recordIt = + scwx::util::GetBoundedElementIterator(level2ProductRecords_, time); - // The requested time may be in the previous record, so get that too - if (recordIt != level2ProductRecords_.cbegin()) + if (recordIt != level2ProductRecords_.cend()) { - recordPtrs.push_back(&(*(--recordIt))); + recordPtrs.push_back(&(*(recordIt))); + + // The requested time may be in the previous record, so get that too + if (recordIt != level2ProductRecords_.cbegin()) + { + recordPtrs.push_back(&(*(--recordIt))); + } } } }