Make ReBuffer also GC its own memory + cleanups:

- Use deque in ReBuffer instead of vector (as before) because it allows freeing its memory
- Random cleanup: remove mutable when not needed.
This commit is contained in:
vsonnier 2017-05-25 16:39:01 +02:00
parent 3192ee0e71
commit 44cdfa8521
4 changed files with 14 additions and 9 deletions

View File

@ -5,7 +5,7 @@
#include <mutex>
#include <atomic>
#include <vector>
#include <deque>
#include <map>
#include <set>
#include <string>
@ -61,7 +61,11 @@ public:
while (it != outputBuffers.end()) {
//careful here: take care of reading the use_count directly
//through the iterator, else it's value is wrong if a temp variable
//is used.
long use = it->ptr.use_count();
//1. If we encounter a shared_ptr with a use count of 0, this
//is a bug since it is supposed to be at least 1, because it is referenced here.
//in this case, purge it from here and trace.
@ -133,13 +137,14 @@ private:
//name of the buffer cache kind
std::string bufferId;
//the ReBuffer cache
std::vector< ReBufferAge < ReBufferPtr > > outputBuffers;
//the ReBuffer cache: use a std:deque to also release
//memory when ReBufferPtr are GCed.
std::deque< ReBufferAge < ReBufferPtr > > outputBuffers;
typedef typename std::vector< ReBufferAge < ReBufferPtr > >::iterator outputBuffersI;
typedef typename std::deque< ReBufferAge < ReBufferPtr > >::iterator outputBuffersI;
//mutex protecting access to outputBuffers.
mutable std::mutex m_mutex;
std::mutex m_mutex;
};
@ -183,7 +188,7 @@ protected:
std::map<std::string, ThreadQueueBase *, map_string_less> output_queues;
//this protects against concurrent changes in input/output bindings: get/set/Input/OutPutQueue
mutable std::mutex m_queue_bindings_mutex;
std::mutex m_queue_bindings_mutex;
//true when a termination is ordered
std::atomic_bool stopping;

View File

@ -139,7 +139,7 @@ private:
DemodulatorThreadControlCommandQueue *threadQueueControl;
//protects child thread creation and termination
mutable std::mutex m_thread_control_mutex;
std::mutex m_thread_control_mutex;
std::atomic<std::string *> label; //
// User editable buffer, 16 bit string.

View File

@ -93,7 +93,7 @@ private:
//because of the usage of public re-entrant methods
std::recursive_mutex demods_busy;
mutable std::mutex deleted_demods_busy;
std::mutex deleted_demods_busy;
std::map<std::string, ModemSettings> lastModemSettings;
std::map<int,RtAudio::DeviceInfo> outputDevices;

View File

@ -68,5 +68,5 @@ protected:
DemodulatorThreadControlCommandQueue *threadQueueControl = nullptr;
//protects the audioVisOutputQueue dynamic binding change at runtime (in DemodulatorMgr)
mutable std::mutex m_mutexAudioVisOutputQueue;
std::mutex m_mutexAudioVisOutputQueue;
};