3131 * @note rating: red
3232 */
3333
34- #include < string>
34+ #include < condition_variable>
35+ #include < ctime>
3536#include < fstream>
36- #include < sstream>
3737#include < iomanip>
38- #include < ctime>
3938#include < iostream>
39+ #include < sstream>
40+ #include < string>
41+ #include < thread>
4042
4143#include " CompilerWarnings.hh"
4244IGNORE_CLANG_WARNING (" -Wkeyword-macro" )
4345#include < boost/regex.hpp>
4446POP_CLANG_DIAGS
45- #include < boost/thread.hpp>
46- #include < boost/bind.hpp>
47- #include < boost/version.hpp>
4847
4948#include " Binary.hh"
5049#include " BinaryReader.hh"
@@ -944,46 +943,20 @@ SimulatorFrontend::stopTimer() {
944943
945944/* *
946945 * A thread function for handling simulation timeout
947- *
946+ *
948947 * @param timeout timeout in seconds
949948 */
950- void
951- timeoutThread (unsigned int timeout, SimulatorFrontend* simFE) {
952- if (timeout == 0 ) {
949+ static void
950+ timeoutThread (unsigned int timeout, SimulatorFrontend* simFE,
951+ std::condition_variable& cv, std::mutex& mtx, bool & done) {
952+ if (timeout == 0 )
953953 return ;
954- }
955-
956- TTASimulationController* simCon = simFE->simCon_ ;
957- boost::xtime xt;
958- boost::xtime xtPoll;
959- #if BOOST_VERSION < 105000
960- boost::xtime_get (&xt, boost::TIME_UTC);
961- #else
962- /* TIME_UTC was replaced by TIME_UTC_ in boost 1.50, to avoid
963- * clashing with a similarly named C11 macro. */
964- boost::xtime_get (&xt, boost::TIME_UTC_);
965- #endif
966- unsigned int pollTime = 5 ; // poll time in seconds
967- xtPoll = xt;
968- xt.sec += timeout;
969-
970- xtPoll.sec += pollTime;
971- while (xt.sec > xtPoll.sec ) {
972- boost::thread::sleep (xtPoll);
973- xtPoll.sec += pollTime;
974- if (simCon != simFE->simCon_ ) {
975- return ;
976- }
977- }
978- boost::thread::sleep (xt);
979954
980- if (simCon != simFE->simCon_ ) {
981- return ;
982- }
955+ std::unique_lock<std::mutex> lk{mtx};
956+ cv.wait_for (lk, std::chrono::seconds{timeout}, [&] { return done; });
983957
984- if (!simFE->hasSimulationEnded ()) {
958+ if (!simFE->hasSimulationEnded ())
985959 simFE->prepareToStop (SRE_AFTER_TIMEOUT);
986- }
987960}
988961
989962/* *
@@ -995,11 +968,27 @@ timeoutThread(unsigned int timeout, SimulatorFrontend* simFE) {
995968 */
996969void
997970SimulatorFrontend::run () {
971+ bool done = false ;
972+ std::mutex mtx;
973+ std::condition_variable cv;
974+
975+ std::thread timeout{timeoutThread, simulationTimeout_, this , std::ref (cv),
976+ std::ref (mtx), std::ref (done)};
977+
998978 startTimer ();
999- boost::thread timeout (
1000- boost::bind (timeoutThread, simulationTimeout_, this ));
979+
1001980 simCon_->run ();
981+
1002982 stopTimer ();
983+
984+ /* stop timeout thread */
985+ mtx.lock ();
986+ done = true ;
987+ mtx.unlock ();
988+
989+ cv.notify_all ();
990+ timeout.join ();
991+
1003992 SequenceTools::deleteAllItems (utilizationStats_);
1004993}
1005994
@@ -1012,11 +1001,24 @@ SimulatorFrontend::run() {
10121001 */
10131002void
10141003SimulatorFrontend::runUntil (UIntWord address) {
1004+ bool done = false ;
1005+ std::mutex mtx;
1006+ std::condition_variable cv;
1007+
1008+ std::thread timeout{timeoutThread, simulationTimeout_, this , std::ref (cv),
1009+ std::ref (mtx), std::ref (done)};
1010+
10151011 startTimer ();
1016- boost::thread timeout (boost::bind (timeoutThread,
1017- simulationTimeout_, this ));
10181012 simCon_->runUntil (address);
10191013 stopTimer ();
1014+
1015+ mtx.lock ();
1016+ done = true ;
1017+ mtx.unlock ();
1018+
1019+ cv.notify_all ();
1020+ timeout.join ();
1021+
10201022 // invalidate utilization statistics (they are not fresh anymore)
10211023 SequenceTools::deleteAllItems (utilizationStats_);
10221024}
@@ -1052,12 +1054,24 @@ void
10521054SimulatorFrontend::next (int count) {
10531055 assert (simCon_ != NULL );
10541056
1057+ bool done = false ;
1058+ std::mutex mtx;
1059+ std::condition_variable cv;
1060+
1061+ std::thread timeout{timeoutThread, simulationTimeout_, this , std::ref (cv),
1062+ std::ref (mtx), std::ref (done)};
1063+
10551064 startTimer ();
1056- boost::thread timeout (boost::bind (timeoutThread,
1057- simulationTimeout_, this ));
10581065 simCon_->next (count);
10591066 stopTimer ();
1060-
1067+
1068+ mtx.lock ();
1069+ done = true ;
1070+ mtx.unlock ();
1071+
1072+ cv.notify_all ();
1073+ timeout.join ();
1074+
10611075 // invalidate utilization statistics (they are not fresh anymore)
10621076 SequenceTools::deleteAllItems (utilizationStats_);
10631077}
0 commit comments