diff options
author | Jonathan Reams <jbreams@mongodb.com> | 2016-09-07 14:18:23 -0400 |
---|---|---|
committer | Jonathan Reams <jbreams@mongodb.com> | 2016-09-16 10:18:34 -0400 |
commit | e3b42fd990070f48c11b233cec0c198098d1a48f (patch) | |
tree | 464665d664b18fe709ccf5e9d039a424b9489a12 /src/mongo/scripting/deadline_monitor.h | |
parent | 7693fa59c4470db729d85af99fb9cc3b264fa8c8 (diff) | |
download | mongo-e3b42fd990070f48c11b233cec0c198098d1a48f.tar.gz |
SERVER-26002 Make sure javascript sleep isn't interrupted
Diffstat (limited to 'src/mongo/scripting/deadline_monitor.h')
-rw-r--r-- | src/mongo/scripting/deadline_monitor.h | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/src/mongo/scripting/deadline_monitor.h b/src/mongo/scripting/deadline_monitor.h index cd5c532c974..127bc81288d 100644 --- a/src/mongo/scripting/deadline_monitor.h +++ b/src/mongo/scripting/deadline_monitor.h @@ -30,6 +30,7 @@ #include <cstdint> #include "mongo/base/disallow_copying.h" +#include "mongo/platform/atomic_word.h" #include "mongo/platform/unordered_map.h" #include "mongo/stdx/condition_variable.h" #include "mongo/stdx/mutex.h" @@ -39,6 +40,9 @@ namespace mongo { +// Returns the current interrupt interval from the setParameter value +int getScriptingEngineInterruptInterval(); + /** * DeadlineMonitor * @@ -133,12 +137,21 @@ private: while (!_inShutdown) { // get the next interval to wait const Date_t now = Date_t::now(); + const auto interruptInterval = Milliseconds{getScriptingEngineInterruptInterval()}; + + if (now - lastInterruptCycle > interruptInterval) { + for (const auto& task : _tasks) { + if (task.second > now) + task.first->interrupt(); + } + lastInterruptCycle = now; + } // wait for a task to be added or a deadline to expire if (_nearestDeadlineWallclock > now) { if (_nearestDeadlineWallclock == Date_t::max() || - _nearestDeadlineWallclock - now > Seconds{1}) { - _newDeadlineAvailable.wait_for(lk, Seconds{1}.toSystemDuration()); + _nearestDeadlineWallclock - now > interruptInterval) { + _newDeadlineAvailable.wait_for(lk, interruptInterval.toSystemDuration()); } else { _newDeadlineAvailable.wait_until(lk, _nearestDeadlineWallclock.toSystemTimePoint()); @@ -162,13 +175,6 @@ private: ++i; } } - - if (now - lastInterruptCycle > Seconds{1}) { - for (auto it : _tasks) { - it.first->interrupt(); - } - lastInterruptCycle = now; - } } } |