diff options
author | Stefan Radomski <github@mintwerk.de> | 2016-06-13 08:52:55 (GMT) |
---|---|---|
committer | Stefan Radomski <github@mintwerk.de> | 2016-06-13 08:52:55 (GMT) |
commit | 053e9bc973fbe88fc41a34064ffadc0deabac58d (patch) | |
tree | 6aeee286577159ffcb612d41972a9d18ab685c6d /src/uscxml/interpreter/BasicEventQueue.cpp | |
parent | 6e13c7b6e0888323223afd5d2e36e86243df57af (diff) | |
download | uscxml-053e9bc973fbe88fc41a34064ffadc0deabac58d.zip uscxml-053e9bc973fbe88fc41a34064ffadc0deabac58d.tar.gz uscxml-053e9bc973fbe88fc41a34064ffadc0deabac58d.tar.bz2 |
Fixed dozens of memory leaks
Diffstat (limited to 'src/uscxml/interpreter/BasicEventQueue.cpp')
-rw-r--r-- | src/uscxml/interpreter/BasicEventQueue.cpp | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/src/uscxml/interpreter/BasicEventQueue.cpp b/src/uscxml/interpreter/BasicEventQueue.cpp index ee2346d..7309392 100644 --- a/src/uscxml/interpreter/BasicEventQueue.cpp +++ b/src/uscxml/interpreter/BasicEventQueue.cpp @@ -35,13 +35,26 @@ Event BasicEventQueue::dequeue(size_t blockMs) { std::lock_guard<std::recursive_mutex> lock(_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); + // block for given milliseconds or until queue is filled + std::chrono::time_point<std::chrono::system_clock> updated, now; + std::chrono::milliseconds remain; + + if (blockMs > std::chrono::system_clock::duration::max().count()) { + blockMs = std::chrono::system_clock::duration::max().count(); + } + + updated = now = std::chrono::system_clock::now(); + remain = std::chrono::milliseconds(blockMs); + + while (remain.count() > 0 && _queue.empty()) { + _cond.wait_for(_mutex, remain); + + now = std::chrono::system_clock::now(); + + auto elapsed = now - updated; + remain -= std::chrono::duration_cast<std::chrono::milliseconds>(elapsed); + updated = now; } } |