More minor tweaks; getBuffer refcount 1 init suggestion from @vsonnier

This commit is contained in:
Charles J. Cliffe 2016-06-08 19:48:46 -04:00
parent 2bdefca263
commit b54ab38a47
3 changed files with 22 additions and 27 deletions

View File

@ -82,7 +82,6 @@ public:
static void addGarbage(ReferenceCounter *ref) { static void addGarbage(ReferenceCounter *ref) {
std::lock_guard < std::mutex > lock(g_mutex); std::lock_guard < std::mutex > lock(g_mutex);
std::cout << "Added garbage.." << std::endl;
garbage.insert(ref); garbage.insert(ref);
} }
@ -107,7 +106,7 @@ public:
for (outputBuffersI = outputBuffers.begin(); outputBuffersI != outputBuffers.end(); outputBuffersI++) { for (outputBuffersI = outputBuffers.begin(); outputBuffersI != outputBuffers.end(); outputBuffersI++) {
if (buf == nullptr && (*outputBuffersI)->getRefCount() <= 0) { if (buf == nullptr && (*outputBuffersI)->getRefCount() <= 0) {
buf = (*outputBuffersI); buf = (*outputBuffersI);
buf->setRefCount(0); buf->setRefCount(1);
} else if ((*outputBuffersI)->getRefCount() <= 0) { } else if ((*outputBuffersI)->getRefCount() <= 0) {
(*outputBuffersI)->decRefCount(); (*outputBuffersI)->decRefCount();
} }
@ -128,6 +127,7 @@ public:
} }
buf = new BufferType(); buf = new BufferType();
buf->setRefCount(1);
outputBuffers.push_back(buf); outputBuffers.push_back(buf);
return buf; return buf;
@ -142,7 +142,7 @@ public:
delete ref; delete ref;
} else { } else {
// Something isn't done with it yet; throw it on the pile.. // Something isn't done with it yet; throw it on the pile..
std::cout << bufferId << "pushed garbage.." << std::endl; std::cout << "'" << bufferId << "' pushed garbage.." << std::endl;
ReBufferGC::addGarbage(ref); ReBufferGC::addGarbage(ref);
} }
} }

View File

@ -393,6 +393,15 @@ void AudioThread::run() {
setSampleRate(command.int_value); setSampleRate(command.int_value);
} }
} }
// Drain any remaining inputs
while (!inputQueue->empty()) {
AudioThreadInput *ref;
inputQueue->pop(ref);
if (ref) {
ref->decRefCount();
}
}
if (deviceController[parameters.deviceId] != this) { if (deviceController[parameters.deviceId] != this) {
deviceController[parameters.deviceId]->removeThread(this); deviceController[parameters.deviceId]->removeThread(this);
@ -408,14 +417,6 @@ void AudioThread::run() {
e.printMessage(); e.printMessage();
} }
} }
while (!inputQueue->empty()) { // flush queue
AudioThreadInput *dummy;
inputQueue->pop(dummy);
if (dummy) {
dummy->setRefCount(0);
}
}
if (threadQueueNotify != NULL) { if (threadQueueNotify != NULL) {
DemodulatorThreadCommand tCmd(DemodulatorThreadCommand::DEMOD_THREAD_CMD_AUDIO_TERMINATED); DemodulatorThreadCommand tCmd(DemodulatorThreadCommand::DEMOD_THREAD_CMD_AUDIO_TERMINATED);
@ -439,23 +440,19 @@ void AudioThread::setActive(bool state) {
AudioThreadInput *dummy; AudioThreadInput *dummy;
if (state && !active && inputQueue) { if (state && !active && inputQueue) {
deviceController[parameters.deviceId]->bindThread(this);
} else if (!state && active) {
deviceController[parameters.deviceId]->removeThread(this);
}
// Activity state changing, clear any inputs
if(inputQueue) {
while (!inputQueue->empty()) { // flush queue while (!inputQueue->empty()) { // flush queue
inputQueue->pop(dummy); inputQueue->pop(dummy);
if (dummy) { if (dummy) {
dummy->decRefCount(); dummy->decRefCount();
} }
} }
deviceController[parameters.deviceId]->bindThread(this);
} else if (!state && active) {
deviceController[parameters.deviceId]->removeThread(this);
if(inputQueue) {
while (!inputQueue->empty()) { // flush queue
inputQueue->pop(dummy);
if (dummy) {
dummy->decRefCount();
}
}
}
} }
active = state; active = state;
} }

View File

@ -132,13 +132,11 @@ void DemodulatorThread::run() {
ati->sampleRate = cModemKit->audioSampleRate; ati->sampleRate = cModemKit->audioSampleRate;
ati->inputRate = inp->sampleRate; ati->inputRate = inp->sampleRate;
ati->setRefCount(1);
} else if (modemDigital != nullptr) { } else if (modemDigital != nullptr) {
ati = outputBuffers.getBuffer(); ati = outputBuffers.getBuffer();
ati->sampleRate = cModemKit->sampleRate; ati->sampleRate = cModemKit->sampleRate;
ati->inputRate = inp->sampleRate; ati->inputRate = inp->sampleRate;
ati->setRefCount(1);
} }
cModem->demodulate(cModemKit, &modemData, ati); cModem->demodulate(cModemKit, &modemData, ati);
@ -281,14 +279,14 @@ void DemodulatorThread::run() {
while (!iqInputQueue->empty()) { while (!iqInputQueue->empty()) {
DemodulatorThreadPostIQData *ref; DemodulatorThreadPostIQData *ref;
iqInputQueue->pop(ref); iqInputQueue->pop(ref);
if (ref) { if (ref) { // May have other consumers; just decrement
ref->setRefCount(0); ref->decRefCount();
} }
} }
while (!audioOutputQueue->empty()) { while (!audioOutputQueue->empty()) {
AudioThreadInput *ref; AudioThreadInput *ref;
audioOutputQueue->pop(ref); audioOutputQueue->pop(ref);
if (ref) { if (ref) { // Originated here; set RefCount to 0
ref->setRefCount(0); ref->setRefCount(0);
} }
} }