mirror of
https://github.com/cjcliffe/CubicSDR.git
synced 2026-06-01 21:54:39 -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:
@@ -34,7 +34,7 @@ wxEND_EVENT_TABLE()
|
||||
ScopeCanvas::ScopeCanvas(wxWindow *parent, std::vector<int> dispAttrs) : InteractiveCanvas(parent, dispAttrs), ppmMode(false), ctr(0), ctrTarget(0), dragAccel(0), helpTip("") {
|
||||
|
||||
glContext = new ScopeContext(this, &wxGetApp().GetContext(this));
|
||||
inputData.set_max_num_items(2);
|
||||
inputData->set_max_num_items(2);
|
||||
bgPanel.setFill(GLPanel::GLPANEL_FILL_GRAD_Y);
|
||||
bgPanel.setSize(1.0, 0.5f);
|
||||
bgPanel.setPosition(0.0, -0.5f);
|
||||
@@ -105,7 +105,7 @@ void ScopeCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) {
|
||||
const wxSize ClientSize = GetClientSize();
|
||||
|
||||
ScopeRenderDataPtr avData;
|
||||
while (inputData.try_pop(avData)) {
|
||||
while (inputData->try_pop(avData)) {
|
||||
|
||||
|
||||
if (!avData->spectrum) {
|
||||
@@ -233,8 +233,8 @@ void ScopeCanvas::OnIdle(wxIdleEvent &event) {
|
||||
event.RequestMore();
|
||||
}
|
||||
|
||||
ScopeRenderDataQueue *ScopeCanvas::getInputQueue() {
|
||||
return &inputData;
|
||||
ScopeRenderDataQueuePtr ScopeCanvas::getInputQueue() {
|
||||
return inputData;
|
||||
}
|
||||
|
||||
void ScopeCanvas::OnMouseMoved(wxMouseEvent& event) {
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
#include <vector>
|
||||
#include <queue>
|
||||
#include <memory>
|
||||
|
||||
#include "ScopeContext.h"
|
||||
#include "ScopeVisualProcessor.h"
|
||||
@@ -42,7 +43,7 @@ public:
|
||||
|
||||
void setHelpTip(std::string tip);
|
||||
|
||||
ScopeRenderDataQueue *getInputQueue();
|
||||
ScopeRenderDataQueuePtr getInputQueue();
|
||||
|
||||
private:
|
||||
void OnPaint(wxPaintEvent& event);
|
||||
@@ -54,7 +55,7 @@ private:
|
||||
void OnMouseEnterWindow(wxMouseEvent& event);
|
||||
void OnMouseLeftWindow(wxMouseEvent& event);
|
||||
|
||||
ScopeRenderDataQueue inputData;
|
||||
ScopeRenderDataQueuePtr inputData = std::make_shared<ScopeRenderDataQueue>();
|
||||
ScopePanel scopePanel;
|
||||
GLPanel parentPanel;
|
||||
SpectrumPanel spectrumPanel;
|
||||
|
||||
@@ -37,7 +37,7 @@ SpectrumCanvas::SpectrumCanvas(wxWindow *parent, std::vector<int> dispAttrs) :
|
||||
|
||||
glContext = new PrimaryGLContext(this, &wxGetApp().GetContext(this));
|
||||
|
||||
visualDataQueue.set_max_num_items(1);
|
||||
visualDataQueue->set_max_num_items(1);
|
||||
|
||||
SetCursor(wxCURSOR_SIZEWE);
|
||||
scaleFactor = 1.0;
|
||||
@@ -55,7 +55,7 @@ void SpectrumCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) {
|
||||
const wxSize ClientSize = GetClientSize();
|
||||
|
||||
SpectrumVisualDataPtr vData;
|
||||
if (visualDataQueue.try_pop(vData)) {
|
||||
if (visualDataQueue->try_pop(vData)) {
|
||||
|
||||
if (vData) {
|
||||
spectrumPanel.setPoints(vData->spectrum_points);
|
||||
@@ -286,8 +286,8 @@ void SpectrumCanvas::attachWaterfallCanvas(WaterfallCanvas* canvas_in) {
|
||||
waterfallCanvas = canvas_in;
|
||||
}
|
||||
|
||||
SpectrumVisualDataQueue *SpectrumCanvas::getVisualDataQueue() {
|
||||
return &visualDataQueue;
|
||||
SpectrumVisualDataQueuePtr SpectrumCanvas::getVisualDataQueue() {
|
||||
return visualDataQueue;
|
||||
}
|
||||
|
||||
void SpectrumCanvas::OnMouseRightDown(wxMouseEvent& event) {
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
#include <vector>
|
||||
#include <queue>
|
||||
#include <memory>
|
||||
|
||||
#include "InteractiveCanvas.h"
|
||||
#include "PrimaryGLContext.h"
|
||||
@@ -44,7 +45,7 @@ public:
|
||||
void setScaleFactorEnabled(bool en);
|
||||
void setFFTSize(int fftSize);
|
||||
|
||||
SpectrumVisualDataQueue *getVisualDataQueue();
|
||||
SpectrumVisualDataQueuePtr getVisualDataQueue();
|
||||
|
||||
private:
|
||||
void OnPaint(wxPaintEvent& event);
|
||||
@@ -70,7 +71,7 @@ private:
|
||||
int bwChange;
|
||||
bool resetScaleFactor, scaleFactorEnabled;
|
||||
|
||||
SpectrumVisualDataQueue visualDataQueue;
|
||||
SpectrumVisualDataQueuePtr visualDataQueue = std::make_shared<SpectrumVisualDataQueue>();
|
||||
|
||||
// event table
|
||||
wxDECLARE_EVENT_TABLE();
|
||||
|
||||
@@ -99,7 +99,7 @@ void WaterfallCanvas::processInputQueue() {
|
||||
while (lpsIndex >= targetVis) {
|
||||
SpectrumVisualDataPtr vData;
|
||||
|
||||
if (visualDataQueue.try_pop(vData)) {
|
||||
if (visualDataQueue->try_pop(vData)) {
|
||||
|
||||
if (vData) {
|
||||
if (vData->spectrum_points.size() == fft_size * 2) {
|
||||
@@ -880,8 +880,8 @@ void WaterfallCanvas::OnMouseRightReleased(wxMouseEvent& event) {
|
||||
mouseZoom = 1.0;
|
||||
}
|
||||
|
||||
SpectrumVisualDataQueue *WaterfallCanvas::getVisualDataQueue() {
|
||||
return &visualDataQueue;
|
||||
SpectrumVisualDataQueuePtr WaterfallCanvas::getVisualDataQueue() {
|
||||
return visualDataQueue;
|
||||
}
|
||||
|
||||
void WaterfallCanvas::updateCenterFrequency(long long freq) {
|
||||
@@ -915,7 +915,7 @@ void WaterfallCanvas::setLinesPerSecond(int lps) {
|
||||
linesPerSecond = lps;
|
||||
|
||||
//empty all
|
||||
visualDataQueue.flush();
|
||||
visualDataQueue->flush();
|
||||
}
|
||||
|
||||
void WaterfallCanvas::setMinBandwidth(int min) {
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
#include <vector>
|
||||
#include <queue>
|
||||
|
||||
#include <memory>
|
||||
#include "InteractiveCanvas.h"
|
||||
#include "MouseTracker.h"
|
||||
#include "SpectrumCanvas.h"
|
||||
@@ -31,7 +31,7 @@ public:
|
||||
|
||||
void attachSpectrumCanvas(SpectrumCanvas *canvas_in);
|
||||
void processInputQueue();
|
||||
SpectrumVisualDataQueue *getVisualDataQueue();
|
||||
SpectrumVisualDataQueuePtr getVisualDataQueue();
|
||||
|
||||
void setLinesPerSecond(int lps);
|
||||
void setMinBandwidth(int min);
|
||||
@@ -88,7 +88,8 @@ private:
|
||||
float scaleMove;
|
||||
int dragBW;
|
||||
|
||||
SpectrumVisualDataQueue visualDataQueue;
|
||||
SpectrumVisualDataQueuePtr visualDataQueue = std::make_shared<SpectrumVisualDataQueue>();
|
||||
|
||||
Timer gTimer;
|
||||
double lpsIndex;
|
||||
bool preBuf;
|
||||
|
||||
Reference in New Issue
Block a user