Mercurial > hg > orthanc
comparison 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 |
comparison
equal
deleted
inserted
replaced
5017:0d61efc6256c | 5018:eb8ca3403983 |
---|---|
791 unsigned int sleepDelay = 100; | 791 unsigned int sleepDelay = 100; |
792 | 792 |
793 boost::posix_time::ptime next = | 793 boost::posix_time::ptime next = |
794 boost::posix_time::microsec_clock::universal_time() + PERIODICITY; | 794 boost::posix_time::microsec_clock::universal_time() + PERIODICITY; |
795 | 795 |
796 while (that->state_ != State_Done) | 796 bool shouldStop = false; |
797 | |
798 while (!shouldStop) | |
797 { | 799 { |
798 boost::this_thread::sleep(boost::posix_time::milliseconds(sleepDelay)); | 800 boost::this_thread::sleep(boost::posix_time::milliseconds(sleepDelay)); |
799 | 801 |
800 if (that->state_ != State_Done && | 802 if (boost::posix_time::microsec_clock::universal_time() >= next) |
801 boost::posix_time::microsec_clock::universal_time() >= next) | |
802 { | 803 { |
803 LuaScripting::Lock lock(*that); | 804 LuaScripting::Lock lock(*that); |
804 | 805 |
805 if (lock.GetLua().IsExistingFunction("OnHeartBeat")) | 806 if (lock.GetLua().IsExistingFunction("OnHeartBeat")) |
806 { | 807 { |
808 call.Execute(); | 809 call.Execute(); |
809 } | 810 } |
810 | 811 |
811 next = boost::posix_time::microsec_clock::universal_time() + PERIODICITY; | 812 next = boost::posix_time::microsec_clock::universal_time() + PERIODICITY; |
812 } | 813 } |
814 | |
815 boost::recursive_mutex::scoped_lock lock(that->mutex_); | |
816 shouldStop = that->state_ == State_Done; | |
813 } | 817 } |
814 | 818 |
815 } | 819 } |
816 | 820 |
817 void LuaScripting::EventThread(LuaScripting* that) | 821 void LuaScripting::EventThread(LuaScripting* that) |