Skip to content

Commit

Permalink
Kick CPU thread while attempting to destroy CPU, and mark atomic vari…
Browse files Browse the repository at this point in the history
…ables

Signed-off-by: Mark Burton <[email protected]>
  • Loading branch information
markfoodyburton authored and Mark Burton committed Nov 5, 2024
1 parent e0efafc commit d621b42
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
11 changes: 7 additions & 4 deletions qemu-components/common/include/cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <sstream>
#include <mutex>
#include <condition_variable>
#include <atomic>

#include <tlm>
#include <tlm_utils/simple_initiator_socket.h>
Expand Down Expand Up @@ -50,13 +51,13 @@ class QemuCpu : public QemuDevice, public QemuInitiatorIface
sc_core::sc_event_or_list m_external_ev;
sc_core::sc_process_handle m_sc_thread; // used for co-routines

bool m_signaled;
std::atomic<bool> m_signaled;
std::mutex m_signaled_lock;
std::condition_variable m_signaled_cond;

std::shared_ptr<gs::tlm_quantumkeeper_extended> m_qk;
bool m_finished = false;
bool m_started = false;
std::atomic<bool> m_finished = false;
std::atomic<bool> m_started = false;
std::mutex m_can_delete;
QemuCpuHintTlmExtension m_cpu_hint_ext;

Expand Down Expand Up @@ -368,7 +369,9 @@ class QemuCpu : public QemuDevice, public QemuInitiatorIface
virtual ~QemuCpu()
{
end_of_simulation(); // catch the case we exited abnormally
std::lock_guard<std::mutex> lock(m_can_delete);
while (!m_can_delete.try_lock()) {
m_qk->stop();
}
m_inst.del_dev(this);
}

Expand Down
4 changes: 3 additions & 1 deletion systemc-components/common/include/qkmultithread.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#include <mutex>
#include <condition_variable>
#include <atomic>
#include <systemc>
#include <tlm>
#include <scp/report.h>
Expand Down Expand Up @@ -64,7 +65,8 @@ class tlm_quantumkeeper_multithread : public gs::tlm_quantumkeeper_extended
virtual bool need_sync() override;

// only NONE, RUNNING and STOPPED will be used by the model, the rest are for debug
enum jobstates { NONE = 0, RUNNING = 1, STOPPED = 2, SYSC_WAITING = 4, EXT_WAITING = 8, ILLEGAL = 12 } status;
enum jobstates { NONE = 0, RUNNING = 1, STOPPED = 2, SYSC_WAITING = 4, EXT_WAITING = 8, ILLEGAL = 12 };
std::atomic<jobstates> status;
// MAKE THIS INTO A CCI_PARAM, and provide to_json in the 'normal' way !!!!!

// this function provided only for debug.
Expand Down

0 comments on commit d621b42

Please sign in to comment.