mirror of
https://github.com/cjcliffe/CubicSDR.git
synced 2024-10-01 09:36:42 -04:00
Rebuffer Garbage collector; mostly to pinpoint/gracefully handle ReBuffer failures
This commit is contained in:
parent
d6e18b08ef
commit
037be13fac
@ -1,5 +1,8 @@
|
|||||||
#include "IOThread.h"
|
#include "IOThread.h"
|
||||||
|
|
||||||
|
std::mutex ReBufferGC::g_mutex;
|
||||||
|
std::set<ReferenceCounter *> ReBufferGC::garbage;
|
||||||
|
|
||||||
IOThread::IOThread() {
|
IOThread::IOThread() {
|
||||||
terminated.store(false);
|
terminated.store(false);
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <deque>
|
#include <deque>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <set>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
@ -54,6 +55,43 @@ private:
|
|||||||
|
|
||||||
#define REBUFFER_GC_LIMIT 100
|
#define REBUFFER_GC_LIMIT 100
|
||||||
|
|
||||||
|
class ReBufferGC {
|
||||||
|
public:
|
||||||
|
static void garbageCollect() {
|
||||||
|
std::lock_guard < std::mutex > lock(g_mutex);
|
||||||
|
|
||||||
|
std::deque<ReferenceCounter *> garbageRemoval;
|
||||||
|
for (typename std::set<ReferenceCounter *>::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<ReferenceCounter *> garbage;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
template<class BufferType = ReferenceCounter>
|
template<class BufferType = ReferenceCounter>
|
||||||
class ReBuffer {
|
class ReBuffer {
|
||||||
|
|
||||||
@ -100,10 +138,17 @@ public:
|
|||||||
while (!outputBuffers.empty()) {
|
while (!outputBuffers.empty()) {
|
||||||
BufferType *ref = outputBuffers.front();
|
BufferType *ref = outputBuffers.front();
|
||||||
outputBuffers.pop_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::string bufferId;
|
||||||
std::deque<BufferType*> outputBuffers;
|
std::deque<BufferType*> outputBuffers;
|
||||||
typename std::deque<BufferType*>::iterator outputBuffersI;
|
typename std::deque<BufferType*>::iterator outputBuffersI;
|
||||||
|
@ -212,6 +212,7 @@ void DemodulatorMgr::setActiveDemodulator(DemodulatorInstance *demod, bool tempo
|
|||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
garbageCollect();
|
garbageCollect();
|
||||||
|
ReBufferGC::garbageCollect();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (activeVisualDemodulator) {
|
if (activeVisualDemodulator) {
|
||||||
|
@ -34,5 +34,7 @@ void ModemAM::demodulate(ModemKit *kit, ModemIQData *input, AudioThreadInput *au
|
|||||||
ampmodem_demodulate(demodAM, input->data[i], &demodOutputData[i]);
|
ampmodem_demodulate(demodAM, input->data[i], &demodOutputData[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
input->decRefCount();
|
||||||
|
|
||||||
buildAudioOutput(amkit,audioOut,true);
|
buildAudioOutput(amkit,audioOut,true);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user