From 099d60bcc41cc5b22e6c559565ad4dac8a38e81a Mon Sep 17 00:00:00 2001 From: Hayodea Hakol Date: Sun, 10 Aug 2025 13:29:34 -0400 Subject: [PATCH] Moved JOLT state tracking into ComponentThread:: --- smocore/componentThread.cpp | 3 +++ smocore/include/componentThread.h | 2 ++ smocore/include/mind.h | 5 +---- smocore/mind.cpp | 10 +++++----- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/smocore/componentThread.cpp b/smocore/componentThread.cpp index ea890e6..f08e352 100644 --- a/smocore/componentThread.cpp +++ b/smocore/componentThread.cpp @@ -65,6 +65,9 @@ std::shared_ptr world = std::make_shared(ComponentThread::WORLD); } +// Initialize static state +std::atomic ComponentThread::threadsHaveBeenJolted{false}; + std::array, ComponentThread::N_ITEMS> ComponentThread::componentThreads = { diff --git a/smocore/include/componentThread.h b/smocore/include/componentThread.h index 0e0ca19..78bb3de 100644 --- a/smocore/include/componentThread.h +++ b/smocore/include/componentThread.h @@ -120,6 +120,8 @@ public: boost::asio::io_service::work pause_work; std::atomic keepLooping; int pinnedCpuId; + // Indicates whether all mind threads have been JOLTed at least once + static std::atomic threadsHaveBeenJolted; /* Always ensure that this is last so that the thread is spawned after * everything else is constructed. diff --git a/smocore/include/mind.h b/smocore/include/mind.h index 50b6145..2ddc429 100644 --- a/smocore/include/mind.h +++ b/smocore/include/mind.h @@ -13,7 +13,7 @@ namespace smo { class Mind { public: - Mind(void) : threadsHaveBeenJolted(false) {} + Mind(void) {} void initialize(void); void execute(void); @@ -26,9 +26,6 @@ public: director::Director director; simulator::Simulator canvas; - -private: - bool threadsHaveBeenJolted; }; extern Mind mind; diff --git a/smocore/mind.cpp b/smocore/mind.cpp index 2aa7301..7361127 100644 --- a/smocore/mind.cpp +++ b/smocore/mind.cpp @@ -22,9 +22,9 @@ void Mind::initialize() /* Jolt the threads, then start them */ ComponentThread::joltAllMindThreadsReq( - [this]() + []() { - this->threadsHaveBeenJolted = true; + ComponentThread::threadsHaveBeenJolted.store(true); std::cout << "Mrntt: All mind threads JOLTed." << "\n"; ComponentThread::startAllMindThreadsReq( []() @@ -42,12 +42,12 @@ void Mind::finalizeReq(std::function callback) * otherwise they'll just enter their main loops and wait for control * messages from mrntt after processing the exit request. */ - if (!threadsHaveBeenJolted) + if (!ComponentThread::threadsHaveBeenJolted.load()) { ComponentThread::joltAllMindThreadsReq( - [this, callback]() + [callback]() { - this->threadsHaveBeenJolted = true; + ComponentThread::threadsHaveBeenJolted.store(true); ComponentThread::exitAllMindThreadsReq( [callback]() {