From: Changgyu Choi Date: Mon, 30 Dec 2024 08:28:42 +0000 (+0900) Subject: Fix crash issue X-Git-Tag: accepted/tizen/unified/20250107.061425~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F08%2F317308%2F2;p=platform%2Fcore%2Fappfw%2Frpc-port.git Fix crash issue memory allocation must not be performed at the end of the process. Change-Id: I41163045f3ffa9d3addb5c3cb8aa4a5f65536d48 Signed-off-by: Changgyu Choi --- diff --git a/src/rpc-port/cynara_thread.cc b/src/rpc-port/cynara_thread.cc index fbb2ee8..fe01cfb 100644 --- a/src/rpc-port/cynara_thread.cc +++ b/src/rpc-port/cynara_thread.cc @@ -30,13 +30,20 @@ Job::Type Job::Do() { 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; } @@ -54,7 +61,7 @@ void CynaraThread::Dispose() { done_ = true; cond_var_.notify_one(); } - thread_.join(); + thread_->join(); disposed_ = true; } @@ -73,6 +80,8 @@ void CynaraThread::ThreadRun() { void CynaraThread::Push(std::shared_ptr job) { std::lock_guard lock(mutex_); + Init(); + queue_.push(std::move(job)); cond_var_.notify_one(); } diff --git a/src/rpc-port/cynara_thread.hh b/src/rpc-port/cynara_thread.hh index acec34f..97baca5 100644 --- a/src/rpc-port/cynara_thread.hh +++ b/src/rpc-port/cynara_thread.hh @@ -50,21 +50,22 @@ class Job { class CynaraThread { public: static CynaraThread& GetInst(); + CynaraThread(); CynaraThread(CynaraThread&) = delete; CynaraThread& operator=(CynaraThread&) = delete; ~CynaraThread(); void Push(std::shared_ptr job); + void Init(); void Dispose(); private: - CynaraThread(); void ThreadRun(); std::shared_ptr WaitAndPop(); bool disposed_ = true; std::atomic done_{false}; - std::thread thread_; + std::unique_ptr thread_; std::queue> queue_; mutable std::mutex mutex_; std::condition_variable cond_var_;