Avoid uncommon race condition with computing a sweep during radar product view destruction

This commit is contained in:
Dan Paulat 2023-11-05 07:52:27 -06:00
parent f56d7f14bf
commit bb2d3a92ad
8 changed files with 37 additions and 7 deletions

View file

@ -72,7 +72,7 @@ public:
SetProduct(product); SetProduct(product);
} }
~Level2ProductViewImpl() = default; ~Level2ProductViewImpl() { threadPool_.join(); };
void void
ComputeCoordinates(std::shared_ptr<wsr88d::rda::ElevationScan> radarData); ComputeCoordinates(std::shared_ptr<wsr88d::rda::ElevationScan> radarData);
@ -82,6 +82,8 @@ public:
Level2ProductView* self_; Level2ProductView* self_;
boost::asio::thread_pool threadPool_ {1u};
common::Level2Product product_; common::Level2Product product_;
wsr88d::rda::DataBlockType dataBlockType_; wsr88d::rda::DataBlockType dataBlockType_;
@ -156,6 +158,11 @@ void Level2ProductView::DisconnectRadarProductManager()
nullptr); nullptr);
} }
boost::asio::thread_pool& Level2ProductView::thread_pool()
{
return p->threadPool_;
}
const std::vector<boost::gil::rgba8_pixel_t>& const std::vector<boost::gil::rgba8_pixel_t>&
Level2ProductView::color_table() const Level2ProductView::color_table() const
{ {

View file

@ -53,6 +53,8 @@ public:
std::shared_ptr<manager::RadarProductManager> radarProductManager); std::shared_ptr<manager::RadarProductManager> radarProductManager);
protected: protected:
boost::asio::thread_pool& thread_pool() override;
void ConnectRadarProductManager() override; void ConnectRadarProductManager() override;
void DisconnectRadarProductManager() override; void DisconnectRadarProductManager() override;
void UpdateColorTable() override; void UpdateColorTable() override;

View file

@ -41,13 +41,15 @@ public:
{ {
coordinates_.resize(kMaxCoordinates_); coordinates_.resize(kMaxCoordinates_);
} }
~Level3RadialViewImpl() = default; ~Level3RadialViewImpl() { threadPool_.join(); };
void ComputeCoordinates( void ComputeCoordinates(
std::shared_ptr<wsr88d::rpg::GenericRadialDataPacket> radialData); std::shared_ptr<wsr88d::rpg::GenericRadialDataPacket> radialData);
Level3RadialView* self_; Level3RadialView* self_;
boost::asio::thread_pool threadPool_ {1u};
std::vector<float> coordinates_ {}; std::vector<float> coordinates_ {};
std::vector<float> vertices_ {}; std::vector<float> vertices_ {};
std::vector<std::uint8_t> dataMoments8_ {}; std::vector<std::uint8_t> dataMoments8_ {};
@ -73,6 +75,11 @@ Level3RadialView::~Level3RadialView()
std::unique_lock sweepLock {sweep_mutex()}; std::unique_lock sweepLock {sweep_mutex()};
} }
boost::asio::thread_pool& Level3RadialView::thread_pool()
{
return p->threadPool_;
}
float Level3RadialView::range() const float Level3RadialView::range() const
{ {
return p->range_; return p->range_;

View file

@ -37,6 +37,9 @@ public:
Create(const std::string& product, Create(const std::string& product,
std::shared_ptr<manager::RadarProductManager> radarProductManager); std::shared_ptr<manager::RadarProductManager> radarProductManager);
protected:
boost::asio::thread_pool& thread_pool() override;
protected slots: protected slots:
void ComputeSweep() override; void ComputeSweep() override;

View file

@ -30,7 +30,9 @@ public:
latitude_ {}, longitude_ {}, range_ {}, vcp_ {}, sweepTime_ {} latitude_ {}, longitude_ {}, range_ {}, vcp_ {}, sweepTime_ {}
{ {
} }
~Level3RasterViewImpl() = default; ~Level3RasterViewImpl() { threadPool_.join(); };
boost::asio::thread_pool threadPool_ {1u};
std::vector<float> vertices_; std::vector<float> vertices_;
std::vector<uint8_t> dataMoments8_; std::vector<uint8_t> dataMoments8_;
@ -56,6 +58,11 @@ Level3RasterView::~Level3RasterView()
std::unique_lock sweepLock {sweep_mutex()}; std::unique_lock sweepLock {sweep_mutex()};
} }
boost::asio::thread_pool& Level3RasterView::thread_pool()
{
return p->threadPool_;
}
float Level3RasterView::range() const float Level3RasterView::range() const
{ {
return p->range_; return p->range_;

View file

@ -37,6 +37,9 @@ public:
Create(const std::string& product, Create(const std::string& product,
std::shared_ptr<manager::RadarProductManager> radarProductManager); std::shared_ptr<manager::RadarProductManager> radarProductManager);
protected:
boost::asio::thread_pool& thread_pool() override;
protected slots: protected slots:
void ComputeSweep() override; void ComputeSweep() override;

View file

@ -35,9 +35,7 @@ public:
radarProductManager_ {radarProductManager} radarProductManager_ {radarProductManager}
{ {
} }
~RadarProductViewImpl() { threadPool_.join(); } ~RadarProductViewImpl() {}
boost::asio::thread_pool threadPool_ {1};
bool initialized_; bool initialized_;
std::mutex sweepMutex_; std::mutex sweepMutex_;
@ -123,7 +121,7 @@ void RadarProductView::SelectTime(std::chrono::system_clock::time_point time)
void RadarProductView::Update() void RadarProductView::Update()
{ {
boost::asio::post(p->threadPool_, [this]() { ComputeSweep(); }); boost::asio::post(thread_pool(), [this]() { ComputeSweep(); });
} }
bool RadarProductView::IsInitialized() const bool RadarProductView::IsInitialized() const

View file

@ -11,6 +11,7 @@
#include <vector> #include <vector>
#include <QObject> #include <QObject>
#include <boost/asio/thread_pool.hpp>
namespace scwx namespace scwx
{ {
@ -66,6 +67,8 @@ public:
std::chrono::system_clock::time_point GetSelectedTime() const; std::chrono::system_clock::time_point GetSelectedTime() const;
protected: protected:
virtual boost::asio::thread_pool& thread_pool() = 0;
virtual void ConnectRadarProductManager() = 0; virtual void ConnectRadarProductManager() = 0;
virtual void DisconnectRadarProductManager() = 0; virtual void DisconnectRadarProductManager() = 0;
virtual void UpdateColorTable() = 0; virtual void UpdateColorTable() = 0;