From 465b073d771c59e8f6ab65cb073f4f45ac9bcc7f Mon Sep 17 00:00:00 2001 From: f4exb Date: Sun, 23 Apr 2017 04:01:00 +0200 Subject: [PATCH] LimeSDR: suspend/resume all buddies threads before/after open/close --- .../limesdroutput/limesdroutput.cpp | 78 +++++++++---------- .../samplesink/limesdroutput/limesdroutput.h | 2 + .../limesdrinput/limesdrinput.cpp | 76 +++++++++++------- .../samplesource/limesdrinput/limesdrinput.h | 2 + 4 files changed, 88 insertions(+), 70 deletions(-) diff --git a/plugins/samplesink/limesdroutput/limesdroutput.cpp b/plugins/samplesink/limesdroutput/limesdroutput.cpp index e6ad2e389..368891b25 100644 --- a/plugins/samplesink/limesdroutput/limesdroutput.cpp +++ b/plugins/samplesink/limesdroutput/limesdroutput.cpp @@ -44,13 +44,17 @@ LimeSDROutput::LimeSDROutput(DeviceSinkAPI *deviceAPI) : m_firstConfig(true) { m_streamId.handle = 0; + suspendBuddies(); openDevice(); + resumeBuddies(); } LimeSDROutput::~LimeSDROutput() { if (m_running) stop(); + suspendBuddies(); closeDevice(); + resumeBuddies(); } bool LimeSDROutput::openDevice() @@ -94,10 +98,6 @@ bool LimeSDROutput::openDevice() DeviceSinkAPI *buddy = m_deviceAPI->getSinkBuddies()[i]; DeviceLimeSDRShared *buddyShared = (DeviceLimeSDRShared *) buddy->getBuddySharedPtr(); busyChannels[buddyShared->m_channel] = 1; - - if (buddyShared->m_thread) { // suspend Tx buddy's thread for proper stream allocation later - buddyShared->m_thread->stopWork(); - } } std::size_t ch = 0; @@ -131,16 +131,6 @@ bool LimeSDROutput::openDevice() qDebug("LimeSDROutput::openDevice: getting device parameters from Rx buddy"); } - for (int i = 0; i < m_deviceAPI->getSourceBuddies().size(); i++) - { - DeviceSourceAPI *buddy = m_deviceAPI->getSourceBuddies()[i]; - DeviceLimeSDRShared *buddyShared = (DeviceLimeSDRShared *) buddy->getBuddySharedPtr(); - - if (buddyShared->m_thread) { // suspend Rx buddy's thread for proper stream allocation later - buddyShared->m_thread->stopWork(); - } - } - m_deviceShared.m_channel = 0; // take first channel } // There are no buddies then create the first LimeSDR common parameters @@ -189,6 +179,38 @@ bool LimeSDROutput::openDevice() qDebug("LimeSDROutput::start: stream set up on Tx channel %lu", m_deviceShared.m_channel); } + return true; +} + +void LimeSDROutput::suspendBuddies() +{ + // suspend Tx buddy's threads + + for (int i = 0; i < m_deviceAPI->getSinkBuddies().size(); i++) + { + DeviceSinkAPI *buddy = m_deviceAPI->getSinkBuddies()[i]; + DeviceLimeSDRShared *buddyShared = (DeviceLimeSDRShared *) buddy->getBuddySharedPtr(); + + if (buddyShared->m_thread) { + buddyShared->m_thread->stopWork(); + } + } + + // suspend Rx buddy's threads + + for (int i = 0; i < m_deviceAPI->getSourceBuddies().size(); i++) + { + DeviceSourceAPI *buddy = m_deviceAPI->getSourceBuddies()[i]; + DeviceLimeSDRShared *buddyShared = (DeviceLimeSDRShared *) buddy->getBuddySharedPtr(); + + if (buddyShared->m_thread) { + buddyShared->m_thread->stopWork(); + } + } +} + +void LimeSDROutput::resumeBuddies() +{ // resume Tx buddy's threads for (int i = 0; i < m_deviceAPI->getSinkBuddies().size(); i++) @@ -208,12 +230,10 @@ bool LimeSDROutput::openDevice() DeviceSourceAPI *buddy = m_deviceAPI->getSourceBuddies()[i]; DeviceLimeSDRShared *buddyShared = (DeviceLimeSDRShared *) buddy->getBuddySharedPtr(); - if (buddyShared->m_thread) { // suspend Rx buddy's thread for proper stream allocation later + if (buddyShared->m_thread) { buddyShared->m_thread->startWork(); } } - - return true; } void LimeSDROutput::closeDevice() @@ -222,18 +242,6 @@ void LimeSDROutput::closeDevice() return; } - // suspend Tx buddy's threads - - for (int i = 0; i < m_deviceAPI->getSinkBuddies().size(); i++) - { - DeviceSinkAPI *buddy = m_deviceAPI->getSinkBuddies()[i]; - DeviceLimeSDRShared *buddyShared = (DeviceLimeSDRShared *) buddy->getBuddySharedPtr(); - - if (buddyShared->m_thread) { - buddyShared->m_thread->stopWork(); - } - } - // destroy the stream LMS_DestroyStream(m_deviceShared.m_deviceParams->getDevice(), &m_streamId); m_streamId.handle = 0; @@ -247,18 +255,6 @@ void LimeSDROutput::closeDevice() m_deviceShared.m_channel = -1; - // resume Tx buddy's threads - - for (int i = 0; i < m_deviceAPI->getSinkBuddies().size(); i++) - { - const DeviceSinkAPI *buddy = m_deviceAPI->getSinkBuddies()[i]; - DeviceLimeSDRShared *buddyShared = (DeviceLimeSDRShared *) buddy->getBuddySharedPtr(); - - if (buddyShared->m_thread) { - buddyShared->m_thread->startWork(); - } - } - // No buddies so effectively close the device if ((m_deviceAPI->getSourceBuddies().size() == 0) && (m_deviceAPI->getSinkBuddies().size() == 0)) diff --git a/plugins/samplesink/limesdroutput/limesdroutput.h b/plugins/samplesink/limesdroutput/limesdroutput.h index 389a771e2..5626aa741 100644 --- a/plugins/samplesink/limesdroutput/limesdroutput.h +++ b/plugins/samplesink/limesdroutput/limesdroutput.h @@ -225,6 +225,8 @@ private: bool openDevice(); void closeDevice(); + void suspendBuddies(); + void resumeBuddies(); bool applySettings(const LimeSDROutputSettings& settings, bool force); }; diff --git a/plugins/samplesource/limesdrinput/limesdrinput.cpp b/plugins/samplesource/limesdrinput/limesdrinput.cpp index 592c23643..37ca06e0a 100644 --- a/plugins/samplesource/limesdrinput/limesdrinput.cpp +++ b/plugins/samplesource/limesdrinput/limesdrinput.cpp @@ -45,13 +45,17 @@ LimeSDRInput::LimeSDRInput(DeviceSourceAPI *deviceAPI) : m_firstConfig(true) { m_streamId.handle = 0; + suspendBuddies(); openDevice(); + resumeBuddies(); } LimeSDRInput::~LimeSDRInput() { if (m_running) stop(); + suspendBuddies(); closeDevice(); + resumeBuddies(); } bool LimeSDRInput::openDevice() @@ -105,10 +109,6 @@ bool LimeSDRInput::openDevice() DeviceSourceAPI *buddy = m_deviceAPI->getSourceBuddies()[i]; DeviceLimeSDRShared *buddyShared = (DeviceLimeSDRShared *) buddy->getBuddySharedPtr(); busyChannels[buddyShared->m_channel] = 1; - - if (buddyShared->m_thread) { // suspend Rx buddy's thread for proper stream allocation later - buddyShared->m_thread->stopWork(); - } } std::size_t ch = 0; @@ -190,6 +190,38 @@ bool LimeSDRInput::openDevice() qDebug("LimeSDRInput::start: stream set up on Rx channel %lu", m_deviceShared.m_channel); } + return true; +} + +void LimeSDRInput::suspendBuddies() +{ + // suspend Rx buddy's threads + + for (int i = 0; i < m_deviceAPI->getSourceBuddies().size(); i++) + { + DeviceSourceAPI *buddy = m_deviceAPI->getSourceBuddies()[i]; + DeviceLimeSDRShared *buddyShared = (DeviceLimeSDRShared *) buddy->getBuddySharedPtr(); + + if (buddyShared->m_thread) { + buddyShared->m_thread->stopWork(); + } + } + + // suspend Tx buddy's threads + + for (int i = 0; i < m_deviceAPI->getSinkBuddies().size(); i++) + { + DeviceSinkAPI *buddy = m_deviceAPI->getSinkBuddies()[i]; + DeviceLimeSDRShared *buddyShared = (DeviceLimeSDRShared *) buddy->getBuddySharedPtr(); + + if (buddyShared->m_thread) { + buddyShared->m_thread->stopWork(); + } + } +} + +void LimeSDRInput::resumeBuddies() +{ // resume Rx buddy's threads for (int i = 0; i < m_deviceAPI->getSourceBuddies().size(); i++) @@ -202,7 +234,17 @@ bool LimeSDRInput::openDevice() } } - return true; + // resume Tx buddy's threads + + for (int i = 0; i < m_deviceAPI->getSinkBuddies().size(); i++) + { + DeviceSinkAPI *buddy = m_deviceAPI->getSinkBuddies()[i]; + DeviceLimeSDRShared *buddyShared = (DeviceLimeSDRShared *) buddy->getBuddySharedPtr(); + + if (buddyShared->m_thread) { + buddyShared->m_thread->startWork(); + } + } } void LimeSDRInput::closeDevice() @@ -211,18 +253,6 @@ void LimeSDRInput::closeDevice() return; } - // suspend Rx buddy's threads - - for (int i = 0; i < m_deviceAPI->getSourceBuddies().size(); i++) - { - DeviceSourceAPI *buddy = m_deviceAPI->getSourceBuddies()[i]; - DeviceLimeSDRShared *buddyShared = (DeviceLimeSDRShared *) buddy->getBuddySharedPtr(); - - if (buddyShared->m_thread) { - buddyShared->m_thread->stopWork(); - } - } - // destroy the stream LMS_DestroyStream(m_deviceShared.m_deviceParams->getDevice(), &m_streamId); m_streamId.handle = 0; @@ -236,18 +266,6 @@ void LimeSDRInput::closeDevice() m_deviceShared.m_channel = -1; - // resume Rx buddy's threads - - for (int i = 0; i < m_deviceAPI->getSourceBuddies().size(); i++) - { - DeviceSourceAPI *buddy = m_deviceAPI->getSourceBuddies()[i]; - DeviceLimeSDRShared *buddyShared = (DeviceLimeSDRShared *) buddy->getBuddySharedPtr(); - - if (buddyShared->m_thread) { - buddyShared->m_thread->startWork(); - } - } - // No buddies so effectively close the device if ((m_deviceAPI->getSinkBuddies().size() == 0) && (m_deviceAPI->getSourceBuddies().size() == 0)) diff --git a/plugins/samplesource/limesdrinput/limesdrinput.h b/plugins/samplesource/limesdrinput/limesdrinput.h index c1753e4ad..84f6e29ae 100644 --- a/plugins/samplesource/limesdrinput/limesdrinput.h +++ b/plugins/samplesource/limesdrinput/limesdrinput.h @@ -225,6 +225,8 @@ private: bool openDevice(); void closeDevice(); + void suspendBuddies(); + void resumeBuddies(); bool applySettings(const LimeSDRInputSettings& settings, bool force); };