From: Alexander A. Klimov Date: Thu, 14 Feb 2019 12:10:04 +0000 (+0100) Subject: Allow CpuBoundWork to be done before end of scope X-Git-Tag: v2.11.0-rc1~174^2~57 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2d7714802d661e02e3c8ac1f7410cc7ffe63780a;p=icinga2 Allow CpuBoundWork to be done before end of scope --- diff --git a/lib/base/io-engine.cpp b/lib/base/io-engine.cpp index e1aeeb094..482d57176 100644 --- a/lib/base/io-engine.cpp +++ b/lib/base/io-engine.cpp @@ -31,6 +31,7 @@ using namespace icinga; CpuBoundWork::CpuBoundWork(boost::asio::yield_context yc) + : m_Done(false) { auto& ioEngine (IoEngine::Get()); @@ -49,7 +50,18 @@ CpuBoundWork::CpuBoundWork(boost::asio::yield_context yc) CpuBoundWork::~CpuBoundWork() { - IoEngine::Get().m_CpuBoundSemaphore.fetch_add(1); + if (!m_Done) { + IoEngine::Get().m_CpuBoundSemaphore.fetch_add(1); + } +} + +void CpuBoundWork::Done() +{ + if (!m_Done) { + IoEngine::Get().m_CpuBoundSemaphore.fetch_add(1); + + m_Done = true; + } } LazyInit> IoEngine::m_Instance ([]() { return std::unique_ptr(new IoEngine()); }); diff --git a/lib/base/io-engine.hpp b/lib/base/io-engine.hpp index df84df9ce..efeb56f99 100644 --- a/lib/base/io-engine.hpp +++ b/lib/base/io-engine.hpp @@ -48,6 +48,11 @@ public: CpuBoundWork& operator=(const CpuBoundWork&) = delete; CpuBoundWork& operator=(CpuBoundWork&&) = delete; ~CpuBoundWork(); + + void Done(); + +private: + bool m_Done; }; /**