OpenDaVINCI  4.15.3
DisposalService.h
Go to the documentation of this file.
1 
20 #ifndef OPENDAVINCI_CORE_WRAPPER_DISPOSALSERVICE_H_
21 #define OPENDAVINCI_CORE_WRAPPER_DISPOSALSERVICE_H_
22 
23 #include <deque>
24 #include <memory>
25 
27 #include <memory>
30 
31 namespace odcore {
32  namespace wrapper {
33 
34 class Disposable;
35 class Mutex;
36 class Thread;
37 
38  using namespace std;
39 
44  private:
51 
57  DisposalService& operator=(const DisposalService &);
58 
59  protected:
61 
62  public:
63  virtual ~DisposalService();
64 
70  static DisposalService& getInstance();
71 
76  void cleanUpFinally();
77 
84  void addDisposableForRegularRemoval(Disposable **d);
85 
92  void addDisposableForFinalRemoval(Disposable **d);
93 
97  void cleanUpImmediately();
98 
99  private:
100  static unique_ptr<Mutex> m_singletonMutex;
101  static DisposalService *m_singleton;
102 
103  std::shared_ptr<Condition> m_queueCondition;
104  unique_ptr<Mutex> m_finalRemovalMutex;
105  unique_ptr<Mutex> m_queueMutex;
106  deque<Disposable**> m_queueForRegularRemoval;
107  deque<Disposable**> m_queueForFinalRemoval;
108 
109  unique_ptr<Thread> m_thread;
110 
114  class QueueCleaner : public Runnable {
115  private:
121  QueueCleaner(const QueueCleaner &);
122 
128  QueueCleaner& operator=(const QueueCleaner &);
129 
130  public:
139  QueueCleaner(std::shared_ptr<Condition> condition, Mutex &finalRemovalMutex, Mutex &mutex, deque<Disposable**> &queue);
140 
141  virtual ~QueueCleaner();
142 
148  void setRunning(const bool &b);
149 
150  private:
151  std::shared_ptr<Condition> m_queueCondition;
152  Mutex &m_finalRemovalMutex;
153  Mutex &m_queueMutex;
154  deque<Disposable**> &m_queue;
155 
156  unique_ptr<Mutex> m_threadStateMutex;
157  bool m_threadState;
158 
159  virtual void run();
160 
161  virtual bool isRunning();
162  } *m_queueCleaner;
163  };
164 
165  }
166 } // odcore::wrapper
167 
168 #endif /*OPENDAVINCI_CORE_WRAPPER_DISPOSALSERVICE_H_*/
Definition: base/Mutex.h:49
#define OPENDAVINCI_API
Definition: opendavinci.h:67
Definition: Runnable.h:35
Definition: DisposalService.h:43
Definition: Disposable.h:31