mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-23 13:45:04 +02:00
Introduce AsioConditionVariable
This commit is contained in:
parent
659bb9e03a
commit
1e24adf247
@ -143,6 +143,30 @@ void AsioDualEvent::WaitForClear(boost::asio::yield_context yc)
|
||||
m_IsFalse.Wait(std::move(yc));
|
||||
}
|
||||
|
||||
AsioConditionVariable::AsioConditionVariable(boost::asio::io_context& io)
|
||||
: m_Timer(io)
|
||||
{
|
||||
m_Timer.expires_at(boost::posix_time::pos_infin);
|
||||
}
|
||||
|
||||
void AsioConditionVariable::Wait(boost::asio::yield_context yc)
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
m_Timer.async_wait(yc[ec]);
|
||||
}
|
||||
|
||||
bool AsioConditionVariable::NotifyOne()
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
return m_Timer.cancel_one(ec);
|
||||
}
|
||||
|
||||
size_t AsioConditionVariable::NotifyAll()
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
return m_Timer.cancel(ec);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancels any pending timeout callback.
|
||||
*
|
||||
|
@ -55,6 +55,24 @@ private:
|
||||
bool m_Done;
|
||||
};
|
||||
|
||||
/**
|
||||
* Condition variable which doesn't block I/O threads
|
||||
*
|
||||
* @ingroup base
|
||||
*/
|
||||
class AsioConditionVariable
|
||||
{
|
||||
public:
|
||||
AsioConditionVariable(boost::asio::io_context& io);
|
||||
|
||||
void Wait(boost::asio::yield_context yc);
|
||||
bool NotifyOne();
|
||||
size_t NotifyAll();
|
||||
|
||||
private:
|
||||
boost::asio::deadline_timer m_Timer;
|
||||
};
|
||||
|
||||
/**
|
||||
* Async I/O engine
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user