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:
vsonnier
2017-08-13 18:49:47 +02:00
parent 98c7c30aee
commit c64baab99d
31 changed files with 162 additions and 153 deletions
+5 -4
View File
@@ -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;
+4 -4
View File
@@ -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;
+4 -3
View File
@@ -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;
}
+2 -1
View File
@@ -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: