Async: new hierachy; manages reply posting and unlocking

Async: Use new [Non]PostedAsyncCont and callOriginalCb

This new hierarchy of classes gives us a central mechanism for
managing both reply-posting and lockSpec unlocking.

* callOriginalCb: Now uses a modern C++ variadic template design
  enabling it to handle both direct calling and std::bind()
  re-binding of an arbitrary number of arguments from the caller.

This enables us to mostly eliminate the repeated, bespoke
definitions of callOriginalCb littered throughout the codebase.

We've also propagated these changes throughout the codebase in
this patch.
This commit is contained in:
2025-09-17 16:32:20 -04:00
parent 33c006b178
commit 816a047920
9 changed files with 145 additions and 169 deletions
+8 -22
View File
@@ -105,32 +105,18 @@ void MindThread::main(MindThread& self)
}
class MindThread::ThreadLifetimeMgmtOp
: public TargetedAsynchronousContinuation<threadLifetimeMgmtOpCbFn>
: public PostedAsynchronousContinuation<threadLifetimeMgmtOpCbFn>
{
public:
ThreadLifetimeMgmtOp(
const std::shared_ptr<ComponentThread> &caller,
const std::shared_ptr<MindThread> &target,
threadLifetimeMgmtOpCbFn callback)
: TargetedAsynchronousContinuation<threadLifetimeMgmtOpCbFn>(
: PostedAsynchronousContinuation<threadLifetimeMgmtOpCbFn>(
caller, callback),
target(target)
{}
void callOriginalCbFn(void)
{
if (originalCbFn)
{
/** EXPLANATION:
* This is only permissible because originalCbFn doesn't take any
* further arguments. If we had to bind argument to it before
* posting it, we'd have to std::bind them and then post the
* resulting function object.
*/
caller->getIoService().post(originalCbFn);
}
}
public:
const std::shared_ptr<MindThread> target;
@@ -144,7 +130,7 @@ public:
<< "\n";
target->io_service.stop();
callOriginalCbFn();
callOriginalCb();
}
void startThreadReq1_posted(
@@ -158,7 +144,7 @@ public:
// Execute private setup sequence here
// This is where each thread would implement its specific initialization
callOriginalCbFn();
callOriginalCb();
}
void exitThreadReq1_mainQueue_posted(
@@ -170,7 +156,7 @@ public:
target->cleanup();
target->io_service.stop();
callOriginalCbFn();
callOriginalCb();
}
void exitThreadReq1_pauseQueue_posted(
@@ -183,7 +169,7 @@ public:
target->cleanup();
target->pause_io_service.stop();
target->io_service.stop();
callOriginalCbFn();
callOriginalCb();
}
void pauseThreadReq1_posted(
@@ -197,7 +183,7 @@ public:
* our next operation is going to block the thread, so it won't
* have a chance to invoke the callback until it's unblocked.
*/
callOriginalCbFn();
callOriginalCb();
target->pause_io_service.reset();
target->pause_io_service.run();
}
@@ -210,7 +196,7 @@ public:
"resumeThread." << "\n";
target->pause_io_service.stop();
callOriginalCbFn();
callOriginalCb();
}
};