diff options
author | Stefan Radomski <github@mintwerk.de> | 2016-05-26 10:36:49 (GMT) |
---|---|---|
committer | Stefan Radomski <github@mintwerk.de> | 2016-05-26 10:36:49 (GMT) |
commit | 6e13c7b6e0888323223afd5d2e36e86243df57af (patch) | |
tree | f558fd45fa499c8bc95041554ecad6be1bf788c1 /src/uscxml/interpreter/BasicEventQueue.cpp | |
parent | f6714b1484b641ea61053350b7d156d2da760b8b (diff) | |
download | uscxml-6e13c7b6e0888323223afd5d2e36e86243df57af.zip uscxml-6e13c7b6e0888323223afd5d2e36e86243df57af.tar.gz uscxml-6e13c7b6e0888323223afd5d2e36e86243df57af.tar.bz2 |
Minor polishing for Java bindings and first draft of JEXL datamodel
Diffstat (limited to 'src/uscxml/interpreter/BasicEventQueue.cpp')
-rw-r--r-- | src/uscxml/interpreter/BasicEventQueue.cpp | 15 |
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(); |