Skip to content

Commit bfd4b77

Browse files
committed
Introduce AsioConditionVariable
1 parent daadf8a commit bfd4b77

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

lib/base/io-engine.cpp

+24
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,30 @@ void AsioEvent::Wait(boost::asio::yield_context yc)
116116
m_Timer.async_wait(yc[ec]);
117117
}
118118

119+
AsioConditionVariable::AsioConditionVariable(boost::asio::io_context& io)
120+
: m_Timer(io)
121+
{
122+
m_Timer.expires_at(boost::posix_time::pos_infin);
123+
}
124+
125+
void AsioConditionVariable::Wait(boost::asio::yield_context yc)
126+
{
127+
boost::system::error_code ec;
128+
m_Timer.async_wait(yc[ec]);
129+
}
130+
131+
bool AsioConditionVariable::NotifyOne()
132+
{
133+
boost::system::error_code ec;
134+
return m_Timer.cancel_one(ec);
135+
}
136+
137+
size_t AsioConditionVariable::NotifyAll()
138+
{
139+
boost::system::error_code ec;
140+
return m_Timer.cancel(ec);
141+
}
142+
119143
/**
120144
* Cancels any pending timeout callback.
121145
*

lib/base/io-engine.hpp

+18
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,24 @@ class CpuBoundWork
5555
bool m_Done;
5656
};
5757

58+
/**
59+
* Condition variable which doesn't block I/O threads
60+
*
61+
* @ingroup base
62+
*/
63+
class AsioConditionVariable
64+
{
65+
public:
66+
AsioConditionVariable(boost::asio::io_context& io);
67+
68+
void Wait(boost::asio::yield_context yc);
69+
bool NotifyOne();
70+
size_t NotifyAll();
71+
72+
private:
73+
boost::asio::deadline_timer m_Timer;
74+
};
75+
5876
/**
5977
* Async I/O engine
6078
*

0 commit comments

Comments
 (0)