Threads vs. Queues lifetimes, cleanups.

- Ideally Queues must outlive the threads using them, but wasn't done so. Yes, std::shared_ptr them!
- Now queues are always valid in the context of the threads using them.
- No longer need tedious queues deallocation by the original owner.
- Misc cleanups.
This commit is contained in:
vsonnier
2017-08-13 18:49:47 +02:00
parent 98c7c30aee
commit c64baab99d
31 changed files with 162 additions and 153 deletions
+8 -8
View File
@@ -175,17 +175,17 @@ public:
//If wait < 0, the wait in infinite until the thread dies.
bool isTerminated(int waitMs = 0);
virtual void onBindOutput(std::string name, ThreadQueueBase* threadQueue);
virtual void onBindInput(std::string name, ThreadQueueBase* threadQueue);
virtual void onBindOutput(std::string name, ThreadQueueBasePtr threadQueue);
virtual void onBindInput(std::string name, ThreadQueueBasePtr threadQueue);
void setInputQueue(std::string qname, ThreadQueueBase *threadQueue);
ThreadQueueBase *getInputQueue(std::string qname);
void setOutputQueue(std::string qname, ThreadQueueBase *threadQueue);
ThreadQueueBase *getOutputQueue(std::string qname);
void setInputQueue(std::string qname, ThreadQueueBasePtr threadQueue);
ThreadQueueBasePtr getInputQueue(std::string qname);
void setOutputQueue(std::string qname, ThreadQueueBasePtr threadQueue);
ThreadQueueBasePtr getOutputQueue(std::string qname);
protected:
std::map<std::string, ThreadQueueBase *, map_string_less> input_queues;
std::map<std::string, ThreadQueueBase *, map_string_less> output_queues;
std::map<std::string, ThreadQueueBasePtr, map_string_less> input_queues;
std::map<std::string, ThreadQueueBasePtr, map_string_less> output_queues;
//this protects against concurrent changes in input/output bindings: get/set/Input/OutPutQueue
std::mutex m_queue_bindings_mutex;