Mercurial > hg > orthanc
changeset 5027:06ffe03d008a
merge
author | Alain Mazy <am@osimis.io> |
---|---|
date | Tue, 21 Jun 2022 11:00:14 +0200 |
parents | bafef43b6f37 (current diff) c8c98389080f (diff) |
children | 1ff06e0ea532 |
files | OrthancServer/Sources/LuaScripting.cpp |
diffstat | 1 files changed, 13 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/OrthancServer/Sources/LuaScripting.cpp Tue Jun 21 10:57:37 2022 +0200 +++ b/OrthancServer/Sources/LuaScripting.cpp Tue Jun 21 11:00:14 2022 +0200 @@ -34,6 +34,8 @@ #include <OrthancServerResources.h> +static const char* ON_HEART_BEAT = "OnHeartBeat"; + namespace Orthanc { @@ -785,11 +787,11 @@ void LuaScripting::HeartBeatThread(LuaScripting* that) { - static const boost::posix_time::time_duration PERIODICITY = + static const unsigned int GRANULARITY = 100; // In milliseconds + + const boost::posix_time::time_duration PERIODICITY = boost::posix_time::seconds(that->heartBeatPeriod_); - unsigned int sleepDelay = 100; - boost::posix_time::ptime next = boost::posix_time::microsec_clock::universal_time() + PERIODICITY; @@ -797,25 +799,26 @@ while (!shouldStop) { - boost::this_thread::sleep(boost::posix_time::milliseconds(sleepDelay)); + boost::this_thread::sleep(boost::posix_time::milliseconds(GRANULARITY)); if (boost::posix_time::microsec_clock::universal_time() >= next) { LuaScripting::Lock lock(*that); - if (lock.GetLua().IsExistingFunction("OnHeartBeat")) + if (lock.GetLua().IsExistingFunction(ON_HEART_BEAT)) { - LuaFunctionCall call(lock.GetLua(), "OnHeartBeat"); + LuaFunctionCall call(lock.GetLua(), ON_HEART_BEAT); call.Execute(); } next = boost::posix_time::microsec_clock::universal_time() + PERIODICITY; } - boost::recursive_mutex::scoped_lock lock(that->mutex_); - shouldStop = that->state_ == State_Done; + { + boost::recursive_mutex::scoped_lock lock(that->mutex_); + shouldStop = (that->state_ == State_Done); + } } - } void LuaScripting::EventThread(LuaScripting* that) @@ -867,7 +870,7 @@ LuaScripting::Lock luaLock(*this); - if (heartBeatPeriod_ > 0 && luaLock.GetLua().IsExistingFunction("OnHeartBeat")) + if (heartBeatPeriod_ > 0 && luaLock.GetLua().IsExistingFunction(ON_HEART_BEAT)) { LOG(INFO) << "Starting the Lua HeartBeat thread with a period of " << heartBeatPeriod_ << " seconds"; heartBeatThread_ = boost::thread(HeartBeatThread, this);