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 <director/director.h>
|
||||||
#include <simulator/simulator.h>
|
#include <simulator/simulator.h>
|
||||||
#include <senseApis/senseApiManager.h>
|
#include <senseApis/senseApiManager.h>
|
||||||
|
#include <marionette/marionette.h>
|
||||||
|
|
||||||
namespace smo {
|
namespace smo {
|
||||||
|
|
||||||
@@ -83,19 +84,21 @@ Mind::getMindThreads() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
class Mind::MindLifetimeMgmtOp
|
class Mind::MindLifetimeMgmtOp
|
||||||
: public AsynchronousContinuation<mindLifetimeMgmtOpCbFn>
|
: public TargetedAsynchronousContinuation<mindLifetimeMgmtOpCbFn>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MindLifetimeMgmtOp(
|
MindLifetimeMgmtOp(
|
||||||
Mind &parent, mindLifetimeMgmtOpCbFn callback)
|
Mind &parent, const std::shared_ptr<ComponentThread> &caller,
|
||||||
: AsynchronousContinuation<mindLifetimeMgmtOpCbFn>(callback),
|
mindLifetimeMgmtOpCbFn callback)
|
||||||
|
: TargetedAsynchronousContinuation<mindLifetimeMgmtOpCbFn>(
|
||||||
|
caller, callback),
|
||||||
parent(parent)
|
parent(parent)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
void callOriginalCbFn(bool success)
|
void callOriginalCbFn(bool success)
|
||||||
{
|
{
|
||||||
if (originalCbFn) {
|
if (originalCbFn) {
|
||||||
originalCbFn(success);
|
caller->getIoService().post(std::bind(originalCbFn, success));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -103,13 +106,12 @@ public:
|
|||||||
Mind &parent;
|
Mind &parent;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void initializeReq1(
|
void initializeReq1_posted(
|
||||||
[[maybe_unused]] std::shared_ptr<MindLifetimeMgmtOp> context
|
[[maybe_unused]] std::shared_ptr<MindLifetimeMgmtOp> context
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
std::cout << "Mrntt: All mind threads JOLTed." << "\n";
|
/* Jolt the threads, then start them */
|
||||||
|
parent.joltAllMindThreadsReq(
|
||||||
parent.startAllMindThreadsReq(
|
|
||||||
std::bind(
|
std::bind(
|
||||||
&MindLifetimeMgmtOp::initializeReq2,
|
&MindLifetimeMgmtOp::initializeReq2,
|
||||||
context.get(), context));
|
context.get(), context));
|
||||||
@@ -118,16 +120,28 @@ public:
|
|||||||
void initializeReq2(
|
void initializeReq2(
|
||||||
[[maybe_unused]] std::shared_ptr<MindLifetimeMgmtOp> context
|
[[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";
|
std::cout << "Mrntt: All mind threads started." << "\n";
|
||||||
|
|
||||||
parent.body.initializeReq(
|
parent.body.initializeReq(
|
||||||
std::bind(
|
std::bind(
|
||||||
&MindLifetimeMgmtOp::initializeReq3,
|
&MindLifetimeMgmtOp::initializeReq4,
|
||||||
context.get(), context, std::placeholders::_1));
|
context.get(), context, std::placeholders::_1));
|
||||||
}
|
}
|
||||||
|
|
||||||
void initializeReq3(
|
void initializeReq4(
|
||||||
[[maybe_unused]] std::shared_ptr<MindLifetimeMgmtOp> context,
|
[[maybe_unused]] std::shared_ptr<MindLifetimeMgmtOp> context,
|
||||||
bool success
|
bool success
|
||||||
)
|
)
|
||||||
@@ -136,7 +150,17 @@ public:
|
|||||||
callOriginalCbFn(success);
|
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,
|
[[maybe_unused]] std::shared_ptr<MindLifetimeMgmtOp> context,
|
||||||
bool success
|
bool success
|
||||||
)
|
)
|
||||||
@@ -153,11 +177,11 @@ public:
|
|||||||
*/
|
*/
|
||||||
parent.joltAllMindThreadsReq(
|
parent.joltAllMindThreadsReq(
|
||||||
std::bind(
|
std::bind(
|
||||||
&MindLifetimeMgmtOp::finalizeReq2,
|
&MindLifetimeMgmtOp::finalizeReq3,
|
||||||
context.get(), context));
|
context.get(), context));
|
||||||
}
|
}
|
||||||
|
|
||||||
void finalizeReq2(
|
void finalizeReq3(
|
||||||
[[maybe_unused]] std::shared_ptr<MindLifetimeMgmtOp> context
|
[[maybe_unused]] std::shared_ptr<MindLifetimeMgmtOp> context
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
@@ -165,11 +189,11 @@ public:
|
|||||||
|
|
||||||
parent.exitAllMindThreadsReq(
|
parent.exitAllMindThreadsReq(
|
||||||
std::bind(
|
std::bind(
|
||||||
&MindLifetimeMgmtOp::finalizeReq3,
|
&MindLifetimeMgmtOp::finalizeReq4,
|
||||||
context.get(), context));
|
context.get(), context));
|
||||||
}
|
}
|
||||||
|
|
||||||
void finalizeReq3(
|
void finalizeReq4(
|
||||||
[[maybe_unused]] std::shared_ptr<MindLifetimeMgmtOp> context
|
[[maybe_unused]] std::shared_ptr<MindLifetimeMgmtOp> context
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
@@ -192,25 +216,26 @@ void Mind::initializeReq(mindLifetimeMgmtOpCbFn callback)
|
|||||||
"Error: " << e.what() << "\n";
|
"Error: " << e.what() << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const auto& caller = ComponentThread::getSelf();
|
||||||
auto request = std::make_shared<MindLifetimeMgmtOp>(
|
auto request = std::make_shared<MindLifetimeMgmtOp>(
|
||||||
*this, callback);
|
*this, caller, callback);
|
||||||
|
|
||||||
/* Jolt the threads, then start them */
|
mrntt::mrntt.thread->getIoService().post(
|
||||||
joltAllMindThreadsReq(
|
|
||||||
std::bind(
|
std::bind(
|
||||||
&MindLifetimeMgmtOp::initializeReq1,
|
&MindLifetimeMgmtOp::initializeReq1_posted,
|
||||||
request.get(), request));
|
request.get(), request));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Mind::finalizeReq(mindLifetimeMgmtOpCbFn callback)
|
void Mind::finalizeReq(mindLifetimeMgmtOpCbFn callback)
|
||||||
{
|
{
|
||||||
|
const auto& caller = ComponentThread::getSelf();
|
||||||
auto request = std::make_shared<MindLifetimeMgmtOp>(
|
auto request = std::make_shared<MindLifetimeMgmtOp>(
|
||||||
*this, callback);
|
*this, caller, callback);
|
||||||
|
|
||||||
body.finalizeReq(
|
mrntt::mrntt.thread->getIoService().post(
|
||||||
std::bind(
|
std::bind(
|
||||||
&MindLifetimeMgmtOp::finalizeReq1,
|
&MindLifetimeMgmtOp::finalizeReq1_posted,
|
||||||
request.get(), request, std::placeholders::_1));
|
request.get(), request));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Mind::distributeAndPinThreadsAcrossCpus()
|
void Mind::distributeAndPinThreadsAcrossCpus()
|
||||||
|
|||||||
Reference in New Issue
Block a user