Clock processor asynchronously through ProcessorHandler
MODIFY
src/mainwindow.cpp
src/mainwindow.cpp
@@ -103,8 +103,6 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent), m_ui(new Ui::Main
setupStatusBar();
// Reset and program reload signals
- connect(ProcessorHandler::get(), &ProcessorHandler::stopping, processorTab, &ProcessorTab::pause);
-
connect(ProcessorHandler::get(), &ProcessorHandler::processorReset, [=] { SystemIO::reset(); });
connect(m_ui->actionSystem_calls, &QAction::triggered, [=] {

MODIFY
src/processorhandler.cpp
src/processorhandler.cpp
@@ -120,6 +120,30 @@ void ProcessorHandler::_triggerProcStateChangeTimer() {
m_enqueueStateChangeLock.unlock();
}
+class ProcessorClocker : public QRunnable {
+public:
+ explicit ProcessorClocker(bool& finished) : m_finished(finished) {}
+ void run() override {
+ ProcessorHandler::getProcessorNonConst()->clockProcessor();
+ ProcessorHandler::checkValidExecutionRange();
+ ProcessorHandler::checkProcessorFinished();
+ if (ProcessorHandler::checkBreakpoint()) {
+ ProcessorHandler::stopRun();
+ }
+ m_finished = true;
+ }
+
+private:
+ bool& m_finished;
+};
+
+void ProcessorHandler::_clock() {
+ if (m_clockFinished) {
+ m_clockFinished = false;
+ QThreadPool::globalInstance()->start(new ProcessorClocker(m_clockFinished));
+ }
+}
+
void ProcessorHandler::_run() {
ProcessorStatusManager::setStatus("Running...");
emit runStarted();

MODIFY
src/processorhandler.h
src/processorhandler.h
@@ -136,6 +136,8 @@ public:
*/
static void run() { get()->_run(); }
+ static void clock() { get()->_clock(); }
+
/**
* @brief stopRun
* Sets the m_stopRunningFlag, and waits for any currently running asynchronous run execution to finish.
@@ -221,6 +223,7 @@ private:
void _checkProcessorFinished();
bool _isRunning();
void _run();
+ void _clock();
void _reset();
void _stopRun();
void _triggerProcStateChangeTimer();
@@ -249,6 +252,7 @@ private:
QFutureWatcher<void> m_runWatcher;
bool m_stopRunningFlag = false;
+ bool m_clockFinished = true;
/**
* @brief To avoid excessive UI updates due to things relying on procStateChangedNonRun, the m_procStateChangeTimer

MODIFY
src/processortab.cpp
src/processortab.cpp
@@ -95,6 +95,8 @@ ProcessorTab::ProcessorTab(QToolBar* controlToolbar, QToolBar* additionalToolbar
connect(ProcessorHandler::get(), &ProcessorHandler::procStateChangedNonRun, this, &ProcessorTab::updateStatistics);
connect(ProcessorHandler::get(), &ProcessorHandler::procStateChangedNonRun, this,
&ProcessorTab::updateInstructionLabels);
+ connect(ProcessorHandler::get(), &ProcessorHandler::procStateChangedNonRun, this,
+ [=] { m_reverseAction->setEnabled(m_vsrtlWidget->isReversible()); });
setupSimulatorActions(controlToolbar);
@@ -118,6 +120,7 @@ ProcessorTab::ProcessorTab(QToolBar* controlToolbar, QToolBar* additionalToolbar
connect(ProcessorHandler::get(), &ProcessorHandler::processorReset, this, &ProcessorTab::reset);
connect(ProcessorHandler::get(), &ProcessorHandler::exit, this, &ProcessorTab::processorFinished);
connect(ProcessorHandler::get(), &ProcessorHandler::runFinished, this, &ProcessorTab::runFinished);
+ connect(ProcessorHandler::get(), &ProcessorHandler::stopping, this, &ProcessorTab::pause);
// Send input data from the console to the SystemIO stdin stream
connect(m_ui->console, &Console::sendData, &SystemIO::get(), &SystemIO::putStdInData);
@@ -197,13 +200,13 @@ void ProcessorTab::setupSimulatorActions(QToolBar* controlToolbar) {
const QIcon clockIcon = QIcon(":/icons/step.svg");
m_clockAction = new QAction(clockIcon, "Clock (F5)", this);
- connect(m_clockAction, &QAction::triggered, this, &ProcessorTab::clock);
+ connect(m_clockAction, &QAction::triggered, this, [=] { ProcessorHandler::clock(); });
m_clockAction->setShortcut(QKeySequence("F5"));
m_clockAction->setToolTip("Clock the circuit (F5)");
controlToolbar->addAction(m_clockAction);
QTimer* timer = new QTimer(this);
- connect(timer, &QTimer::timeout, this, &ProcessorTab::clock);
+ connect(timer, &QTimer::timeout, this, [=] { ProcessorHandler::clock(); });
const QIcon startAutoClockIcon = QIcon(":/icons/step-clock.svg");
const QIcon stopAutoTimerIcon = QIcon(":/icons/stop-clock.svg");
@@ -510,16 +513,6 @@ void ProcessorTab::reverse() {
enableSimulatorControls();
}
-void ProcessorTab::clock() {
- m_vsrtlWidget->clock();
- ProcessorHandler::checkValidExecutionRange();
- if (ProcessorHandler::checkBreakpoint()) {
- pause();
- }
- ProcessorHandler::checkProcessorFinished();
- m_reverseAction->setEnabled(m_vsrtlWidget->isReversible());
-}
-
void ProcessorTab::showPipelineDiagram() {
auto w = PipelineDiagramWidget(m_stageModel);
w.exec();

MODIFY
src/processortab.h
src/processortab.h
@@ -52,7 +52,6 @@ public slots:
private slots:
void run(bool state);
- void clock();
void setInstructionViewCenterAddr(AInt address);
void showPipelineDiagram();

Clock processor asynchronously through ProcessorHandler