From fcaf22418de96e7053988ad7f612b0bde5d9bf0e Mon Sep 17 00:00:00 2001 From: f4exb Date: Tue, 25 Sep 2018 14:31:57 +0200 Subject: [PATCH] BladerRF2 input support. Transfer thread ownership before closing the source if it has the allocated thread --- .../bladerf2input/bladerf2input.cpp | 27 ++++++++++++++++--- .../bladerf2input/bladerf2input.h | 3 ++- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/plugins/samplesource/bladerf2input/bladerf2input.cpp b/plugins/samplesource/bladerf2input/bladerf2input.cpp index 66e6b45fc..7abdc14e4 100644 --- a/plugins/samplesource/bladerf2input/bladerf2input.cpp +++ b/plugins/samplesource/bladerf2input/bladerf2input.cpp @@ -204,6 +204,10 @@ void BladeRF2Input::closeDevice() stop(); } + if (m_thread) { // stills own the thread => transfer to a buddy + moveThreadToBuddy(); + } + m_deviceShared.m_channel = -1; m_deviceShared.m_source = 0; @@ -254,6 +258,23 @@ BladeRF2InputThread *BladeRF2Input::findThread() } } +void BladeRF2Input::moveThreadToBuddy() +{ + const std::vector& sourceBuddies = m_deviceAPI->getSourceBuddies(); + std::vector::const_iterator it = sourceBuddies.begin(); + + for (; it != sourceBuddies.end(); ++it) + { + BladeRF2Input *buddySource = ((DeviceBladeRF2Shared*) (*it)->getBuddySharedPtr())->m_source; + + if (buddySource) + { + buddySource->setThread(m_thread); + m_thread = 0; // zero for others + } + } +} + bool BladeRF2Input::start() { if (!m_deviceShared.m_dev) @@ -299,7 +320,7 @@ bool BladeRF2Input::start() std::vector::const_iterator it = sourceBuddies.begin(); for (; it != sourceBuddies.end(); ++it) { - ((DeviceBladeRF2Shared*) (*it)->getBuddySharedPtr())->m_source->resetThread(); + ((DeviceBladeRF2Shared*) (*it)->getBuddySharedPtr())->m_source->setThread(0); } needsStart = true; @@ -354,7 +375,7 @@ void BladeRF2Input::stop() std::vector::const_iterator it = sourceBuddies.begin(); for (; it != sourceBuddies.end(); ++it) { - ((DeviceBladeRF2Shared*) (*it)->getBuddySharedPtr())->m_source->resetThread(); + ((DeviceBladeRF2Shared*) (*it)->getBuddySharedPtr())->m_source->setThread(0); } } else if (m_deviceShared.m_channel == nbOriginalChannels - 1) // remove last MI channel => reduce by deleting and re-creating the thread @@ -387,7 +408,7 @@ void BladeRF2Input::stop() std::vector::const_iterator it = sourceBuddies.begin(); for (; it != sourceBuddies.end(); ++it) { - ((DeviceBladeRF2Shared*) (*it)->getBuddySharedPtr())->m_source->resetThread(); + ((DeviceBladeRF2Shared*) (*it)->getBuddySharedPtr())->m_source->setThread(0); } bladerf2InputThread->startWork(); diff --git a/plugins/samplesource/bladerf2input/bladerf2input.h b/plugins/samplesource/bladerf2input/bladerf2input.h index 9448cdf2b..f2d8486ba 100644 --- a/plugins/samplesource/bladerf2input/bladerf2input.h +++ b/plugins/samplesource/bladerf2input/bladerf2input.h @@ -101,7 +101,7 @@ public: virtual bool start(); virtual void stop(); BladeRF2InputThread *getThread() { return m_thread; } - void resetThread() { m_thread = 0; } + void setThread(BladeRF2InputThread *thread) { m_thread = thread; } virtual QByteArray serialize() const; virtual bool deserialize(const QByteArray& data); @@ -155,6 +155,7 @@ private: bool openDevice(); void closeDevice(); BladeRF2InputThread *findThread(); + void moveThreadToBuddy(); bool applySettings(const BladeRF2InputSettings& settings, bool force = false); void webapiFormatDeviceSettings(SWGSDRangel::SWGDeviceSettings& response, const BladeRF2InputSettings& settings); void webapiFormatDeviceReport(SWGSDRangel::SWGDeviceReport& response);