| 178 | } |
| 179 | |
| 180 | Dictionary::Ptr EventsInbox::Shift(boost::asio::yield_context yc, double timeout) |
| 181 | { |
| 182 | std::unique_lock<std::mutex> lock (m_Mutex, std::defer_lock); |
| 183 | |
| 184 | m_Timer.expires_at(boost::posix_time::neg_infin); |
| 185 | |
| 186 | { |
| 187 | boost::system::error_code ec; |
| 188 | |
| 189 | while (!lock.try_lock()) { |
| 190 | m_Timer.async_wait(yc[ec]); |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | if (m_Queue.empty()) { |
| 195 | m_Timer.expires_from_now(boost::posix_time::milliseconds((unsigned long)(timeout * 1000.0))); |
| 196 | lock.unlock(); |
| 197 | |
| 198 | { |
| 199 | boost::system::error_code ec; |
| 200 | m_Timer.async_wait(yc[ec]); |
| 201 | |
| 202 | while (!lock.try_lock()) { |
| 203 | m_Timer.async_wait(yc[ec]); |
| 204 | } |
| 205 | } |
| 206 | |
| 207 | if (m_Queue.empty()) { |
| 208 | return nullptr; |
| 209 | } |
| 210 | } |
| 211 | |
| 212 | auto event (std::move(m_Queue.front())); |
| 213 | m_Queue.pop(); |
| 214 | return event; |
| 215 | } |
| 216 | |
| 217 | EventsSubscriber::EventsSubscriber(std::set<EventType> types, String filter, const String& filterSource) |
| 218 | : m_Types(std::move(types)), m_Inbox(new EventsInbox(std::move(filter), filterSource)) |