mirror of
https://github.com/cjcliffe/CubicSDR.git
synced 2026-06-07 16:34:50 -04:00
Threads vs. Queues lifetimes, cleanups.
- Ideally Queues must outlive the threads using them, but wasn't done so. Yes, std::shared_ptr them! - Now queues are always valid in the context of the threads using them. - No longer need tedious queues deallocation by the original owner. - Misc cleanups.
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
|
||||
#include <vector>
|
||||
#include <deque>
|
||||
#include <memory>
|
||||
|
||||
//50 ms
|
||||
#define HEARTBEAT_CHECK_PERIOD_MICROS (50 * 1000)
|
||||
@@ -179,10 +180,10 @@ void SDRPostThread::run() {
|
||||
|
||||
// std::cout << "SDR post-processing thread started.." << std::endl;
|
||||
|
||||
iqDataInQueue = static_cast<SDRThreadIQDataQueue*>(getInputQueue("IQDataInput"));
|
||||
iqDataOutQueue = static_cast<DemodulatorThreadInputQueue*>(getOutputQueue("IQDataOutput"));
|
||||
iqVisualQueue = static_cast<DemodulatorThreadInputQueue*>(getOutputQueue("IQVisualDataOutput"));
|
||||
iqActiveDemodVisualQueue = static_cast<DemodulatorThreadInputQueue*>(getOutputQueue("IQActiveDemodVisualDataOutput"));
|
||||
iqDataInQueue = std::static_pointer_cast<SDRThreadIQDataQueue>(getInputQueue("IQDataInput"));
|
||||
iqDataOutQueue = std::static_pointer_cast<DemodulatorThreadInputQueue>(getOutputQueue("IQDataOutput"));
|
||||
iqVisualQueue = std::static_pointer_cast<DemodulatorThreadInputQueue>(getOutputQueue("IQVisualDataOutput"));
|
||||
iqActiveDemodVisualQueue = std::static_pointer_cast<DemodulatorThreadInputQueue>(getOutputQueue("IQActiveDemodVisualDataOutput"));
|
||||
|
||||
while (!stopping) {
|
||||
SDRThreadIQDataPtr data_in;
|
||||
|
||||
@@ -23,10 +23,10 @@ public:
|
||||
void setIQVisualRange(long long frequency, int bandwidth);
|
||||
|
||||
protected:
|
||||
SDRThreadIQDataQueue *iqDataInQueue;
|
||||
DemodulatorThreadInputQueue *iqDataOutQueue;
|
||||
DemodulatorThreadInputQueue *iqVisualQueue;
|
||||
DemodulatorThreadInputQueue *iqActiveDemodVisualQueue;
|
||||
SDRThreadIQDataQueuePtr iqDataInQueue;
|
||||
DemodulatorThreadInputQueuePtr iqDataOutQueue;
|
||||
DemodulatorThreadInputQueuePtr iqVisualQueue;
|
||||
DemodulatorThreadInputQueuePtr iqActiveDemodVisualQueue;
|
||||
|
||||
//protects access to demodulators lists and such
|
||||
std::mutex busy_demod;
|
||||
|
||||
@@ -191,7 +191,7 @@ void SDRThread::assureBufferMinSize(SDRThreadIQData * dataOut, size_t minSize) {
|
||||
//Called in an infinite loop, read SaopySDR device to build
|
||||
// a 'this.numElems' sized batch of samples (SDRThreadIQData) and push it into iqDataOutQueue.
|
||||
//this batch of samples is built to represent 1 frame / TARGET_DISPLAY_FPS.
|
||||
void SDRThread::readStream(SDRThreadIQDataQueue* iqDataOutQueue) {
|
||||
void SDRThread::readStream(SDRThreadIQDataQueuePtr iqDataOutQueue) {
|
||||
int flags;
|
||||
long long timeNs;
|
||||
|
||||
@@ -365,9 +365,10 @@ void SDRThread::readStream(SDRThreadIQDataQueue* iqDataOutQueue) {
|
||||
}
|
||||
|
||||
void SDRThread::readLoop() {
|
||||
SDRThreadIQDataQueue* iqDataOutQueue = static_cast<SDRThreadIQDataQueue*>( getOutputQueue("IQDataOutput"));
|
||||
|
||||
SDRThreadIQDataQueuePtr iqDataOutQueue = std::static_pointer_cast<SDRThreadIQDataQueue>( getOutputQueue("IQDataOutput"));
|
||||
|
||||
if (iqDataOutQueue == NULL) {
|
||||
if (iqDataOutQueue == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -41,12 +41,13 @@ public:
|
||||
};
|
||||
typedef std::shared_ptr<SDRThreadIQData> SDRThreadIQDataPtr;
|
||||
typedef ThreadBlockingQueue<SDRThreadIQDataPtr> SDRThreadIQDataQueue;
|
||||
typedef std::shared_ptr<SDRThreadIQDataQueue> SDRThreadIQDataQueuePtr;
|
||||
|
||||
class SDRThread : public IOThread {
|
||||
private:
|
||||
bool init();
|
||||
void deinit();
|
||||
void readStream(SDRThreadIQDataQueue* iqDataOutQueue);
|
||||
void readStream(SDRThreadIQDataQueuePtr iqDataOutQueue);
|
||||
void readLoop();
|
||||
|
||||
public:
|
||||
|
||||
Reference in New Issue
Block a user