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
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)
if (this->m_worker.joinable())
this->m_worker.join();
+
+ return true;
}
bool HandleExt::isStopped() const
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;