mirror of
https://github.com/cjcliffe/CubicSDR.git
synced 2026-06-08 08:55:07 -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:
@@ -73,7 +73,7 @@ static int audioCallback(void *outputBuffer, void * /* inputBuffer */, unsigned
|
||||
|
||||
//Zero output buffer in all cases: this allow to mute audio if no AudioThread data is
|
||||
//actually active.
|
||||
memset(out, 0, nBufferFrames * 2 * sizeof(float));
|
||||
::memset(out, 0, nBufferFrames * 2 * sizeof(float));
|
||||
|
||||
AudioThread *src = (AudioThread *) userData;
|
||||
|
||||
@@ -424,8 +424,8 @@ void AudioThread::run() {
|
||||
setupDevice((outputDevice.load() == -1) ? (dac.getDefaultOutputDevice()) : outputDevice.load());
|
||||
|
||||
// std::cout << "Audio thread started." << std::endl;
|
||||
|
||||
inputQueue = static_cast<AudioThreadInputQueue *>(getInputQueue("AudioDataInput"));
|
||||
|
||||
inputQueue = std::static_pointer_cast<AudioThreadInputQueue>(getInputQueue("AudioDataInput"));
|
||||
|
||||
//Infinite loop, witing for commands or for termination
|
||||
while (!stopping) {
|
||||
@@ -451,7 +451,7 @@ void AudioThread::run() {
|
||||
if (inputQueue != nullptr) {
|
||||
inputQueue->flush();
|
||||
}
|
||||
|
||||
|
||||
//Nullify currentInput...
|
||||
currentInput = nullptr;
|
||||
|
||||
@@ -499,7 +499,6 @@ void AudioThread::setActive(bool state) {
|
||||
|
||||
// Activity state changing, clear any inputs
|
||||
if(inputQueue) {
|
||||
|
||||
inputQueue->flush();
|
||||
}
|
||||
active = state;
|
||||
|
||||
@@ -52,10 +52,13 @@ public:
|
||||
typedef ThreadBlockingQueue<AudioThreadInputPtr> AudioThreadInputQueue;
|
||||
typedef ThreadBlockingQueue<AudioThreadCommand> AudioThreadCommandQueue;
|
||||
|
||||
typedef std::shared_ptr<AudioThreadInputQueue> AudioThreadInputQueuePtr;
|
||||
typedef std::shared_ptr<AudioThreadCommandQueue> AudioThreadCommandQueuePtr;
|
||||
|
||||
class AudioThread : public IOThread {
|
||||
public:
|
||||
AudioThreadInputPtr currentInput;
|
||||
AudioThreadInputQueue *inputQueue;
|
||||
AudioThreadInputQueuePtr inputQueue;
|
||||
std::atomic_uint audioQueuePtr;
|
||||
std::atomic_uint underflowCount;
|
||||
std::atomic_bool initialized;
|
||||
|
||||
Reference in New Issue
Block a user