Mercurial > hg > orthanc
diff OrthancServer/Sources/LuaScripting.cpp @ 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 | 3d0a084e1ace bafef43b6f37 |
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; } }