Mercurial > hg > orthanc
changeset 5018:eb8ca3403983 lua-heart-beat
fix: lock mutex when accessing state in HeartBeatThread
author | Alain Mazy <am@osimis.io> |
---|---|
date | Tue, 14 Jun 2022 17:19:16 +0200 |
parents | 0d61efc6256c |
children | 4be5a8b0af1d e13c76454e0a |
files | OrthancServer/Sources/LuaScripting.cpp |
diffstat | 1 files changed, 7 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/OrthancServer/Sources/LuaScripting.cpp Mon Jun 13 18:54:49 2022 +0200 +++ b/OrthancServer/Sources/LuaScripting.cpp Tue Jun 14 17:19:16 2022 +0200 @@ -793,12 +793,13 @@ boost::posix_time::ptime next = boost::posix_time::microsec_clock::universal_time() + PERIODICITY; - while (that->state_ != State_Done) + bool shouldStop = false; + + while (!shouldStop) { boost::this_thread::sleep(boost::posix_time::milliseconds(sleepDelay)); - if (that->state_ != State_Done && - boost::posix_time::microsec_clock::universal_time() >= next) + if (boost::posix_time::microsec_clock::universal_time() >= next) { LuaScripting::Lock lock(*that); @@ -810,6 +811,9 @@ next = boost::posix_time::microsec_clock::universal_time() + PERIODICITY; } + + boost::recursive_mutex::scoped_lock lock(that->mutex_); + shouldStop = that->state_ == State_Done; } }