# HG changeset patch # User Alain Mazy # Date 1655802014 -7200 # Node ID 06ffe03d008a6c8f0ef5f7ca085c58759262e43f # Parent bafef43b6f37559e12dae80f30db001d587e26ae# Parent c8c98389080ff21fe4d7c1cc7cebbbd3b82a3142 merge diff -r bafef43b6f37 -r 06ffe03d008a OrthancServer/Sources/LuaScripting.cpp --- 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 +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);