mirror of
https://github.com/cjcliffe/CubicSDR.git
synced 2024-11-26 13:48:38 -05:00
more debugging; fix some potential refcount leaks...
This commit is contained in:
parent
b54ab38a47
commit
0067e309d1
@ -24,6 +24,16 @@ class ReferenceCounter {
|
|||||||
|
|
||||||
public:
|
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) {
|
void setRefCount(int rc) {
|
||||||
std::lock_guard < std::recursive_mutex > lock(m_mutex);
|
std::lock_guard < std::recursive_mutex > lock(m_mutex);
|
||||||
refCount = rc;
|
refCount = rc;
|
||||||
@ -49,7 +59,7 @@ protected:
|
|||||||
mutable std::recursive_mutex m_mutex;
|
mutable std::recursive_mutex m_mutex;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int refCount;
|
int index, refCount;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -66,7 +76,7 @@ public:
|
|||||||
garbageRemoval.push_back(*i);
|
garbageRemoval.push_back(*i);
|
||||||
}
|
}
|
||||||
else {
|
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() ) {
|
if ( garbageRemoval.size() ) {
|
||||||
@ -96,7 +106,7 @@ class ReBuffer {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
ReBuffer(std::string bufferId) : bufferId(bufferId) {
|
ReBuffer(std::string bufferId) : bufferId(bufferId) {
|
||||||
|
indexCounter.store(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
BufferType *getBuffer() {
|
BufferType *getBuffer() {
|
||||||
@ -118,6 +128,7 @@ public:
|
|||||||
outputBuffers.pop_back();
|
outputBuffers.pop_back();
|
||||||
delete ref;
|
delete ref;
|
||||||
}
|
}
|
||||||
|
buf->setIndex(indexCounter++);
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -128,6 +139,7 @@ public:
|
|||||||
|
|
||||||
buf = new BufferType();
|
buf = new BufferType();
|
||||||
buf->setRefCount(1);
|
buf->setRefCount(1);
|
||||||
|
buf->setIndex(indexCounter++);
|
||||||
outputBuffers.push_back(buf);
|
outputBuffers.push_back(buf);
|
||||||
|
|
||||||
return buf;
|
return buf;
|
||||||
@ -135,6 +147,9 @@ public:
|
|||||||
|
|
||||||
void purge() {
|
void purge() {
|
||||||
std::lock_guard < std::mutex > lock(m_mutex);
|
std::lock_guard < std::mutex > lock(m_mutex);
|
||||||
|
if (bufferId == "DemodulatorThreadBuffers") {
|
||||||
|
std::cout << "'" << bufferId << "' purging.. total indexes: " << indexCounter.load() << std::endl;
|
||||||
|
}
|
||||||
while (!outputBuffers.empty()) {
|
while (!outputBuffers.empty()) {
|
||||||
BufferType *ref = outputBuffers.front();
|
BufferType *ref = outputBuffers.front();
|
||||||
outputBuffers.pop_front();
|
outputBuffers.pop_front();
|
||||||
@ -153,6 +168,7 @@ public:
|
|||||||
std::deque<BufferType*> outputBuffers;
|
std::deque<BufferType*> outputBuffers;
|
||||||
typename std::deque<BufferType*>::iterator outputBuffersI;
|
typename std::deque<BufferType*>::iterator outputBuffersI;
|
||||||
mutable std::mutex m_mutex;
|
mutable std::mutex m_mutex;
|
||||||
|
std::atomic_int indexCounter;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -84,6 +84,9 @@ static int audioCallback(void *outputBuffer, void * /* inputBuffer */, unsigned
|
|||||||
}
|
}
|
||||||
srcmix->inputQueue->pop(srcmix->currentInput);
|
srcmix->inputQueue->pop(srcmix->currentInput);
|
||||||
if (srcmix->isTerminated()) {
|
if (srcmix->isTerminated()) {
|
||||||
|
if (srcmix->currentInput) {
|
||||||
|
srcmix->currentInput->decRefCount();
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
@ -123,6 +126,9 @@ static int audioCallback(void *outputBuffer, void * /* inputBuffer */, unsigned
|
|||||||
}
|
}
|
||||||
srcmix->inputQueue->pop(srcmix->currentInput);
|
srcmix->inputQueue->pop(srcmix->currentInput);
|
||||||
if (srcmix->isTerminated()) {
|
if (srcmix->isTerminated()) {
|
||||||
|
if (srcmix->currentInput) {
|
||||||
|
srcmix->currentInput->decRefCount();
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -144,6 +150,9 @@ static int audioCallback(void *outputBuffer, void * /* inputBuffer */, unsigned
|
|||||||
}
|
}
|
||||||
srcmix->inputQueue->pop(srcmix->currentInput);
|
srcmix->inputQueue->pop(srcmix->currentInput);
|
||||||
if (srcmix->isTerminated()) {
|
if (srcmix->isTerminated()) {
|
||||||
|
if (srcmix->currentInput) {
|
||||||
|
srcmix->currentInput->decRefCount();
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
float srcPeak = srcmix->currentInput->peak * srcmix->gain;
|
float srcPeak = srcmix->currentInput->peak * srcmix->gain;
|
||||||
@ -171,6 +180,9 @@ static int audioCallback(void *outputBuffer, void * /* inputBuffer */, unsigned
|
|||||||
}
|
}
|
||||||
srcmix->inputQueue->pop(srcmix->currentInput);
|
srcmix->inputQueue->pop(srcmix->currentInput);
|
||||||
if (srcmix->isTerminated()) {
|
if (srcmix->isTerminated()) {
|
||||||
|
if (srcmix->currentInput) {
|
||||||
|
srcmix->currentInput->decRefCount();
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
float srcPeak = srcmix->currentInput->peak * srcmix->gain;
|
float srcPeak = srcmix->currentInput->peak * srcmix->gain;
|
||||||
|
Loading…
Reference in New Issue
Block a user