mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-26 23:24:09 +02:00
Introduce AsioDualEvent
This commit is contained in:
parent
331ba1f661
commit
060d8b185e
@ -146,6 +146,33 @@ void AsioEvent::Wait(boost::asio::yield_context yc)
|
|||||||
m_Timer.async_wait(yc[ec]);
|
m_Timer.async_wait(yc[ec]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AsioDualEvent::AsioDualEvent(boost::asio::io_context& io, bool init)
|
||||||
|
: m_IsTrue(io, init), m_IsFalse(io, !init)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void AsioDualEvent::Set()
|
||||||
|
{
|
||||||
|
m_IsTrue.Set();
|
||||||
|
m_IsFalse.Clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
void AsioDualEvent::Clear()
|
||||||
|
{
|
||||||
|
m_IsTrue.Clear();
|
||||||
|
m_IsFalse.Set();
|
||||||
|
}
|
||||||
|
|
||||||
|
void AsioDualEvent::WaitForSet(boost::asio::yield_context yc)
|
||||||
|
{
|
||||||
|
m_IsTrue.Wait(std::move(yc));
|
||||||
|
}
|
||||||
|
|
||||||
|
void AsioDualEvent::WaitForClear(boost::asio::yield_context yc)
|
||||||
|
{
|
||||||
|
m_IsFalse.Wait(std::move(yc));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cancels any pending timeout callback.
|
* Cancels any pending timeout callback.
|
||||||
*
|
*
|
||||||
|
@ -175,6 +175,26 @@ private:
|
|||||||
boost::asio::deadline_timer m_Timer;
|
boost::asio::deadline_timer m_Timer;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Like AsioEvent, which only allows waiting for an event to be set, but additionally supports waiting for clearing
|
||||||
|
*
|
||||||
|
* @ingroup base
|
||||||
|
*/
|
||||||
|
class AsioDualEvent
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
AsioDualEvent(boost::asio::io_context& io, bool init = false);
|
||||||
|
|
||||||
|
void Set();
|
||||||
|
void Clear();
|
||||||
|
|
||||||
|
void WaitForSet(boost::asio::yield_context yc);
|
||||||
|
void WaitForClear(boost::asio::yield_context yc);
|
||||||
|
|
||||||
|
private:
|
||||||
|
AsioEvent m_IsTrue, m_IsFalse;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* I/O timeout emulator
|
* I/O timeout emulator
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user