Allow CpuBoundWork to be done before end of scope

This commit is contained in:
Alexander A. Klimov 2019-02-14 13:10:04 +01:00
parent e21956e26e
commit 2d7714802d
2 changed files with 18 additions and 1 deletions

View 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()); });

View File

@ -48,6 +48,11 @@ public:
CpuBoundWork& operator=(const CpuBoundWork&) = delete;
CpuBoundWork& operator=(CpuBoundWork&&) = delete;
~CpuBoundWork();
void Done();
private:
bool m_Done;
};
/**