diff options
author | Dongsun Lee <ds73.lee@samsung.com> | 2017-03-19 13:58:53 +0900 |
---|---|---|
committer | Dong Sun Lee <ds73.lee@samsung.com> | 2017-03-20 23:33:21 -0700 |
commit | 7a29f6023922d7e11ca319941b59e6a3083895c8 (patch) | |
tree | fd65aa1f53852577ce9dfb55bddc5b1f6d413a0d | |
parent | 9d64087d82c52b04ca50b995f6604bd247424f73 (diff) | |
download | csr-framework-7a29f6023922d7e11ca319941b59e6a3083895c8.tar.gz csr-framework-7a29f6023922d7e11ca319941b59e6a3083895c8.tar.bz2 csr-framework-7a29f6023922d7e11ca319941b59e6a3083895c8.zip |
Check a task status inside HandleExt to handle concurrent issue
Change-Id: I46211a78f6b43cf8da0e001b3e511e765d981d70
Signed-off-by: Dongsun Lee <ds73.lee@samsung.com>
(cherry picked from commit 9f8be3f00c3dc9446f8b7abad887871ad3224804)
-rw-r--r-- | src/framework/client/content-screening.cpp | 4 | ||||
-rw-r--r-- | src/framework/client/handle-ext.cpp | 8 | ||||
-rw-r--r-- | src/framework/client/handle-ext.h | 2 |
3 files changed, 9 insertions, 5 deletions
diff --git a/src/framework/client/content-screening.cpp b/src/framework/client/content-screening.cpp index 17d518a..f682cc9 100644 --- a/src/framework/client/content-screening.cpp +++ b/src/framework/client/content-screening.cpp @@ -491,11 +491,9 @@ int csr_cs_cancel_scanning(csr_cs_context_h handle) auto hExt = reinterpret_cast<Client::HandleExt *>(handle); - if (!hExt->isRunning() || hExt->isStopped()) + if (!hExt->stop()) return CSR_ERROR_NO_TASK; - hExt->stop(); - return CSR_ERROR_NONE; EXCEPTION_SAFE_END diff --git a/src/framework/client/handle-ext.cpp b/src/framework/client/handle-ext.cpp index 66a9273..cf97924 100644 --- a/src/framework/client/handle-ext.cpp +++ b/src/framework/client/handle-ext.cpp @@ -47,12 +47,16 @@ void HandleExt::setStopFunc(std::function<void()> &&func) this->m_stopFunc = std::move(func); } -void HandleExt::stop() +bool HandleExt::stop() { DEBUG("Stop & join worker..."); { std::lock_guard<std::mutex> l(this->m_flagMutex); + + if (!this->m_isRunning || this->m_stop) + return false; + this->m_stop = true; if (this->m_stopFunc != nullptr) @@ -61,6 +65,8 @@ void HandleExt::stop() if (this->m_worker.joinable()) this->m_worker.join(); + + return true; } bool HandleExt::isStopped() const diff --git a/src/framework/client/handle-ext.h b/src/framework/client/handle-ext.h index 31efdf9..c9df5a8 100644 --- a/src/framework/client/handle-ext.h +++ b/src/framework/client/handle-ext.h @@ -38,7 +38,7 @@ public: void dispatchAsync(const std::shared_ptr<Task> &task); void setStopFunc(std::function<void()> &&func); - void stop(void); + bool stop(void); bool isStopped(void) const; bool isRunning(void) const; |