mirror of
				https://github.com/Icinga/icinga2.git
				synced 2025-11-03 21:25:56 +01:00 
			
		
		
		
	Allow CpuBoundWork to be done before end of scope
This commit is contained in:
		
							parent
							
								
									e21956e26e
								
							
						
					
					
						commit
						2d7714802d
					
				@ -31,6 +31,7 @@
 | 
			
		||||
using namespace icinga;
 | 
			
		||||
 | 
			
		||||
CpuBoundWork::CpuBoundWork(boost::asio::yield_context yc)
 | 
			
		||||
	: m_Done(false)
 | 
			
		||||
{
 | 
			
		||||
	auto& ioEngine (IoEngine::Get());
 | 
			
		||||
 | 
			
		||||
@ -49,8 +50,19 @@ CpuBoundWork::CpuBoundWork(boost::asio::yield_context yc)
 | 
			
		||||
 | 
			
		||||
CpuBoundWork::~CpuBoundWork()
 | 
			
		||||
{
 | 
			
		||||
	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()); });
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -48,6 +48,11 @@ public:
 | 
			
		||||
	CpuBoundWork& operator=(const CpuBoundWork&) = delete;
 | 
			
		||||
	CpuBoundWork& operator=(CpuBoundWork&&) = delete;
 | 
			
		||||
	~CpuBoundWork();
 | 
			
		||||
 | 
			
		||||
	void Done();
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
	bool m_Done;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user