mirror of
https://github.com/Icinga/icinga2.git
synced 2025-09-24 10:17:59 +02:00
Introduce AsioConditionVariable
This commit is contained in:
parent
11f0a1d34a
commit
bb380d33e0
@ -116,6 +116,30 @@ void AsioEvent::Wait(boost::asio::yield_context yc)
|
||||
m_Timer.async_wait(yc[ec]);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
void Timeout::Cancel()
|
||||
{
|
||||
m_Cancelled.store(true);
|
||||
|
@ -145,6 +145,24 @@ private:
|
||||
boost::asio::deadline_timer m_Timer;
|
||||
};
|
||||
|
||||
/**
|
||||
* 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;
|
||||
};
|
||||
|
||||
/**
|
||||
* I/O timeout emulator
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user