From 037be13fac56361ec45505e73d90f5d5416bcff8 Mon Sep 17 00:00:00 2001 From: "Charles J. Cliffe" Date: Tue, 7 Jun 2016 19:54:36 -0400 Subject: [PATCH 01/10] Rebuffer Garbage collector; mostly to pinpoint/gracefully handle ReBuffer failures --- src/IOThread.cpp | 3 ++ src/IOThread.h | 49 ++++++++++++++++++++++++++-- src/demod/DemodulatorMgr.cpp | 1 + src/modules/modem/analog/ModemAM.cpp | 2 ++ 4 files changed, 53 insertions(+), 2 deletions(-) diff --git a/src/IOThread.cpp b/src/IOThread.cpp index d57f5ba..b3ffb0a 100644 --- a/src/IOThread.cpp +++ b/src/IOThread.cpp @@ -1,5 +1,8 @@ #include "IOThread.h" +std::mutex ReBufferGC::g_mutex; +std::set ReBufferGC::garbage; + IOThread::IOThread() { terminated.store(false); } diff --git a/src/IOThread.h b/src/IOThread.h index ee93f6f..7ec7165 100644 --- a/src/IOThread.h +++ b/src/IOThread.h @@ -4,6 +4,7 @@ #include #include #include +#include #include #include @@ -54,6 +55,43 @@ private: #define REBUFFER_GC_LIMIT 100 +class ReBufferGC { +public: + static void garbageCollect() { + std::lock_guard < std::mutex > lock(g_mutex); + + std::deque garbageRemoval; + for (typename std::set::iterator i = garbage.begin(); i != garbage.end(); i++) { + if ((*i)->getRefCount() <= 0) { + garbageRemoval.push_back(*i); + } + else { + std::cout << "Garbage in queue " << (*i)->getRefCount() << " usage(s)" << std::endl; + } + } + if ( garbageRemoval.size() ) { + std::cout << "Garbage collecting " << garbageRemoval.size() << " ReBuffer(s)" << std::endl; + while (!garbageRemoval.empty()) { + ReferenceCounter *ref = garbageRemoval.back(); + garbageRemoval.pop_back(); + garbage.erase(ref); + delete ref; + } + } + } + + static void addGarbage(ReferenceCounter *ref) { + std::lock_guard < std::mutex > lock(g_mutex); + std::cout << "Added garbage.." << std::endl; + garbage.insert(ref); + } + +private: + static std::mutex g_mutex; + static std::set garbage; +}; + + template class ReBuffer { @@ -100,10 +138,17 @@ public: while (!outputBuffers.empty()) { BufferType *ref = outputBuffers.front(); outputBuffers.pop_front(); - delete ref; + if (ref->getRefCount() <= 0) { + delete ref; + } else { + // Something isn't done with it yet; throw it on the pile.. + std::cout << bufferId << "pushed garbage.." << std::endl; + ReBufferGC::addGarbage(ref); + } } } -private: + + private: std::string bufferId; std::deque outputBuffers; typename std::deque::iterator outputBuffersI; diff --git a/src/demod/DemodulatorMgr.cpp b/src/demod/DemodulatorMgr.cpp index 95970be..64b9d82 100644 --- a/src/demod/DemodulatorMgr.cpp +++ b/src/demod/DemodulatorMgr.cpp @@ -212,6 +212,7 @@ void DemodulatorMgr::setActiveDemodulator(DemodulatorInstance *demod, bool tempo #endif } else { garbageCollect(); + ReBufferGC::garbageCollect(); } if (activeVisualDemodulator) { diff --git a/src/modules/modem/analog/ModemAM.cpp b/src/modules/modem/analog/ModemAM.cpp index 6a5eb3c..af956cd 100644 --- a/src/modules/modem/analog/ModemAM.cpp +++ b/src/modules/modem/analog/ModemAM.cpp @@ -34,5 +34,7 @@ void ModemAM::demodulate(ModemKit *kit, ModemIQData *input, AudioThreadInput *au ampmodem_demodulate(demodAM, input->data[i], &demodOutputData[i]); } + input->decRefCount(); + buildAudioOutput(amkit,audioOut,true); } From 389ac4f53764793c4184eb805342a2c86604deb3 Mon Sep 17 00:00:00 2001 From: "Charles J. Cliffe" Date: Tue, 7 Jun 2016 19:56:08 -0400 Subject: [PATCH 02/10] remove test decRef --- src/modules/modem/analog/ModemAM.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/modules/modem/analog/ModemAM.cpp b/src/modules/modem/analog/ModemAM.cpp index af956cd..6a5eb3c 100644 --- a/src/modules/modem/analog/ModemAM.cpp +++ b/src/modules/modem/analog/ModemAM.cpp @@ -34,7 +34,5 @@ void ModemAM::demodulate(ModemKit *kit, ModemIQData *input, AudioThreadInput *au ampmodem_demodulate(demodAM, input->data[i], &demodOutputData[i]); } - input->decRefCount(); - buildAudioOutput(amkit,audioOut,true); } From 50bfb251f8defc56c5a6b80ec570b29fa18d9a1e Mon Sep 17 00:00:00 2001 From: "Charles J. Cliffe" Date: Tue, 7 Jun 2016 20:36:59 -0400 Subject: [PATCH 03/10] Attempt to clean up any buffers that weren't used on terminate, still one hanging around.. --- src/audio/AudioThread.cpp | 8 ++++++++ src/demod/DemodulatorPreThread.cpp | 5 +++++ src/demod/DemodulatorThread.cpp | 11 +++++++++++ src/util/ThreadQueue.h | 3 ++- 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/audio/AudioThread.cpp b/src/audio/AudioThread.cpp index 62cec69..c4152de 100644 --- a/src/audio/AudioThread.cpp +++ b/src/audio/AudioThread.cpp @@ -421,6 +421,14 @@ void AudioThread::terminate() { terminated = true; AudioThreadCommand endCond; // push an empty input to bump the queue cmdQueue.push(endCond); + + while (!inputQueue->empty()) { // flush queue + AudioThreadInput *dummy; + inputQueue->pop(dummy); + if (dummy) { + dummy->decRefCount(); + } + } } bool AudioThread::isActive() { diff --git a/src/demod/DemodulatorPreThread.cpp b/src/demod/DemodulatorPreThread.cpp index 31f9dfc..e1a438c 100644 --- a/src/demod/DemodulatorPreThread.cpp +++ b/src/demod/DemodulatorPreThread.cpp @@ -271,6 +271,11 @@ void DemodulatorPreThread::run() { } } + while (!iqOutputQueue->empty()) { + DemodulatorThreadPostIQData *tmp; + iqOutputQueue->pop(tmp); + tmp->decRefCount(); + } buffers.purge(); DemodulatorThreadCommand tCmd(DemodulatorThreadCommand::DEMOD_THREAD_CMD_DEMOD_PREPROCESS_TERMINATED); diff --git a/src/demod/DemodulatorThread.cpp b/src/demod/DemodulatorThread.cpp index 254aa68..0ef3bb1 100644 --- a/src/demod/DemodulatorThread.cpp +++ b/src/demod/DemodulatorThread.cpp @@ -277,6 +277,17 @@ void DemodulatorThread::run() { } // end while !terminated + // Purge any unused inputs + while (!iqInputQueue->empty()) { + DemodulatorThreadPostIQData *inp; + iqInputQueue->pop(inp); + inp->setRefCount(0); + } + while (!audioOutputQueue->empty()) { + AudioThreadInput *ati; + audioOutputQueue->pop(ati); + ati->setRefCount(0); + } outputBuffers.purge(); //Guard the cleanup of audioVisOutputQueue properly. diff --git a/src/util/ThreadQueue.h b/src/util/ThreadQueue.h index e69265c..4d1f901 100644 --- a/src/util/ThreadQueue.h +++ b/src/util/ThreadQueue.h @@ -231,8 +231,9 @@ public: /** * Remove any items in the queue. */ - void flush() const { + void flush() { std::lock_guard < std::mutex > lock(m_mutex); + m_queue = std::queue(); std::queue emptyQueue; std::swap(m_queue, emptyQueue); } From 2bdefca2635112c2794ae0299a130b58887c8d09 Mon Sep 17 00:00:00 2001 From: "Charles J. Cliffe" Date: Tue, 7 Jun 2016 21:12:30 -0400 Subject: [PATCH 04/10] Trying.. still one stuck in the queue on delete.. --- src/audio/AudioThread.cpp | 16 ++++++++-------- src/demod/DemodulatorThread.cpp | 23 +++++++++++------------ 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/src/audio/AudioThread.cpp b/src/audio/AudioThread.cpp index c4152de..5db31d8 100644 --- a/src/audio/AudioThread.cpp +++ b/src/audio/AudioThread.cpp @@ -409,6 +409,14 @@ void AudioThread::run() { } } + 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); tCmd.context = this; @@ -421,14 +429,6 @@ void AudioThread::terminate() { terminated = true; AudioThreadCommand endCond; // push an empty input to bump the queue cmdQueue.push(endCond); - - while (!inputQueue->empty()) { // flush queue - AudioThreadInput *dummy; - inputQueue->pop(dummy); - if (dummy) { - dummy->decRefCount(); - } - } } bool AudioThread::isActive() { diff --git a/src/demod/DemodulatorThread.cpp b/src/demod/DemodulatorThread.cpp index 0ef3bb1..bab8239 100644 --- a/src/demod/DemodulatorThread.cpp +++ b/src/demod/DemodulatorThread.cpp @@ -173,7 +173,7 @@ void DemodulatorThread::run() { } } } else if (ati) { - ati->decRefCount(); + ati->setRefCount(0); ati = nullptr; } @@ -279,24 +279,23 @@ void DemodulatorThread::run() { // Purge any unused inputs while (!iqInputQueue->empty()) { - DemodulatorThreadPostIQData *inp; - iqInputQueue->pop(inp); - inp->setRefCount(0); + DemodulatorThreadPostIQData *ref; + iqInputQueue->pop(ref); + if (ref) { + ref->setRefCount(0); + } } while (!audioOutputQueue->empty()) { - AudioThreadInput *ati; - audioOutputQueue->pop(ati); - ati->setRefCount(0); + AudioThreadInput *ref; + audioOutputQueue->pop(ref); + if (ref) { + ref->setRefCount(0); + } } outputBuffers.purge(); //Guard the cleanup of audioVisOutputQueue properly. std::lock_guard < std::mutex > lock(m_mutexAudioVisOutputQueue); - -// if (audioVisOutputQueue != nullptr && !audioVisOutputQueue->empty()) { -// AudioThreadInput *dummy_vis; -// audioVisOutputQueue->pop(dummy_vis); -// } DemodulatorThreadCommand tCmd(DemodulatorThreadCommand::DEMOD_THREAD_CMD_DEMOD_TERMINATED); tCmd.context = this; From b54ab38a47675632f42adaf1474f4064bba79c27 Mon Sep 17 00:00:00 2001 From: "Charles J. Cliffe" Date: Wed, 8 Jun 2016 19:48:46 -0400 Subject: [PATCH 05/10] More minor tweaks; getBuffer refcount 1 init suggestion from @vsonnier --- src/IOThread.h | 6 +++--- src/audio/AudioThread.cpp | 35 +++++++++++++++------------------ src/demod/DemodulatorThread.cpp | 8 +++----- 3 files changed, 22 insertions(+), 27 deletions(-) diff --git a/src/IOThread.h b/src/IOThread.h index 7ec7165..2397018 100644 --- a/src/IOThread.h +++ b/src/IOThread.h @@ -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); } } diff --git a/src/audio/AudioThread.cpp b/src/audio/AudioThread.cpp index 5db31d8..bc51ef7 100644 --- a/src/audio/AudioThread.cpp +++ b/src/audio/AudioThread.cpp @@ -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; } diff --git a/src/demod/DemodulatorThread.cpp b/src/demod/DemodulatorThread.cpp index bab8239..9ec0cab 100644 --- a/src/demod/DemodulatorThread.cpp +++ b/src/demod/DemodulatorThread.cpp @@ -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); } } From 0067e309d18b917298cab8546d11a403517d75bf Mon Sep 17 00:00:00 2001 From: "Charles J. Cliffe" Date: Wed, 8 Jun 2016 21:31:52 -0400 Subject: [PATCH 06/10] more debugging; fix some potential refcount leaks... --- src/IOThread.h | 22 +++++++++++++++++++--- src/audio/AudioThread.cpp | 12 ++++++++++++ 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/src/IOThread.h b/src/IOThread.h index 2397018..5a2a1da 100644 --- a/src/IOThread.h +++ b/src/IOThread.h @@ -24,6 +24,16 @@ class ReferenceCounter { public: + void setIndex(int idx) { + std::lock_guard < std::recursive_mutex > lock(m_mutex); + index = idx; + } + + int getIndex() { + std::lock_guard < std::recursive_mutex > lock(m_mutex); + return index; + } + void setRefCount(int rc) { std::lock_guard < std::recursive_mutex > lock(m_mutex); refCount = rc; @@ -49,7 +59,7 @@ protected: mutable std::recursive_mutex m_mutex; private: - int refCount; + int index, refCount; }; @@ -66,7 +76,7 @@ public: garbageRemoval.push_back(*i); } else { - std::cout << "Garbage in queue " << (*i)->getRefCount() << " usage(s)" << std::endl; + std::cout << "Garbage in queue buffer idx #" << (*i)->getIndex() << ", " << (*i)->getRefCount() << " usage(s)" << std::endl; } } if ( garbageRemoval.size() ) { @@ -96,7 +106,7 @@ class ReBuffer { public: ReBuffer(std::string bufferId) : bufferId(bufferId) { - + indexCounter.store(0); } BufferType *getBuffer() { @@ -118,6 +128,7 @@ public: outputBuffers.pop_back(); delete ref; } + buf->setIndex(indexCounter++); return buf; } @@ -128,6 +139,7 @@ public: buf = new BufferType(); buf->setRefCount(1); + buf->setIndex(indexCounter++); outputBuffers.push_back(buf); return buf; @@ -135,6 +147,9 @@ public: void purge() { std::lock_guard < std::mutex > lock(m_mutex); + if (bufferId == "DemodulatorThreadBuffers") { + std::cout << "'" << bufferId << "' purging.. total indexes: " << indexCounter.load() << std::endl; + } while (!outputBuffers.empty()) { BufferType *ref = outputBuffers.front(); outputBuffers.pop_front(); @@ -153,6 +168,7 @@ public: std::deque outputBuffers; typename std::deque::iterator outputBuffersI; mutable std::mutex m_mutex; + std::atomic_int indexCounter; }; diff --git a/src/audio/AudioThread.cpp b/src/audio/AudioThread.cpp index bc51ef7..7b18336 100644 --- a/src/audio/AudioThread.cpp +++ b/src/audio/AudioThread.cpp @@ -84,6 +84,9 @@ static int audioCallback(void *outputBuffer, void * /* inputBuffer */, unsigned } srcmix->inputQueue->pop(srcmix->currentInput); if (srcmix->isTerminated()) { + if (srcmix->currentInput) { + srcmix->currentInput->decRefCount(); + } continue; } continue; @@ -123,6 +126,9 @@ static int audioCallback(void *outputBuffer, void * /* inputBuffer */, unsigned } srcmix->inputQueue->pop(srcmix->currentInput); if (srcmix->isTerminated()) { + if (srcmix->currentInput) { + srcmix->currentInput->decRefCount(); + } continue; } } @@ -144,6 +150,9 @@ static int audioCallback(void *outputBuffer, void * /* inputBuffer */, unsigned } srcmix->inputQueue->pop(srcmix->currentInput); if (srcmix->isTerminated()) { + if (srcmix->currentInput) { + srcmix->currentInput->decRefCount(); + } break; } float srcPeak = srcmix->currentInput->peak * srcmix->gain; @@ -171,6 +180,9 @@ static int audioCallback(void *outputBuffer, void * /* inputBuffer */, unsigned } srcmix->inputQueue->pop(srcmix->currentInput); if (srcmix->isTerminated()) { + if (srcmix->currentInput) { + srcmix->currentInput->decRefCount(); + } break; } float srcPeak = srcmix->currentInput->peak * srcmix->gain; From d7ef86ae1072c3d5501f10c286b1300681a5518d Mon Sep 17 00:00:00 2001 From: "Charles J. Cliffe" Date: Wed, 8 Jun 2016 21:45:52 -0400 Subject: [PATCH 07/10] =?UTF-8?q?On=20second=20thought,=20let=E2=80=99s=20?= =?UTF-8?q?not=20go=20to=20Camelot.=20=E2=80=98Tis=20a=20silly=20place.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/audio/AudioThread.cpp | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/src/audio/AudioThread.cpp b/src/audio/AudioThread.cpp index 7b18336..20193a7 100644 --- a/src/audio/AudioThread.cpp +++ b/src/audio/AudioThread.cpp @@ -84,16 +84,11 @@ static int audioCallback(void *outputBuffer, void * /* inputBuffer */, unsigned } srcmix->inputQueue->pop(srcmix->currentInput); if (srcmix->isTerminated()) { - if (srcmix->currentInput) { - srcmix->currentInput->decRefCount(); - } continue; } continue; } -// std::lock_guard < std::mutex > lock(srcmix->currentInput->m_mutex); - if (srcmix->currentInput->sampleRate != src->getSampleRate()) { while (srcmix->inputQueue->size()) { srcmix->inputQueue->pop(srcmix->currentInput); @@ -126,9 +121,6 @@ static int audioCallback(void *outputBuffer, void * /* inputBuffer */, unsigned } srcmix->inputQueue->pop(srcmix->currentInput); if (srcmix->isTerminated()) { - if (srcmix->currentInput) { - srcmix->currentInput->decRefCount(); - } continue; } } @@ -150,9 +142,6 @@ static int audioCallback(void *outputBuffer, void * /* inputBuffer */, unsigned } srcmix->inputQueue->pop(srcmix->currentInput); if (srcmix->isTerminated()) { - if (srcmix->currentInput) { - srcmix->currentInput->decRefCount(); - } break; } float srcPeak = srcmix->currentInput->peak * srcmix->gain; @@ -180,9 +169,6 @@ static int audioCallback(void *outputBuffer, void * /* inputBuffer */, unsigned } srcmix->inputQueue->pop(srcmix->currentInput); if (srcmix->isTerminated()) { - if (srcmix->currentInput) { - srcmix->currentInput->decRefCount(); - } break; } float srcPeak = srcmix->currentInput->peak * srcmix->gain; @@ -414,6 +400,11 @@ void AudioThread::run() { ref->decRefCount(); } } + + if (currentInput) { + currentInput->setRefCount(0); + currentInput = nullptr; + } if (deviceController[parameters.deviceId] != this) { deviceController[parameters.deviceId]->removeThread(this); From df33751f9ee20fc75247cffecdf0500d98769bb0 Mon Sep 17 00:00:00 2001 From: "Charles J. Cliffe" Date: Wed, 8 Jun 2016 21:48:10 -0400 Subject: [PATCH 08/10] might be null.. --- src/audio/AudioThread.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/audio/AudioThread.cpp b/src/audio/AudioThread.cpp index 20193a7..0e400d0 100644 --- a/src/audio/AudioThread.cpp +++ b/src/audio/AudioThread.cpp @@ -393,7 +393,7 @@ void AudioThread::run() { } // Drain any remaining inputs - while (!inputQueue->empty()) { + if (inputQueue) while (!inputQueue->empty()) { AudioThreadInput *ref; inputQueue->pop(ref); if (ref) { From 1dba16b15f5b4d37cbb84250cf55b73d763da929 Mon Sep 17 00:00:00 2001 From: "Charles J. Cliffe" Date: Wed, 8 Jun 2016 21:54:02 -0400 Subject: [PATCH 09/10] comment some debug logging --- src/IOThread.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/IOThread.h b/src/IOThread.h index 5a2a1da..f39d71d 100644 --- a/src/IOThread.h +++ b/src/IOThread.h @@ -147,16 +147,16 @@ public: void purge() { std::lock_guard < std::mutex > lock(m_mutex); - if (bufferId == "DemodulatorThreadBuffers") { - std::cout << "'" << bufferId << "' purging.. total indexes: " << indexCounter.load() << std::endl; - } +// if (bufferId == "DemodulatorThreadBuffers") { +// std::cout << "'" << bufferId << "' purging.. total indexes: " << indexCounter.load() << std::endl; +// } while (!outputBuffers.empty()) { BufferType *ref = outputBuffers.front(); outputBuffers.pop_front(); if (ref->getRefCount() <= 0) { delete ref; } 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.. keep this as a bug indicator for now.. std::cout << "'" << bufferId << "' pushed garbage.." << std::endl; ReBufferGC::addGarbage(ref); } From 9c10e2baaf086979c625990b11635e90d8e19a73 Mon Sep 17 00:00:00 2001 From: "Charles J. Cliffe" Date: Wed, 8 Jun 2016 22:08:14 -0400 Subject: [PATCH 10/10] comment index debugging --- src/IOThread.h | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/IOThread.h b/src/IOThread.h index f39d71d..0197894 100644 --- a/src/IOThread.h +++ b/src/IOThread.h @@ -24,15 +24,15 @@ class ReferenceCounter { public: - void setIndex(int idx) { - std::lock_guard < std::recursive_mutex > lock(m_mutex); - index = idx; - } +// void setIndex(int idx) { +// std::lock_guard < std::recursive_mutex > lock(m_mutex); +// index = idx; +// } - int getIndex() { - std::lock_guard < std::recursive_mutex > lock(m_mutex); - return index; - } +// int getIndex() { +// std::lock_guard < std::recursive_mutex > lock(m_mutex); +// return index; +// } void setRefCount(int rc) { std::lock_guard < std::recursive_mutex > lock(m_mutex); @@ -59,7 +59,8 @@ protected: mutable std::recursive_mutex m_mutex; private: - int index, refCount; + int refCount; +// int index; }; @@ -76,7 +77,8 @@ public: garbageRemoval.push_back(*i); } else { - std::cout << "Garbage in queue buffer idx #" << (*i)->getIndex() << ", " << (*i)->getRefCount() << " usage(s)" << std::endl; +// std::cout << "Garbage in queue buffer idx #" << (*i)->getIndex() << ", " << (*i)->getRefCount() << " usage(s)" << std::endl; + std::cout << "Garbage in queue buffer with " << (*i)->getRefCount() << " usage(s)" << std::endl; } } if ( garbageRemoval.size() ) { @@ -106,7 +108,7 @@ class ReBuffer { public: ReBuffer(std::string bufferId) : bufferId(bufferId) { - indexCounter.store(0); +// indexCounter.store(0); } BufferType *getBuffer() { @@ -128,7 +130,7 @@ public: outputBuffers.pop_back(); delete ref; } - buf->setIndex(indexCounter++); +// buf->setIndex(indexCounter++); return buf; } @@ -139,7 +141,7 @@ public: buf = new BufferType(); buf->setRefCount(1); - buf->setIndex(indexCounter++); +// buf->setIndex(indexCounter++); outputBuffers.push_back(buf); return buf; @@ -168,7 +170,7 @@ public: std::deque outputBuffers; typename std::deque::iterator outputBuffersI; mutable std::mutex m_mutex; - std::atomic_int indexCounter; +// std::atomic_int indexCounter; };