Mind:threadMgmt ops: move 0-iter callback to top

This commit is contained in:
2025-09-16 18:24:16 -04:00
parent 5d30941aab
commit 8fd8826f8d
+36 -19
View File
@@ -335,6 +335,14 @@ void Mind::joltAllMindThreadsReq(mindThreadLifetimeMgmtOpCbFn callback)
return; return;
} }
// If no threads, set flag and call callback immediately
if (componentThreads.size() == 0 && callback)
{
threadsHaveBeenJolted = true;
callback();
return;
}
// Create a counter to track when all threads have been jolted // Create a counter to track when all threads have been jolted
auto request = std::make_shared<MindThreadLifetimeMgmtOp>( auto request = std::make_shared<MindThreadLifetimeMgmtOp>(
*this, componentThreads.size(), callback); *this, componentThreads.size(), callback);
@@ -346,18 +354,18 @@ void Mind::joltAllMindThreadsReq(mindThreadLifetimeMgmtOpCbFn callback)
&MindThreadLifetimeMgmtOp::joltAllMindThreadsReq1, &MindThreadLifetimeMgmtOp::joltAllMindThreadsReq1,
request.get(), request)); request.get(), request));
} }
// If no threads, set flag and call callback immediately
if (request->loop.nTotalIsZero() && callback)
{
threadsHaveBeenJolted = true;
callback();
}
} }
// Thread management methods (moved from ComponentThread) // Thread management methods (moved from ComponentThread)
void Mind::startAllMindThreadsReq(mindThreadLifetimeMgmtOpCbFn callback) void Mind::startAllMindThreadsReq(mindThreadLifetimeMgmtOpCbFn callback)
{ {
// If no threads, call callback immediately
if (componentThreads.size() == 0 && callback)
{
callback();
return;
}
// Create a counter to track when all threads have started // Create a counter to track when all threads have started
auto request = std::make_shared<MindThreadLifetimeMgmtOp>( auto request = std::make_shared<MindThreadLifetimeMgmtOp>(
*this, componentThreads.size(), callback); *this, componentThreads.size(), callback);
@@ -369,13 +377,17 @@ void Mind::startAllMindThreadsReq(mindThreadLifetimeMgmtOpCbFn callback)
&MindThreadLifetimeMgmtOp::executeGenericOpOnAllMindThreadsReq1, &MindThreadLifetimeMgmtOp::executeGenericOpOnAllMindThreadsReq1,
request.get(), request)); request.get(), request));
} }
// If no threads, call callback immediately
if (request->loop.nTotalIsZero() && callback) { callback(); }
} }
void Mind::pauseAllMindThreadsReq(mindThreadLifetimeMgmtOpCbFn callback) void Mind::pauseAllMindThreadsReq(mindThreadLifetimeMgmtOpCbFn callback)
{ {
// If no threads, call callback immediately
if (componentThreads.size() == 0 && callback)
{
callback();
return;
}
// Create a counter to track when all threads have paused // Create a counter to track when all threads have paused
auto request = std::make_shared<MindThreadLifetimeMgmtOp>( auto request = std::make_shared<MindThreadLifetimeMgmtOp>(
*this, componentThreads.size(), callback); *this, componentThreads.size(), callback);
@@ -387,13 +399,17 @@ void Mind::pauseAllMindThreadsReq(mindThreadLifetimeMgmtOpCbFn callback)
&MindThreadLifetimeMgmtOp::executeGenericOpOnAllMindThreadsReq1, &MindThreadLifetimeMgmtOp::executeGenericOpOnAllMindThreadsReq1,
request.get(), request)); request.get(), request));
} }
// If no threads, call callback immediately
if (request->loop.nTotalIsZero() && callback) { callback(); }
} }
void Mind::resumeAllMindThreadsReq(mindThreadLifetimeMgmtOpCbFn callback) void Mind::resumeAllMindThreadsReq(mindThreadLifetimeMgmtOpCbFn callback)
{ {
// If no threads, call callback immediately
if (componentThreads.size() == 0 && callback)
{
callback();
return;
}
// Create a counter to track when all threads have resumed // Create a counter to track when all threads have resumed
auto request = std::make_shared<MindThreadLifetimeMgmtOp>( auto request = std::make_shared<MindThreadLifetimeMgmtOp>(
*this, componentThreads.size(), callback); *this, componentThreads.size(), callback);
@@ -405,13 +421,17 @@ void Mind::resumeAllMindThreadsReq(mindThreadLifetimeMgmtOpCbFn callback)
&MindThreadLifetimeMgmtOp::executeGenericOpOnAllMindThreadsReq1, &MindThreadLifetimeMgmtOp::executeGenericOpOnAllMindThreadsReq1,
request.get(), request)); request.get(), request));
} }
// If no threads, call callback immediately
if (request->loop.nTotalIsZero() && callback) { callback(); }
} }
void Mind::exitAllMindThreadsReq(mindThreadLifetimeMgmtOpCbFn callback) void Mind::exitAllMindThreadsReq(mindThreadLifetimeMgmtOpCbFn callback)
{ {
// If no threads, call callback immediately
if (componentThreads.size() == 0 && callback)
{
callback();
return;
}
// Create a counter to track when all threads have exited // Create a counter to track when all threads have exited
auto request = std::make_shared<MindThreadLifetimeMgmtOp>( auto request = std::make_shared<MindThreadLifetimeMgmtOp>(
*this, componentThreads.size(), callback); *this, componentThreads.size(), callback);
@@ -423,9 +443,6 @@ void Mind::exitAllMindThreadsReq(mindThreadLifetimeMgmtOpCbFn callback)
&MindThreadLifetimeMgmtOp::executeGenericOpOnAllMindThreadsReq1, &MindThreadLifetimeMgmtOp::executeGenericOpOnAllMindThreadsReq1,
request.get(), request)); request.get(), request));
} }
// If no threads, call callback immediately
if (request->loop.nTotalIsZero() && callback) { callback(); }
} }
} // namespace smo } // namespace smo