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) {
std::lock_guard < std::mutex > lock(g_mutex);
std::cout << "Added garbage.." << std::endl;
garbage.insert(ref);
}
@ -107,7 +106,7 @@ public:
for (outputBuffersI = outputBuffers.begin(); outputBuffersI != outputBuffers.end(); outputBuffersI++) {
if (buf == nullptr && (*outputBuffersI)->getRefCount() <= 0) {
buf = (*outputBuffersI);
buf->setRefCount(0);
buf->setRefCount(1);
} else if ((*outputBuffersI)->getRefCount() <= 0) {
(*outputBuffersI)->decRefCount();
}
@ -128,6 +127,7 @@ public:
}
buf = new BufferType();
buf->setRefCount(1);
outputBuffers.push_back(buf);
return buf;
@ -142,7 +142,7 @@ public:
delete ref;
} else {
// 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);
}
}

View File

@ -393,6 +393,15 @@ void AudioThread::run() {
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) {
deviceController[parameters.deviceId]->removeThread(this);
@ -408,14 +417,6 @@ void AudioThread::run() {
e.printMessage();
}
}
while (!inputQueue->empty()) { // flush queue
AudioThreadInput *dummy;
inputQueue->pop(dummy);
if (dummy) {
dummy->setRefCount(0);
}
}
if (threadQueueNotify != NULL) {
DemodulatorThreadCommand tCmd(DemodulatorThreadCommand::DEMOD_THREAD_CMD_AUDIO_TERMINATED);
@ -439,23 +440,19 @@ void AudioThread::setActive(bool state) {
AudioThreadInput *dummy;
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
inputQueue->pop(dummy);
if (dummy) {
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;
}

View File

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