memory allocation must not be performed at the end of the process.
Change-Id: I41163045f3ffa9d3addb5c3cb8aa4a5f65536d48
Signed-off-by: Changgyu Choi <changyu.choi@samsung.com>
return cb_();
}
+static CynaraThread* inst = new CynaraThread();
+
CynaraThread& CynaraThread::GetInst() {
- static CynaraThread* inst = new CynaraThread();
return *inst;
}
CynaraThread::CynaraThread() {
- thread_ = std::thread([this]() { ThreadRun(); });
+}
+
+void CynaraThread::Init() {
+ if (!disposed_)
+ return;
+
+ thread_.reset(new std::thread([this]() { ThreadRun(); }));
disposed_ = false;
}
done_ = true;
cond_var_.notify_one();
}
- thread_.join();
+ thread_->join();
disposed_ = true;
}
void CynaraThread::Push(std::shared_ptr<Job> job) {
std::lock_guard<std::mutex> lock(mutex_);
+ Init();
+
queue_.push(std::move(job));
cond_var_.notify_one();
}
class CynaraThread {
public:
static CynaraThread& GetInst();
+ CynaraThread();
CynaraThread(CynaraThread&) = delete;
CynaraThread& operator=(CynaraThread&) = delete;
~CynaraThread();
void Push(std::shared_ptr<Job> job);
+ void Init();
void Dispose();
private:
- CynaraThread();
void ThreadRun();
std::shared_ptr<Job> WaitAndPop();
bool disposed_ = true;
std::atomic<bool> done_{false};
- std::thread thread_;
+ std::unique_ptr<std::thread> thread_;
std::queue<std::shared_ptr<Job>> queue_;
mutable std::mutex mutex_;
std::condition_variable cond_var_;