BladeRF2 input: do not re-create the thread if there are no more channels active

This commit is contained in:
f4exb 2018-09-27 06:37:31 +02:00
parent d5a33b7448
commit 7078cd868e
2 changed files with 25 additions and 8 deletions

View File

@ -385,7 +385,7 @@ void BladeRF2Input::stop()
// //
// If the thread is currently managing many channels (MI mode) and we are removing the last channel. The transition // If the thread is currently managing many channels (MI mode) and we are removing the last channel. The transition
// from MI to SI or reduction of MI size is handled by stopping the thread, deleting it and creating a new one // from MI to SI or reduction of MI size is handled by stopping the thread, deleting it and creating a new one
// with one channel less. Then the channel is closed (disabled). // with one channel less if (and only if) there is still a channel active.
// //
// If the thread is currently managing many channels (MI mode) but the channel being stopped is not the last // If the thread is currently managing many channels (MI mode) but the channel being stopped is not the last
// channel then the FIFO reference is simply removed from the thread so that it will not stream into this FIFO // channel then the FIFO reference is simply removed from the thread so that it will not stream into this FIFO
@ -430,23 +430,34 @@ void BladeRF2Input::stop()
SampleSinkFifo **fifos = new SampleSinkFifo*[nbOriginalChannels-1]; SampleSinkFifo **fifos = new SampleSinkFifo*[nbOriginalChannels-1];
unsigned int *log2Decims = new unsigned int[nbOriginalChannels-1]; unsigned int *log2Decims = new unsigned int[nbOriginalChannels-1];
int *fcPoss = new int[nbOriginalChannels-1]; int *fcPoss = new int[nbOriginalChannels-1];
bool stillActiveFIFO = false;
for (int i = 0; i < nbOriginalChannels-1; i++) // save original FIFO references for (int i = 0; i < nbOriginalChannels-1; i++) // save original FIFO references
{ {
fifos[i] = bladerf2InputThread->getFifo(i); fifos[i] = bladerf2InputThread->getFifo(i);
stillActiveFIFO = stillActiveFIFO || (bladerf2InputThread->getFifo(i) != 0);
log2Decims[i] = bladerf2InputThread->getLog2Decimation(i); log2Decims[i] = bladerf2InputThread->getLog2Decimation(i);
fcPoss[i] = bladerf2InputThread->getFcPos(i); fcPoss[i] = bladerf2InputThread->getFcPos(i);
} }
delete bladerf2InputThread; delete bladerf2InputThread;
bladerf2InputThread = new BladeRF2InputThread(m_deviceShared.m_dev->getDev(), nbOriginalChannels-1); m_thread = 0;
m_thread = bladerf2InputThread; // take ownership
for (int i = 0; i < nbOriginalChannels-1; i++) // restore original FIFO references if (stillActiveFIFO)
{ {
bladerf2InputThread->setFifo(i, fifos[i]); bladerf2InputThread = new BladeRF2InputThread(m_deviceShared.m_dev->getDev(), nbOriginalChannels-1);
bladerf2InputThread->setLog2Decimation(i, log2Decims[i]); m_thread = bladerf2InputThread; // take ownership
bladerf2InputThread->setFcPos(i, fcPoss[i]);
for (int i = 0; i < nbOriginalChannels-1; i++) // restore original FIFO references
{
bladerf2InputThread->setFifo(i, fifos[i]);
bladerf2InputThread->setLog2Decimation(i, log2Decims[i]);
bladerf2InputThread->setFcPos(i, fcPoss[i]);
}
}
else
{
qDebug("BladeRF2Input::stop: do not re-create thread as there are no more FIFOs active");
} }
// remove old thread address from buddies (reset in all buddies) // remove old thread address from buddies (reset in all buddies)
@ -458,7 +469,10 @@ void BladeRF2Input::stop()
} }
m_deviceShared.m_dev->closeRx(requestedChannel); // close the last channel m_deviceShared.m_dev->closeRx(requestedChannel); // close the last channel
bladerf2InputThread->startWork();
if (stillActiveFIFO) {
bladerf2InputThread->startWork();
}
} }
else // remove channel from existing thread else // remove channel from existing thread
{ {

View File

@ -22,6 +22,7 @@ BladeRF2InputThread::BladeRF2InputThread(struct bladerf* dev, unsigned int nbRxC
m_dev(dev), m_dev(dev),
m_nbChannels(nbRxChannels) m_nbChannels(nbRxChannels)
{ {
qDebug("BladeRF2InputThread::BladeRF2InputThread");
m_channels = new Channel[nbRxChannels]; m_channels = new Channel[nbRxChannels];
for (unsigned int i = 0; i < nbRxChannels; i++) { for (unsigned int i = 0; i < nbRxChannels; i++) {
@ -86,6 +87,7 @@ void BladeRF2InputThread::run()
} }
else else
{ {
qDebug("BladeRF2InputThread::run: start running loop");
while (m_running) while (m_running)
{ {
res = bladerf_sync_rx(m_dev, m_buf, DeviceBladeRF2::blockSize, NULL, 10000); res = bladerf_sync_rx(m_dev, m_buf, DeviceBladeRF2::blockSize, NULL, 10000);
@ -102,6 +104,7 @@ void BladeRF2InputThread::run()
callbackSI(m_buf, 2*DeviceBladeRF2::blockSize); callbackSI(m_buf, 2*DeviceBladeRF2::blockSize);
} }
} }
qDebug("BladeRF2InputThread::run: stop running loop");
} }
} }
else else