diff --git a/plugins/samplesink/bladerf1output/bladerf1output.cpp b/plugins/samplesink/bladerf1output/bladerf1output.cpp index 1108a8f58..802421d0e 100644 --- a/plugins/samplesink/bladerf1output/bladerf1output.cpp +++ b/plugins/samplesink/bladerf1output/bladerf1output.cpp @@ -392,6 +392,9 @@ bool Bladerf1Output::applySettings(const BladeRF1OutputSettings& settings, const { bool changeSettings; + // Buddy lists can be changed in the GUI thread, but this is also called from start() in the device engine thread + QMutexLocker buddiesLocker(&DeviceAPI::getBuddiesMutex()); + if (!m_deviceAPI->getSourceBuddies().empty()) { DeviceAPI *buddy = m_deviceAPI->getSourceBuddies()[0]; @@ -407,6 +410,8 @@ bool Bladerf1Output::applySettings(const BladeRF1OutputSettings& settings, const changeSettings = true; } + buddiesLocker.unlock(); + if (changeSettings) { if (settings.m_xb200) diff --git a/plugins/samplesink/bladerf2output/bladerf2output.cpp b/plugins/samplesink/bladerf2output/bladerf2output.cpp index b3255ab72..c4ea05718 100644 --- a/plugins/samplesink/bladerf2output/bladerf2output.cpp +++ b/plugins/samplesink/bladerf2output/bladerf2output.cpp @@ -20,6 +20,7 @@ #include #include +#include #include #include @@ -238,6 +239,10 @@ void BladeRF2Output::moveThreadToBuddy() bool BladeRF2Output::start() { + // Buddy lists can be changed in the GUI thread, but are accessed here (and in functions called from here) + // in the device engine thread. Lock before any of our own mutexes, to keep a consistent lock order. + QMutexLocker buddiesLocker(&DeviceAPI::getBuddiesMutex()); + // There is a single thread per physical device (Tx side). This thread is unique and referenced by a unique // buddy in the group of sink buddies associated with this physical device. // @@ -366,6 +371,10 @@ bool BladeRF2Output::start() void BladeRF2Output::stop() { + // Buddy lists can be changed in the GUI thread, but are accessed here (and in functions called from here) + // in the device engine thread. Lock before any of our own mutexes, to keep a consistent lock order. + QMutexLocker buddiesLocker(&DeviceAPI::getBuddiesMutex()); + // This stop method is responsible for managing the thread and channel disabling when the streaming of // a Tx channel is stopped // diff --git a/plugins/samplesink/hackrfoutput/hackrfoutput.cpp b/plugins/samplesink/hackrfoutput/hackrfoutput.cpp index 962f68dcc..3893a441f 100644 --- a/plugins/samplesink/hackrfoutput/hackrfoutput.cpp +++ b/plugins/samplesink/hackrfoutput/hackrfoutput.cpp @@ -388,11 +388,16 @@ bool HackRFOutput::applySettings(const HackRFOutputSettings& settings, const QLi } } - if (m_deviceAPI->getSourceBuddies().size() > 0) { - DeviceAPI *buddy = m_deviceAPI->getSourceBuddies()[0]; - DeviceHackRFShared::MsgSynchronizeSampleRate *sampleRateMsg = DeviceHackRFShared::MsgSynchronizeSampleRate::create(settings.m_devSampleRate); - buddy->getSamplingDeviceInputMessageQueue()->push(sampleRateMsg); + // Buddy lists can be changed in the GUI thread, but this is also called from start() in the device engine thread + QMutexLocker buddiesLocker(&DeviceAPI::getBuddiesMutex()); + + if (m_deviceAPI->getSourceBuddies().size() > 0) + { + DeviceAPI *buddy = m_deviceAPI->getSourceBuddies()[0]; + DeviceHackRFShared::MsgSynchronizeSampleRate *sampleRateMsg = DeviceHackRFShared::MsgSynchronizeSampleRate::create(settings.m_devSampleRate); + buddy->getSamplingDeviceInputMessageQueue()->push(sampleRateMsg); + } } } diff --git a/plugins/samplesink/limesdroutput/limesdroutput.cpp b/plugins/samplesink/limesdroutput/limesdroutput.cpp index f672d7f77..a191044cc 100644 --- a/plugins/samplesink/limesdroutput/limesdroutput.cpp +++ b/plugins/samplesink/limesdroutput/limesdroutput.cpp @@ -380,6 +380,10 @@ void LimeSDROutput::init() bool LimeSDROutput::start() { + // Buddy lists can be changed in the GUI thread, but are accessed here (and in functions called from here) + // in the device engine thread. Lock before any of our own mutexes, to keep a consistent lock order. + QMutexLocker buddiesLocker(&DeviceAPI::getBuddiesMutex()); + QMutexLocker mutexLocker(&m_mutex); if (m_running) { @@ -412,6 +416,10 @@ bool LimeSDROutput::start() void LimeSDROutput::stop() { + // Buddy lists can be changed in the GUI thread, but are accessed here (and in functions called from here) + // in the device engine thread. Lock before any of our own mutexes, to keep a consistent lock order. + QMutexLocker buddiesLocker(&DeviceAPI::getBuddiesMutex()); + if (!m_running) { return; } diff --git a/plugins/samplesink/plutosdroutput/plutosdroutput.cpp b/plugins/samplesink/plutosdroutput/plutosdroutput.cpp index f60e8bba0..c52d45ed8 100644 --- a/plugins/samplesink/plutosdroutput/plutosdroutput.cpp +++ b/plugins/samplesink/plutosdroutput/plutosdroutput.cpp @@ -20,6 +20,7 @@ /////////////////////////////////////////////////////////////////////////////////// #include +#include #include #include @@ -102,6 +103,10 @@ void PlutoSDROutput::init() bool PlutoSDROutput::start() { + // Buddy lists can be changed in the GUI thread, but are accessed here (and in functions called from here) + // in the device engine thread. Lock before any of our own mutexes, to keep a consistent lock order. + QMutexLocker buddiesLocker(&DeviceAPI::getBuddiesMutex()); + QMutexLocker mutexLocker(&m_mutex); if (m_running) { @@ -141,6 +146,10 @@ bool PlutoSDROutput::start() void PlutoSDROutput::stop() { + // Buddy lists can be changed in the GUI thread, but are accessed here (and in functions called from here) + // in the device engine thread. Lock before any of our own mutexes, to keep a consistent lock order. + QMutexLocker buddiesLocker(&DeviceAPI::getBuddiesMutex()); + QMutexLocker mutexLocker(&m_mutex); if (!m_running) { diff --git a/plugins/samplesink/soapysdroutput/soapysdroutput.cpp b/plugins/samplesink/soapysdroutput/soapysdroutput.cpp index e9b0232c7..246a1b465 100644 --- a/plugins/samplesink/soapysdroutput/soapysdroutput.cpp +++ b/plugins/samplesink/soapysdroutput/soapysdroutput.cpp @@ -19,6 +19,7 @@ /////////////////////////////////////////////////////////////////////////////////// #include +#include #include #include @@ -424,6 +425,10 @@ void SoapySDROutput::moveThreadToBuddy() bool SoapySDROutput::start() { + // Buddy lists can be changed in the GUI thread, but are accessed here (and in functions called from here) + // in the device engine thread. Lock before any of our own mutexes, to keep a consistent lock order. + QMutexLocker buddiesLocker(&DeviceAPI::getBuddiesMutex()); + // There is a single thread per physical device (Tx side). This thread is unique and referenced by a unique // buddy in the group of sink buddies associated with this physical device. // @@ -570,6 +575,10 @@ bool SoapySDROutput::start() void SoapySDROutput::stop() { + // Buddy lists can be changed in the GUI thread, but are accessed here (and in functions called from here) + // in the device engine thread. Lock before any of our own mutexes, to keep a consistent lock order. + QMutexLocker buddiesLocker(&DeviceAPI::getBuddiesMutex()); + // This stop method is responsible for managing the thread and channel disabling when the streaming of // a Tx channel is stopped // diff --git a/plugins/samplesink/xtrxoutput/xtrxoutput.cpp b/plugins/samplesink/xtrxoutput/xtrxoutput.cpp index b181c4e2c..e32835ed9 100644 --- a/plugins/samplesink/xtrxoutput/xtrxoutput.cpp +++ b/plugins/samplesink/xtrxoutput/xtrxoutput.cpp @@ -242,6 +242,10 @@ void XTRXOutput::moveThreadToBuddy() bool XTRXOutput::start() { + // Buddy lists can be changed in the GUI thread, but are accessed here (and in functions called from here) + // in the device engine thread. Lock before any of our own mutexes, to keep a consistent lock order. + QMutexLocker buddiesLocker(&DeviceAPI::getBuddiesMutex()); + // There is a single thread per physical device (Tx side). This thread is unique and referenced by a unique // buddy in the group of sink buddies associated with this physical device. // @@ -364,6 +368,10 @@ bool XTRXOutput::start() void XTRXOutput::stop() { + // Buddy lists can be changed in the GUI thread, but are accessed here (and in functions called from here) + // in the device engine thread. Lock before any of our own mutexes, to keep a consistent lock order. + QMutexLocker buddiesLocker(&DeviceAPI::getBuddiesMutex()); + // This stop method is responsible for managing the thread when the streaming of a Rx channel is stopped // // If the thread is currently managing only one channel (SO mode). The thread can be just stopped and deleted. diff --git a/plugins/samplesource/bladerf1input/bladerf1input.cpp b/plugins/samplesource/bladerf1input/bladerf1input.cpp index 83157a59b..59457426e 100644 --- a/plugins/samplesource/bladerf1input/bladerf1input.cpp +++ b/plugins/samplesource/bladerf1input/bladerf1input.cpp @@ -365,6 +365,9 @@ bool Bladerf1Input::applySettings(const BladeRF1InputSettings& settings, const Q { bool changeSettings; + // Buddy lists can be changed in the GUI thread, but this is also called from start() in the device engine thread + QMutexLocker buddiesLocker(&DeviceAPI::getBuddiesMutex()); + if (!m_deviceAPI->getSinkBuddies().empty()) { DeviceAPI *buddy = m_deviceAPI->getSinkBuddies()[0]; @@ -380,6 +383,8 @@ bool Bladerf1Input::applySettings(const BladeRF1InputSettings& settings, const Q changeSettings = true; } + buddiesLocker.unlock(); + if (changeSettings) { if (settings.m_xb200) diff --git a/plugins/samplesource/bladerf2input/bladerf2input.cpp b/plugins/samplesource/bladerf2input/bladerf2input.cpp index d0968e8cd..5435b327b 100644 --- a/plugins/samplesource/bladerf2input/bladerf2input.cpp +++ b/plugins/samplesource/bladerf2input/bladerf2input.cpp @@ -17,6 +17,7 @@ /////////////////////////////////////////////////////////////////////////////////// #include +#include #include #include @@ -261,6 +262,10 @@ void BladeRF2Input::moveThreadToBuddy() bool BladeRF2Input::start() { + // Buddy lists can be changed in the GUI thread, but are accessed here (and in functions called from here) + // in the device engine thread. Lock before any of our own mutexes, to keep a consistent lock order. + QMutexLocker buddiesLocker(&DeviceAPI::getBuddiesMutex()); + // There is a single thread per physical device (Rx side). This thread is unique and referenced by a unique // buddy in the group of source buddies associated with this physical device. // @@ -399,6 +404,10 @@ bool BladeRF2Input::start() void BladeRF2Input::stop() { + // Buddy lists can be changed in the GUI thread, but are accessed here (and in functions called from here) + // in the device engine thread. Lock before any of our own mutexes, to keep a consistent lock order. + QMutexLocker buddiesLocker(&DeviceAPI::getBuddiesMutex()); + // This stop method is responsible for managing the thread and channel disabling when the streaming of // a Rx channel is stopped // diff --git a/plugins/samplesource/hackrfinput/hackrfinput.cpp b/plugins/samplesource/hackrfinput/hackrfinput.cpp index 36b0117b8..b370929fe 100644 --- a/plugins/samplesource/hackrfinput/hackrfinput.cpp +++ b/plugins/samplesource/hackrfinput/hackrfinput.cpp @@ -378,11 +378,16 @@ bool HackRFInput::applySettings(const HackRFInputSettings& settings, const QList } } - if (m_deviceAPI->getSourceBuddies().size() > 0) { - DeviceAPI *buddy = m_deviceAPI->getSourceBuddies()[0]; - DeviceHackRFShared::MsgSynchronizeSampleRate *sampleRateMsg = DeviceHackRFShared::MsgSynchronizeSampleRate::create(settings.m_devSampleRate); - buddy->getSamplingDeviceInputMessageQueue()->push(sampleRateMsg); + // Buddy lists can be changed in the GUI thread, but this is also called from start() in the device engine thread + QMutexLocker buddiesLocker(&DeviceAPI::getBuddiesMutex()); + + if (m_deviceAPI->getSourceBuddies().size() > 0) + { + DeviceAPI *buddy = m_deviceAPI->getSourceBuddies()[0]; + DeviceHackRFShared::MsgSynchronizeSampleRate *sampleRateMsg = DeviceHackRFShared::MsgSynchronizeSampleRate::create(settings.m_devSampleRate); + buddy->getSamplingDeviceInputMessageQueue()->push(sampleRateMsg); + } } } diff --git a/plugins/samplesource/limesdrinput/limesdrinput.cpp b/plugins/samplesource/limesdrinput/limesdrinput.cpp index 5b50c571a..5612a6eaf 100644 --- a/plugins/samplesource/limesdrinput/limesdrinput.cpp +++ b/plugins/samplesource/limesdrinput/limesdrinput.cpp @@ -409,6 +409,10 @@ void LimeSDRInput::init() bool LimeSDRInput::start() { + // Buddy lists can be changed in the GUI thread, but are accessed here (and in functions called from here) + // in the device engine thread. Lock before any of our own mutexes, to keep a consistent lock order. + QMutexLocker buddiesLocker(&DeviceAPI::getBuddiesMutex()); + QMutexLocker mutexLocker(&m_mutex); if (m_running) { @@ -442,6 +446,10 @@ bool LimeSDRInput::start() void LimeSDRInput::stop() { + // Buddy lists can be changed in the GUI thread, but are accessed here (and in functions called from here) + // in the device engine thread. Lock before any of our own mutexes, to keep a consistent lock order. + QMutexLocker buddiesLocker(&DeviceAPI::getBuddiesMutex()); + QMutexLocker mutexLocker(&m_mutex); if (!m_running) { diff --git a/plugins/samplesource/plutosdrinput/plutosdrinput.cpp b/plugins/samplesource/plutosdrinput/plutosdrinput.cpp index 9bfee3305..87633906a 100644 --- a/plugins/samplesource/plutosdrinput/plutosdrinput.cpp +++ b/plugins/samplesource/plutosdrinput/plutosdrinput.cpp @@ -20,6 +20,7 @@ /////////////////////////////////////////////////////////////////////////////////// #include +#include #include #include @@ -102,6 +103,10 @@ void PlutoSDRInput::init() bool PlutoSDRInput::start() { + // Buddy lists can be changed in the GUI thread, but are accessed here (and in functions called from here) + // in the device engine thread. Lock before any of our own mutexes, to keep a consistent lock order. + QMutexLocker buddiesLocker(&DeviceAPI::getBuddiesMutex()); + QMutexLocker mutexLocker(&m_mutex); if (m_running) { @@ -142,6 +147,10 @@ bool PlutoSDRInput::start() void PlutoSDRInput::stop() { + // Buddy lists can be changed in the GUI thread, but are accessed here (and in functions called from here) + // in the device engine thread. Lock before any of our own mutexes, to keep a consistent lock order. + QMutexLocker buddiesLocker(&DeviceAPI::getBuddiesMutex()); + QMutexLocker mutexLocker(&m_mutex); if (!m_running) { diff --git a/plugins/samplesource/soapysdrinput/soapysdrinput.cpp b/plugins/samplesource/soapysdrinput/soapysdrinput.cpp index 5caf22cd9..c5a7e42e4 100644 --- a/plugins/samplesource/soapysdrinput/soapysdrinput.cpp +++ b/plugins/samplesource/soapysdrinput/soapysdrinput.cpp @@ -19,6 +19,7 @@ /////////////////////////////////////////////////////////////////////////////////// #include +#include #include #include @@ -448,6 +449,10 @@ void SoapySDRInput::moveThreadToBuddy() bool SoapySDRInput::start() { + // Buddy lists can be changed in the GUI thread, but are accessed here (and in functions called from here) + // in the device engine thread. Lock before any of our own mutexes, to keep a consistent lock order. + QMutexLocker buddiesLocker(&DeviceAPI::getBuddiesMutex()); + // There is a single thread per physical device (Rx side). This thread is unique and referenced by a unique // buddy in the group of source buddies associated with this physical device. // @@ -582,6 +587,10 @@ bool SoapySDRInput::start() void SoapySDRInput::stop() { + // Buddy lists can be changed in the GUI thread, but are accessed here (and in functions called from here) + // in the device engine thread. Lock before any of our own mutexes, to keep a consistent lock order. + QMutexLocker buddiesLocker(&DeviceAPI::getBuddiesMutex()); + // This stop method is responsible for managing the thread and channel disabling when the streaming of // a Rx channel is stopped // diff --git a/plugins/samplesource/xtrxinput/xtrxinput.cpp b/plugins/samplesource/xtrxinput/xtrxinput.cpp index 7e8aa75b7..6b324eab8 100644 --- a/plugins/samplesource/xtrxinput/xtrxinput.cpp +++ b/plugins/samplesource/xtrxinput/xtrxinput.cpp @@ -252,6 +252,10 @@ void XTRXInput::moveThreadToBuddy() bool XTRXInput::start() { + // Buddy lists can be changed in the GUI thread, but are accessed here (and in functions called from here) + // in the device engine thread. Lock before any of our own mutexes, to keep a consistent lock order. + QMutexLocker buddiesLocker(&DeviceAPI::getBuddiesMutex()); + // There is a single thread per physical device (Rx side). This thread is unique and referenced by a unique // buddy in the group of source buddies associated with this physical device. // @@ -375,6 +379,10 @@ bool XTRXInput::start() void XTRXInput::stop() { + // Buddy lists can be changed in the GUI thread, but are accessed here (and in functions called from here) + // in the device engine thread. Lock before any of our own mutexes, to keep a consistent lock order. + QMutexLocker buddiesLocker(&DeviceAPI::getBuddiesMutex()); + // This stop method is responsible for managing the thread when the streaming of a Rx channel is stopped // // If the thread is currently managing only one channel (SI mode). The thread can be just stopped and deleted.