From: Andrew Waterman Date: Mon, 23 Sep 2013 22:47:50 +0000 (-0700) Subject: Fix Scott's deadlock X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=2deb1197bc57bf732a900671e653073b37d67398;p=riscv-isa-sim.git Fix Scott's deadlock Not Scott's fault, I mean --- diff --git a/riscv/htif.cc b/riscv/htif.cc index 679ef93..d7b9f63 100644 --- a/riscv/htif.cc +++ b/riscv/htif.cc @@ -15,9 +15,14 @@ htif_isasim_t::htif_isasim_t(sim_t* _sim, const std::vector& args) { } -void htif_isasim_t::tick() +bool htif_isasim_t::tick() { + if (done()) + return false; + do tick_once(); while (reset); + + return true; } void htif_isasim_t::tick_once() diff --git a/riscv/htif.h b/riscv/htif.h index 3e4a88d..2a940ad 100644 --- a/riscv/htif.h +++ b/riscv/htif.h @@ -17,8 +17,7 @@ class htif_isasim_t : public htif_pthread_t { public: htif_isasim_t(sim_t* _sim, const std::vector& args); - void tick(); - bool done(); + bool tick(); private: sim_t* sim; @@ -26,6 +25,7 @@ private: uint8_t seqno; void tick_once(); + bool done(); }; #endif diff --git a/riscv/sim.cc b/riscv/sim.cc index 864ec09..a4a1c17 100644 --- a/riscv/sim.cc +++ b/riscv/sim.cc @@ -74,9 +74,8 @@ reg_t sim_t::get_scr(int which) void sim_t::run() { - while (!htif->done()) + while (htif->tick()) { - htif->tick(); if (debug || ctrlc_pressed) interactive(); else @@ -115,6 +114,6 @@ bool sim_t::running() void sim_t::stop() { procs[0]->state.tohost = 1; - while (!htif->done()) - htif->tick(); + while (htif->tick()) + ; }