Mind:init/finiReq: now posted to mrntt; callbacks std:bind
We now have mind::initialize/finalizeReq post their requests to Mrntt instead of executing on the caller's thread context. We also fixed the way that we invoke callbacks by properly wrapping it in a std::bind.
This commit is contained in:
+48
-23
@@ -7,6 +7,7 @@
|
||||
#include <director/director.h>
|
||||
#include <simulator/simulator.h>
|
||||
#include <senseApis/senseApiManager.h>
|
||||
#include <marionette/marionette.h>
|
||||
|
||||
namespace smo {
|
||||
|
||||
@@ -83,19 +84,21 @@ Mind::getMindThreads() const
|
||||
}
|
||||
|
||||
class Mind::MindLifetimeMgmtOp
|
||||
: public AsynchronousContinuation<mindLifetimeMgmtOpCbFn>
|
||||
: public TargetedAsynchronousContinuation<mindLifetimeMgmtOpCbFn>
|
||||
{
|
||||
public:
|
||||
MindLifetimeMgmtOp(
|
||||
Mind &parent, mindLifetimeMgmtOpCbFn callback)
|
||||
: AsynchronousContinuation<mindLifetimeMgmtOpCbFn>(callback),
|
||||
Mind &parent, const std::shared_ptr<ComponentThread> &caller,
|
||||
mindLifetimeMgmtOpCbFn callback)
|
||||
: TargetedAsynchronousContinuation<mindLifetimeMgmtOpCbFn>(
|
||||
caller, callback),
|
||||
parent(parent)
|
||||
{}
|
||||
|
||||
void callOriginalCbFn(bool success)
|
||||
{
|
||||
if (originalCbFn) {
|
||||
originalCbFn(success);
|
||||
caller->getIoService().post(std::bind(originalCbFn, success));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,13 +106,12 @@ public:
|
||||
Mind &parent;
|
||||
|
||||
public:
|
||||
void initializeReq1(
|
||||
void initializeReq1_posted(
|
||||
[[maybe_unused]] std::shared_ptr<MindLifetimeMgmtOp> context
|
||||
)
|
||||
{
|
||||
std::cout << "Mrntt: All mind threads JOLTed." << "\n";
|
||||
|
||||
parent.startAllMindThreadsReq(
|
||||
/* Jolt the threads, then start them */
|
||||
parent.joltAllMindThreadsReq(
|
||||
std::bind(
|
||||
&MindLifetimeMgmtOp::initializeReq2,
|
||||
context.get(), context));
|
||||
@@ -118,16 +120,28 @@ public:
|
||||
void initializeReq2(
|
||||
[[maybe_unused]] std::shared_ptr<MindLifetimeMgmtOp> context
|
||||
)
|
||||
{
|
||||
std::cout << "Mrntt: All mind threads JOLTed." << "\n";
|
||||
|
||||
parent.startAllMindThreadsReq(
|
||||
std::bind(
|
||||
&MindLifetimeMgmtOp::initializeReq3,
|
||||
context.get(), context));
|
||||
}
|
||||
|
||||
void initializeReq3(
|
||||
[[maybe_unused]] std::shared_ptr<MindLifetimeMgmtOp> context
|
||||
)
|
||||
{
|
||||
std::cout << "Mrntt: All mind threads started." << "\n";
|
||||
|
||||
parent.body.initializeReq(
|
||||
std::bind(
|
||||
&MindLifetimeMgmtOp::initializeReq3,
|
||||
&MindLifetimeMgmtOp::initializeReq4,
|
||||
context.get(), context, std::placeholders::_1));
|
||||
}
|
||||
|
||||
void initializeReq3(
|
||||
void initializeReq4(
|
||||
[[maybe_unused]] std::shared_ptr<MindLifetimeMgmtOp> context,
|
||||
bool success
|
||||
)
|
||||
@@ -136,7 +150,17 @@ public:
|
||||
callOriginalCbFn(success);
|
||||
}
|
||||
|
||||
void finalizeReq1(
|
||||
void finalizeReq1_posted(
|
||||
[[maybe_unused]] std::shared_ptr<MindLifetimeMgmtOp> context
|
||||
)
|
||||
{
|
||||
parent.body.finalizeReq(
|
||||
std::bind(
|
||||
&MindLifetimeMgmtOp::finalizeReq2,
|
||||
context.get(), context, std::placeholders::_1));
|
||||
}
|
||||
|
||||
void finalizeReq2(
|
||||
[[maybe_unused]] std::shared_ptr<MindLifetimeMgmtOp> context,
|
||||
bool success
|
||||
)
|
||||
@@ -153,11 +177,11 @@ public:
|
||||
*/
|
||||
parent.joltAllMindThreadsReq(
|
||||
std::bind(
|
||||
&MindLifetimeMgmtOp::finalizeReq2,
|
||||
&MindLifetimeMgmtOp::finalizeReq3,
|
||||
context.get(), context));
|
||||
}
|
||||
|
||||
void finalizeReq2(
|
||||
void finalizeReq3(
|
||||
[[maybe_unused]] std::shared_ptr<MindLifetimeMgmtOp> context
|
||||
)
|
||||
{
|
||||
@@ -165,11 +189,11 @@ public:
|
||||
|
||||
parent.exitAllMindThreadsReq(
|
||||
std::bind(
|
||||
&MindLifetimeMgmtOp::finalizeReq3,
|
||||
&MindLifetimeMgmtOp::finalizeReq4,
|
||||
context.get(), context));
|
||||
}
|
||||
|
||||
void finalizeReq3(
|
||||
void finalizeReq4(
|
||||
[[maybe_unused]] std::shared_ptr<MindLifetimeMgmtOp> context
|
||||
)
|
||||
{
|
||||
@@ -192,25 +216,26 @@ void Mind::initializeReq(mindLifetimeMgmtOpCbFn callback)
|
||||
"Error: " << e.what() << "\n";
|
||||
}
|
||||
|
||||
const auto& caller = ComponentThread::getSelf();
|
||||
auto request = std::make_shared<MindLifetimeMgmtOp>(
|
||||
*this, callback);
|
||||
*this, caller, callback);
|
||||
|
||||
/* Jolt the threads, then start them */
|
||||
joltAllMindThreadsReq(
|
||||
mrntt::mrntt.thread->getIoService().post(
|
||||
std::bind(
|
||||
&MindLifetimeMgmtOp::initializeReq1,
|
||||
&MindLifetimeMgmtOp::initializeReq1_posted,
|
||||
request.get(), request));
|
||||
}
|
||||
|
||||
void Mind::finalizeReq(mindLifetimeMgmtOpCbFn callback)
|
||||
{
|
||||
const auto& caller = ComponentThread::getSelf();
|
||||
auto request = std::make_shared<MindLifetimeMgmtOp>(
|
||||
*this, callback);
|
||||
*this, caller, callback);
|
||||
|
||||
body.finalizeReq(
|
||||
mrntt::mrntt.thread->getIoService().post(
|
||||
std::bind(
|
||||
&MindLifetimeMgmtOp::finalizeReq1,
|
||||
request.get(), request, std::placeholders::_1));
|
||||
&MindLifetimeMgmtOp::finalizeReq1_posted,
|
||||
request.get(), request));
|
||||
}
|
||||
|
||||
void Mind::distributeAndPinThreadsAcrossCpus()
|
||||
|
||||
Reference in New Issue
Block a user