smo::Mind instance now global; track & manage JOLT state in Mind

We moved the instance of smo::Mind to global scope. I suppose we'll
only support one instance of Mind per SMO process at least for now.

We now track the state of Mind threads' JOLT-waiting. This allows us
to centralize the Mind thread shutdown logic. Mind::finalizeReq()
now takes care of all Mind thread shutdown state logic by tracking
whether Mind threads need to be JOLTed first before being told to
exit.
This commit is contained in:
2025-08-10 13:12:17 -04:00
parent e2e589dc17
commit c457ee7aca
4 changed files with 53 additions and 25 deletions
+35 -2
View File
@@ -4,6 +4,8 @@
namespace smo {
Mind mind;
void Mind::initialize()
{
/* Distribute threads across available CPUs */
@@ -20,8 +22,9 @@ void Mind::initialize()
/* Jolt the threads, then start them */
ComponentThread::joltAllMindThreadsReq(
[]()
[this]()
{
this->threadsHaveBeenJolted = true;
std::cout << "Mrntt: All mind threads JOLTed." << "\n";
ComponentThread::startAllMindThreadsReq(
[]()
@@ -33,8 +36,38 @@ void Mind::initialize()
);
}
void Mind::finalize(void)
void Mind::finalizeReq(std::function<void()> callback)
{
/* If the threads haven't been jolted, we need to do that first, because
* otherwise they'll just enter their main loops and wait for control
* messages from mrntt after processing the exit request.
*/
if (!threadsHaveBeenJolted)
{
ComponentThread::joltAllMindThreadsReq(
[this, callback]()
{
this->threadsHaveBeenJolted = true;
ComponentThread::exitAllMindThreadsReq(
[callback]()
{
std::cout << "Mrntt: All mind threads exited." << "\n";
if (callback) { callback(); }
}
);
}
);
}
else
{
ComponentThread::exitAllMindThreadsReq(
[callback]()
{
std::cout << "Mrntt: All mind threads exited." << "\n";
if (callback) { callback(); }
}
);
}
}
} // namespace smo