LimeSDR: suspend/resume all buddies threads before/after open/close

This commit is contained in:
f4exb 2017-04-23 04:01:00 +02:00
parent 2369cb62af
commit 465b073d77
4 changed files with 88 additions and 70 deletions

View File

@ -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))

View File

@ -225,6 +225,8 @@ private:
bool openDevice();
void closeDevice();
void suspendBuddies();
void resumeBuddies();
bool applySettings(const LimeSDROutputSettings& settings, bool force);
};

View File

@ -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))

View File

@ -225,6 +225,8 @@ private:
bool openDevice();
void closeDevice();
void suspendBuddies();
void resumeBuddies();
bool applySettings(const LimeSDRInputSettings& settings, bool force);
};