Commit 5fb85c67 authored by Laurent Claustre's avatar Laurent Claustre

Merge branch '4-fix-poolthreadmgr-singleton-implementation' into 'master'

Resolve "Fix PoolThreadMgr singleton implementation"

Closes #4

See merge request !21
parents 4b922ed6 da81a7f2
Pipeline #8631 passed with stages
in 6 minutes and 38 seconds
......@@ -47,9 +47,7 @@ class DLL_EXPORT PoolThreadMgr
public:
typedef std::pair<int, int> TaskPriority;
PoolThreadMgr() = default;
~PoolThreadMgr() = default;
static PoolThreadMgr &get() throw();
static PoolThreadMgr &get();
void addProcess(TaskMgr *aProcess, bool lock = true);
void removeProcess(TaskMgr *aProcess, bool lock = true);
......@@ -63,6 +61,12 @@ class DLL_EXPORT PoolThreadMgr
void quit();
private:
// Thread safe Singleton (guaranted in C++11)
PoolThreadMgr() : _stopFlag(false), _suspendFlag(false), _runningThread(0), _taskMgr(NULL) {}
~PoolThreadMgr()= default;
PoolThreadMgr(const PoolThreadMgr&)= delete;
PoolThreadMgr& operator=(const PoolThreadMgr&)= delete;
struct cmp
{
bool operator()(const TaskPriority &a, const TaskPriority &b)
......
......@@ -194,9 +194,12 @@ void PoolThreadMgr::_createProcessThread(size_t aNumber)
m_threads.emplace_back(_run, this);
}
PoolThreadMgr &PoolThreadMgr::get() throw()
PoolThreadMgr &PoolThreadMgr::get()
{
static PoolThreadMgr singleton;
// Defere the creation of the threads to the first call of get
std::call_once(PoolThreadMgr::init_flag, []() { _processMgrPt->_createProcessThread(NB_DEFAULT_THREADS); });
return *_processMgrPt;
std::call_once(PoolThreadMgr::init_flag, []() { singleton._createProcessThread(NB_DEFAULT_THREADS); });
return singleton;
}
......@@ -482,6 +482,7 @@ class PoolThreadMgr
private:
PoolThreadMgr(const PoolThreadMgr&);
~PoolThreadMgr();
};
%Feature BPM_SUPPORT
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment