From b8174714ffdb0340ae197c2375ef076da6d8c3c1 Mon Sep 17 00:00:00 2001 From: f4exb Date: Thu, 20 Apr 2017 00:01:11 +0200 Subject: [PATCH] LimeSDR: suspend buddies threads if changing critical values --- devices/limesdr/devicelimesdrshared.h | 4 +- .../limesdrinput/limesdrinput.cpp | 167 ++++++++++++++++-- 2 files changed, 158 insertions(+), 13 deletions(-) diff --git a/devices/limesdr/devicelimesdrshared.h b/devices/limesdr/devicelimesdrshared.h index ae8a79ce9..23050c269 100644 --- a/devices/limesdr/devicelimesdrshared.h +++ b/devices/limesdr/devicelimesdrshared.h @@ -27,10 +27,12 @@ struct DeviceLimeSDRShared { DeviceLimeSDRParams *m_deviceParams; //!< unique hardware device parameters std::size_t m_channel; //!< logical device channel number (-1 if none) + void *m_thread; //!< anonymous pointer that will hold the thread address if started else 0 DeviceLimeSDRShared() : m_deviceParams(0), - m_channel(-1) + m_channel(-1), + m_thread(0) {} ~DeviceLimeSDRShared() diff --git a/plugins/samplesource/limesdrinput/limesdrinput.cpp b/plugins/samplesource/limesdrinput/limesdrinput.cpp index f03b75ff0..eae8da46e 100644 --- a/plugins/samplesource/limesdrinput/limesdrinput.cpp +++ b/plugins/samplesource/limesdrinput/limesdrinput.cpp @@ -240,6 +240,7 @@ bool LimeSDRInput::start() m_limeSDRInputThread->startWork(); + m_deviceShared.m_thread = (void *) m_limeSDRInputThread; m_running = true; return true; @@ -254,6 +255,7 @@ void LimeSDRInput::stop() m_limeSDRInputThread = 0; } + m_deviceShared.m_thread = 0; m_running = false; } @@ -393,23 +395,105 @@ bool LimeSDRInput::applySettings(const LimeSDRInputSettings& settings, bool forc bool forwardChangeOwnDSP = false; bool forwardChangeRxDSP = false; bool forwardChangeAllDSP = false; + bool suspendOwnThread = false; + bool suspendRxThread = false; + bool suspendAllThread = false; bool doCalibration = false; - bool threadStopped = false; // QMutexLocker mutexLocker(&m_mutex); - if ((m_deviceShared.m_deviceParams->getDevice() != 0) && m_limeSDRInputThread && - ((m_settings.m_gain != settings.m_gain) || - (m_settings.m_devSampleRate != settings.m_devSampleRate) || - (m_settings.m_log2HardDecim != settings.m_log2HardDecim) || + // determine if buddies threads or own thread need to be suspended + + if ((m_settings.m_devSampleRate != settings.m_devSampleRate) || force) + { + suspendAllThread = true; + } + + if ((m_settings.m_log2HardDecim != settings.m_log2HardDecim) || + (m_settings.m_centerFrequency != settings.m_centerFrequency) || force) + { + suspendRxThread = true; + } + + if ((m_settings.m_gain != settings.m_gain) || (m_settings.m_lpfBW != settings.m_lpfBW) || (m_settings.m_lpfFIRBW != settings.m_lpfFIRBW) || - (m_settings.m_lpfFIREnable != settings.m_lpfFIREnable) || - (m_settings.m_centerFrequency != settings.m_centerFrequency) || force)) + (m_settings.m_lpfFIREnable != settings.m_lpfFIREnable) || force) { - m_limeSDRInputThread->stopWork(); - threadStopped = true; + suspendOwnThread = true; } + // suspend buddies threads or own thread + + if (suspendAllThread) + { + const std::vector& sourceBuddies = m_deviceAPI->getSourceBuddies(); + std::vector::const_iterator itSource = sourceBuddies.begin(); + + for (; itSource != sourceBuddies.end(); ++itSource) + { + DeviceLimeSDRShared *buddySharedPtr = (DeviceLimeSDRShared *) (*itSource)->getBuddySharedPtr(); + if (buddySharedPtr->m_thread) + { + ((LimeSDRInputThread *) buddySharedPtr->m_thread)->stopWork(); + } + } + + const std::vector& sinkBuddies = m_deviceAPI->getSinkBuddies(); + std::vector::const_iterator itSink = sinkBuddies.begin(); + + for (; itSink != sinkBuddies.end(); ++itSink) + { + DeviceLimeSDRShared *buddySharedPtr = (DeviceLimeSDRShared *) (*itSink)->getBuddySharedPtr(); + if (buddySharedPtr->m_thread) + { + ((LimeSDRInputThread *) buddySharedPtr->m_thread)->stopWork(); + } + } + + if (m_limeSDRInputThread) { + m_limeSDRInputThread->stopWork(); + } + } + else if (suspendRxThread) + { + const std::vector& sourceBuddies = m_deviceAPI->getSourceBuddies(); + std::vector::const_iterator itSource = sourceBuddies.begin(); + + for (; itSource != sourceBuddies.end(); ++itSource) + { + DeviceLimeSDRShared *buddySharedPtr = (DeviceLimeSDRShared *) (*itSource)->getBuddySharedPtr(); + if (buddySharedPtr->m_thread) + { + ((LimeSDRInputThread *) buddySharedPtr->m_thread)->stopWork(); + } + } + + if (m_limeSDRInputThread) { + m_limeSDRInputThread->stopWork(); + } + } + else if (suspendOwnThread) + { + if (m_limeSDRInputThread) { + m_limeSDRInputThread->stopWork(); + } + } + +// if ((m_deviceShared.m_deviceParams->getDevice() != 0) && m_limeSDRInputThread && +// ((m_settings.m_gain != settings.m_gain) || +// (m_settings.m_devSampleRate != settings.m_devSampleRate) || +// (m_settings.m_log2HardDecim != settings.m_log2HardDecim) || +// (m_settings.m_lpfBW != settings.m_lpfBW) || +// (m_settings.m_lpfFIRBW != settings.m_lpfFIRBW) || +// (m_settings.m_lpfFIREnable != settings.m_lpfFIREnable) || +// (m_settings.m_centerFrequency != settings.m_centerFrequency) || force)) +// { +// m_limeSDRInputThread->stopWork(); +// threadStopped = true; +// } + + // apply settings + if ((m_settings.m_dcBlock != settings.m_dcBlock) || force) { m_settings.m_dcBlock = settings.m_dcBlock; @@ -574,11 +658,70 @@ bool LimeSDRInput::applySettings(const LimeSDRInputSettings& settings, bool forc } } - if (threadStopped) +// if (threadStopped) +// { +// m_limeSDRInputThread->startWork(); +// threadStopped = false; +// } + + // resume buddies threads or own thread + + if (suspendAllThread) { - m_limeSDRInputThread->startWork(); - threadStopped = false; + const std::vector& sourceBuddies = m_deviceAPI->getSourceBuddies(); + std::vector::const_iterator itSource = sourceBuddies.begin(); + + for (; itSource != sourceBuddies.end(); ++itSource) + { + DeviceLimeSDRShared *buddySharedPtr = (DeviceLimeSDRShared *) (*itSource)->getBuddySharedPtr(); + if (buddySharedPtr->m_thread) + { + ((LimeSDRInputThread *) buddySharedPtr->m_thread)->startWork(); + } + } + + const std::vector& sinkBuddies = m_deviceAPI->getSinkBuddies(); + std::vector::const_iterator itSink = sinkBuddies.begin(); + + for (; itSink != sinkBuddies.end(); ++itSink) + { + DeviceLimeSDRShared *buddySharedPtr = (DeviceLimeSDRShared *) (*itSink)->getBuddySharedPtr(); + if (buddySharedPtr->m_thread) + { + ((LimeSDRInputThread *) buddySharedPtr->m_thread)->startWork(); + } + } + + if (m_limeSDRInputThread) { + m_limeSDRInputThread->startWork(); + } } + else if (suspendRxThread) + { + const std::vector& sourceBuddies = m_deviceAPI->getSourceBuddies(); + std::vector::const_iterator itSource = sourceBuddies.begin(); + + for (; itSource != sourceBuddies.end(); ++itSource) + { + DeviceLimeSDRShared *buddySharedPtr = (DeviceLimeSDRShared *) (*itSource)->getBuddySharedPtr(); + if (buddySharedPtr->m_thread) + { + ((LimeSDRInputThread *) buddySharedPtr->m_thread)->startWork(); + } + } + + if (m_limeSDRInputThread) { + m_limeSDRInputThread->startWork(); + } + } + else if (suspendOwnThread) + { + if (m_limeSDRInputThread) { + m_limeSDRInputThread->startWork(); + } + } + + // forward changes to buddies or oneself if (forwardChangeAllDSP) {