Moved JOLT state tracking into ComponentThread::

This commit is contained in:
2025-08-10 13:29:34 -04:00
parent 42b32f27e6
commit 099d60bcc4
4 changed files with 11 additions and 9 deletions
+3
View File
@@ -65,6 +65,9 @@ std::shared_ptr<ComponentThread> world =
std::make_shared<ComponentThread>(ComponentThread::WORLD); std::make_shared<ComponentThread>(ComponentThread::WORLD);
} }
// Initialize static state
std::atomic<bool> ComponentThread::threadsHaveBeenJolted{false};
std::array<std::shared_ptr<ComponentThread>, ComponentThread::N_ITEMS> std::array<std::shared_ptr<ComponentThread>, ComponentThread::N_ITEMS>
ComponentThread::componentThreads = ComponentThread::componentThreads =
{ {
+2
View File
@@ -120,6 +120,8 @@ public:
boost::asio::io_service::work pause_work; boost::asio::io_service::work pause_work;
std::atomic<bool> keepLooping; std::atomic<bool> keepLooping;
int pinnedCpuId; int pinnedCpuId;
// Indicates whether all mind threads have been JOLTed at least once
static std::atomic<bool> threadsHaveBeenJolted;
/* Always ensure that this is last so that the thread is spawned after /* Always ensure that this is last so that the thread is spawned after
* everything else is constructed. * everything else is constructed.
+1 -4
View File
@@ -13,7 +13,7 @@ namespace smo {
class Mind class Mind
{ {
public: public:
Mind(void) : threadsHaveBeenJolted(false) {} Mind(void) {}
void initialize(void); void initialize(void);
void execute(void); void execute(void);
@@ -26,9 +26,6 @@ public:
director::Director director; director::Director director;
simulator::Simulator canvas; simulator::Simulator canvas;
private:
bool threadsHaveBeenJolted;
}; };
extern Mind mind; extern Mind mind;
+5 -5
View File
@@ -22,9 +22,9 @@ void Mind::initialize()
/* Jolt the threads, then start them */ /* Jolt the threads, then start them */
ComponentThread::joltAllMindThreadsReq( ComponentThread::joltAllMindThreadsReq(
[this]() []()
{ {
this->threadsHaveBeenJolted = true; ComponentThread::threadsHaveBeenJolted.store(true);
std::cout << "Mrntt: All mind threads JOLTed." << "\n"; std::cout << "Mrntt: All mind threads JOLTed." << "\n";
ComponentThread::startAllMindThreadsReq( ComponentThread::startAllMindThreadsReq(
[]() []()
@@ -42,12 +42,12 @@ void Mind::finalizeReq(std::function<void()> callback)
* otherwise they'll just enter their main loops and wait for control * otherwise they'll just enter their main loops and wait for control
* messages from mrntt after processing the exit request. * messages from mrntt after processing the exit request.
*/ */
if (!threadsHaveBeenJolted) if (!ComponentThread::threadsHaveBeenJolted.load())
{ {
ComponentThread::joltAllMindThreadsReq( ComponentThread::joltAllMindThreadsReq(
[this, callback]() [callback]()
{ {
this->threadsHaveBeenJolted = true; ComponentThread::threadsHaveBeenJolted.store(true);
ComponentThread::exitAllMindThreadsReq( ComponentThread::exitAllMindThreadsReq(
[callback]() [callback]()
{ {