diff options
author | bd <bdunahu@operationnull.com> | 2025-04-19 12:18:14 -0400 |
---|---|---|
committer | bd <bdunahu@operationnull.com> | 2025-04-19 12:18:14 -0400 |
commit | 5ad39ec769fa09b9ac4dcc8f66232ef51384a3c6 (patch) | |
tree | 76291c5284711f5e371134439dce2c4c48432528 /gui/worker.cc | |
parent | 24de6faf71c85e0281b32fb899fcbe4fe82380c4 (diff) |
Safely delete old controller object when re-initializing
Diffstat (limited to 'gui/worker.cc')
-rw-r--r-- | gui/worker.cc | 42 |
1 files changed, 17 insertions, 25 deletions
diff --git a/gui/worker.cc b/gui/worker.cc index cd79821..88248e8 100644 --- a/gui/worker.cc +++ b/gui/worker.cc @@ -18,21 +18,23 @@ void Worker::configure( { Dram *d; Storage *s; + Stage *old; int i; + this->ct_mutex.lock(); if (ways.size() != 0) { // will ensure the largest cache is only half of DRAM this->size_inc = (MEM_LINE_SPEC / ways.size()) / 2; } d = new Dram(DRAM_DELAY); - s = (Storage *)d; + s = static_cast<Storage *>(d); this->s.push_front(s); d->load(program); for (i = ways.size(); i > 0; --i) { - s = (Storage *)new Cache( - s, this->size_inc * (i), ways.at(i - 1), CACHE_DELAY + i); + s = static_cast<Storage *>(new Cache( + s, this->size_inc * (i), ways.at(i - 1), CACHE_DELAY + i)); this->s.push_front(s); } @@ -41,37 +43,26 @@ void Worker::configure( this->ex_stage = new EX(id_stage); this->mm_stage = new MM(ex_stage); this->wb_stage = new WB(mm_stage); - this->ct = - new Controller(wb_stage, s, is_pipelined); - emit clock_cycles(this->ct->get_clock_cycle(), this->ct->get_pc()); -} - -void Worker::refreshDram() -{ - qDebug() << "Refreshing Dram"; - emit dram_storage(this->s.back()->view(0, 255)); -} - -void Worker::refreshCache() -{ - qDebug() << "Refreshing Cache"; - if(this->s.size() > 0) { - emit cache_storage(this->s.at(0)->view(0, 1 << this->size_inc)); - } -} + old = static_cast<Stage *>(this->ct); + this->ct = new Controller(wb_stage, s, is_pipelined); + if (old) + delete old; + this->ct_mutex.unlock(); -void Worker::refreshRegisters() -{ - qDebug() << "Refreshing Registers"; - emit register_storage(this->ct->get_gprs()); + emit clock_cycles(this->ct->get_clock_cycle(), this->ct->get_pc()); } void Worker::runSteps(int steps) { + this->ct_mutex.lock(); qDebug() << "Running for " << steps << "steps"; this->ct->run_for(steps); + // TODO move these to separate functions emit dram_storage(this->s.back()->view(0, 255)); + if (this->s.size() > 1) { + emit cache_storage(this->s.at(0)->view(0, 1 << this->size_inc)); + } emit register_storage(this->ct->get_gprs()); emit clock_cycles(this->ct->get_clock_cycle(), this->ct->get_pc()); emit if_info(this->if_stage->stage_info()); @@ -79,4 +70,5 @@ void Worker::runSteps(int steps) emit ex_info(this->ex_stage->stage_info()); emit mm_info(this->mm_stage->stage_info()); emit wb_info(this->wb_stage->stage_info()); + this->ct_mutex.unlock(); } |