From d621b42186d69e0902feee2fb56c380ee7be1ca5 Mon Sep 17 00:00:00 2001 From: Mark Burton Date: Mon, 4 Nov 2024 11:57:13 +0100 Subject: [PATCH] Kick CPU thread while attempting to destroy CPU, and mark atomic variables Signed-off-by: Mark Burton --- qemu-components/common/include/cpu.h | 11 +++++++---- systemc-components/common/include/qkmultithread.h | 4 +++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/qemu-components/common/include/cpu.h b/qemu-components/common/include/cpu.h index 93f47b7c..662c2527 100644 --- a/qemu-components/common/include/cpu.h +++ b/qemu-components/common/include/cpu.h @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -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 m_signaled; std::mutex m_signaled_lock; std::condition_variable m_signaled_cond; std::shared_ptr m_qk; - bool m_finished = false; - bool m_started = false; + std::atomic m_finished = false; + std::atomic m_started = false; std::mutex m_can_delete; QemuCpuHintTlmExtension m_cpu_hint_ext; @@ -368,7 +369,9 @@ class QemuCpu : public QemuDevice, public QemuInitiatorIface virtual ~QemuCpu() { end_of_simulation(); // catch the case we exited abnormally - std::lock_guard lock(m_can_delete); + while (!m_can_delete.try_lock()) { + m_qk->stop(); + } m_inst.del_dev(this); } diff --git a/systemc-components/common/include/qkmultithread.h b/systemc-components/common/include/qkmultithread.h index b9500adc..8085113f 100644 --- a/systemc-components/common/include/qkmultithread.h +++ b/systemc-components/common/include/qkmultithread.h @@ -12,6 +12,7 @@ #include #include +#include #include #include #include @@ -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 status; // MAKE THIS INTO A CCI_PARAM, and provide to_json in the 'normal' way !!!!! // this function provided only for debug.