summaryrefslogtreecommitdiffstats
path: root/src/uscxml/interpreter/BasicEventQueue.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/uscxml/interpreter/BasicEventQueue.cpp')
-rw-r--r--src/uscxml/interpreter/BasicEventQueue.cpp15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/uscxml/interpreter/BasicEventQueue.cpp b/src/uscxml/interpreter/BasicEventQueue.cpp
index 5d3fa2d..ee2346d 100644
--- a/src/uscxml/interpreter/BasicEventQueue.cpp
+++ b/src/uscxml/interpreter/BasicEventQueue.cpp
@@ -31,13 +31,20 @@ BasicEventQueue::BasicEventQueue() {
BasicEventQueue::~BasicEventQueue() {
}
-Event BasicEventQueue::dequeue(bool blocking) {
+Event BasicEventQueue::dequeue(size_t blockMs) {
std::lock_guard<std::recursive_mutex> lock(_mutex);
- if (blocking) {
- while (_queue.empty()) {
- _cond.wait(_mutex);
+
+ if (blockMs > 0) {
+ // block for given milliseconds or until queue is filled
+ std::chrono::time_point<std::chrono::system_clock> end, now;
+ now = std::chrono::system_clock::now();
+ end = now + std::chrono::milliseconds(blockMs);
+
+ while (std::chrono::system_clock::now() < end && _queue.empty()) {
+ _cond.wait_for(_mutex, std::chrono::system_clock::now() - end);
}
}
+
if (_queue.size() > 0) {
Event event = _queue.front();
_queue.pop_front();