]> granicus.if.org Git - icinga2/commitdiff
Allow CpuBoundWork to be done before end of scope
authorAlexander A. Klimov <alexander.klimov@icinga.com>
Thu, 14 Feb 2019 12:10:04 +0000 (13:10 +0100)
committerAlexander A. Klimov <alexander.klimov@icinga.com>
Mon, 1 Apr 2019 09:40:14 +0000 (11:40 +0200)
lib/base/io-engine.cpp
lib/base/io-engine.hpp

index e1aeeb094f534b38507cdded8b6bacb1b2e99b02..482d5717631c5197c3eb09c7f32b12fd650a578f 100644 (file)
@@ -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<std::unique_ptr<IoEngine>> IoEngine::m_Instance ([]() { return std::unique_ptr<IoEngine>(new IoEngine()); });
index df84df9cef5853bd67d36b5f05986ab1227936a3..efeb56f997746ea1308a55d1a03b570a6aa16936 100644 (file)
@@ -48,6 +48,11 @@ public:
        CpuBoundWork& operator=(const CpuBoundWork&) = delete;
        CpuBoundWork& operator=(CpuBoundWork&&) = delete;
        ~CpuBoundWork();
+
+       void Done();
+
+private:
+       bool m_Done;
 };
 
 /**