mirror of
https://github.com/Icinga/icinga2.git
synced 2026-05-28 04:12:13 -04:00
Introduce AsioConditionVariable
This commit is contained in:
parent
e03db5f71d
commit
c40c15ee11
2 changed files with 41 additions and 0 deletions
|
|
@ -142,6 +142,28 @@ 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(decltype(m_Timer)::clock_type::time_point::max());
|
||||
}
|
||||
|
||||
void AsioConditionVariable::Wait(boost::asio::yield_context yc)
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
m_Timer.async_wait(yc[ec]);
|
||||
}
|
||||
|
||||
bool AsioConditionVariable::NotifyOne()
|
||||
{
|
||||
return m_Timer.cancel_one();
|
||||
}
|
||||
|
||||
size_t AsioConditionVariable::NotifyAll()
|
||||
{
|
||||
return m_Timer.cancel();
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancels any pending timeout callback.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@
|
|||
#include <boost/asio/io_context.hpp>
|
||||
#include <boost/asio/io_context_strand.hpp>
|
||||
#include <boost/asio/spawn.hpp>
|
||||
#include <boost/asio/steady_timer.hpp>
|
||||
|
||||
#if BOOST_VERSION >= 108700
|
||||
# include <boost/asio/detached.hpp>
|
||||
|
|
@ -56,6 +57,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::steady_timer m_Timer;
|
||||
};
|
||||
|
||||
/**
|
||||
* Async I/O engine
|
||||
*
|
||||
|
|
|
|||
Loading…
Reference in a new issue