Async: add sh_ptr<ContinuationChainLink> to Callback<>

This change enables us to finally implement the tracing of
continuations backward from the point of acquisition for deadlock
debugging.
This commit is contained in:
2025-09-27 18:30:09 -04:00
parent 2212aec080
commit 782bcd4567
26 changed files with 384 additions and 269 deletions
+10 -9
View File
@@ -2,6 +2,7 @@
#include <opts.h>
#include <asynchronousContinuation.h>
#include <asynchronousLoop.h>
#include <callback.h>
#include <body/body.h>
#include <componentThread.h>
#include <mind.h>
@@ -21,7 +22,7 @@ class Body::InitializeReq
public:
InitializeReq(
Mind &parent, const std::shared_ptr<ComponentThread> &caller,
bodyLifetimeMgmtOpCbFn callback)
Callback<bodyLifetimeMgmtOpCbFn> callback)
: PostedAsynchronousContinuation<bodyLifetimeMgmtOpCbFn>(caller, callback),
parent(parent)
{}
@@ -78,10 +79,10 @@ public:
}
sense_api::SenseApiManager::getInstance()
.attachAllSenseDevicesFromSpecsReq(
std::bind(
{context, std::bind(
&InitializeReq::initializeReq2,
context.get(), context,
std::placeholders::_1));
std::placeholders::_1)});
}
void initializeReq2(
@@ -117,10 +118,10 @@ public:
std::cout << "Mrntt: About to detach all sense devices." << "\n";
sense_api::SenseApiManager::getInstance().detachAllSenseDevicesReq(
std::bind(
{context, std::bind(
&FinalizeReq::finalizeReq2,
context.get(), context,
std::placeholders::_1));
std::placeholders::_1)});
}
void finalizeReq2(
@@ -141,7 +142,7 @@ public:
}
};
void Body::initializeReq(bodyLifetimeMgmtOpCbFn callback)
void Body::initializeReq(Callback<bodyLifetimeMgmtOpCbFn> callback)
{
auto mrntt = ComponentThread::getSelf();
@@ -160,7 +161,7 @@ void Body::initializeReq(bodyLifetimeMgmtOpCbFn callback)
request.get(), request));
}
void Body::finalizeReq(bodyLifetimeMgmtOpCbFn callback)
void Body::finalizeReq(Callback<bodyLifetimeMgmtOpCbFn> callback)
{
auto mrntt = ComponentThread::getSelf();
@@ -168,7 +169,7 @@ void Body::finalizeReq(bodyLifetimeMgmtOpCbFn callback)
{
std::cerr << __func__ << ": Must be invoked by Mrntt thread"
<< std::endl;
callback(false);
callback.callbackFn(false);
return;
}
@@ -176,7 +177,7 @@ void Body::finalizeReq(bodyLifetimeMgmtOpCbFn callback)
{
std::cout << "Mrntt: Body component not initialized. "
<< "Skipping finalization." << "\n";
callback(true);
callback.callbackFn(true);
return;
}
+9 -8
View File
@@ -5,6 +5,7 @@
#include <boost/asio.hpp>
#include <opts.h>
#include <asynchronousContinuation.h>
#include <callback.h>
#include <mind.h>
#include <mindManager/mindManager.h>
#include <componentThread.h>
@@ -96,8 +97,8 @@ void MindThread::main(MindThread& self)
if (sendExceptionInd)
{
mrntt::mrntt.finalizeReq(
std::bind(
&mrntt::marionetteFinalizeReqCb, std::placeholders::_1));
{nullptr, std::bind(
&mrntt::marionetteFinalizeReqCb, std::placeholders::_1)});
}
}
@@ -111,7 +112,7 @@ public:
ThreadLifetimeMgmtOp(
const std::shared_ptr<ComponentThread> &caller,
const std::shared_ptr<MindThread> &target,
threadLifetimeMgmtOpCbFn callback)
Callback<threadLifetimeMgmtOpCbFn> callback)
: PostedAsynchronousContinuation<threadLifetimeMgmtOpCbFn>(
caller, callback),
target(target)
@@ -205,7 +206,7 @@ void ComponentThread::cleanup(void)
this->keepLooping = false;
}
void MindThread::joltThreadReq(threadLifetimeMgmtOpCbFn callback)
void MindThread::joltThreadReq(Callback<threadLifetimeMgmtOpCbFn> callback)
{
/** EXPLANATION:
* We can't use shared_from_this() here because JOLTing occurs prior to
@@ -241,7 +242,7 @@ void MindThread::joltThreadReq(threadLifetimeMgmtOpCbFn callback)
}
// Thread management method implementations
void MindThread::startThreadReq(threadLifetimeMgmtOpCbFn callback)
void MindThread::startThreadReq(Callback<threadLifetimeMgmtOpCbFn> callback)
{
std::shared_ptr<ComponentThread> caller = getSelf();
auto request = std::make_shared<ThreadLifetimeMgmtOp>(
@@ -253,7 +254,7 @@ void MindThread::startThreadReq(threadLifetimeMgmtOpCbFn callback)
request.get(), request));
}
void MindThread::exitThreadReq(threadLifetimeMgmtOpCbFn callback)
void MindThread::exitThreadReq(Callback<threadLifetimeMgmtOpCbFn> callback)
{
std::shared_ptr<ComponentThread> caller = getSelf();
auto request = std::make_shared<ThreadLifetimeMgmtOp>(
@@ -270,7 +271,7 @@ void MindThread::exitThreadReq(threadLifetimeMgmtOpCbFn callback)
request.get(), request));
}
void MindThread::pauseThreadReq(threadLifetimeMgmtOpCbFn callback)
void MindThread::pauseThreadReq(Callback<threadLifetimeMgmtOpCbFn> callback)
{
if (id == ComponentThread::MRNTT)
{
@@ -288,7 +289,7 @@ void MindThread::pauseThreadReq(threadLifetimeMgmtOpCbFn callback)
request.get(), request));
}
void MindThread::resumeThreadReq(threadLifetimeMgmtOpCbFn callback)
void MindThread::resumeThreadReq(Callback<threadLifetimeMgmtOpCbFn> callback)
{
if (id == ComponentThread::MRNTT)
{
+6 -5
View File
@@ -7,6 +7,7 @@
#include <memory>
#include <opts.h>
#include <asynchronousContinuation.h>
#include <callback.h>
#include <deviceManager/deviceManager.h>
#include <senseApis/senseApiManager.h>
#include <marionette/marionette.h>
@@ -45,7 +46,7 @@ public:
NewDeviceAttachmentSpecInd(
std::shared_ptr<DeviceAttachmentSpec> s,
const std::shared_ptr<ComponentThread> &caller,
newDeviceAttachmentSpecIndCbFn cb)
Callback<newDeviceAttachmentSpecIndCbFn> cb)
: PostedAsynchronousContinuation<newDeviceAttachmentSpecIndCbFn>(
caller, cb),
spec(s)
@@ -61,10 +62,10 @@ public:
{
sense_api::SenseApiManager::getInstance().attachSenseDeviceReq(
spec,
std::bind(
{context, std::bind(
&NewDeviceAttachmentSpecInd::newDeviceAttachmentSpecInd2,
context.get(), context,
std::placeholders::_1, std::placeholders::_2));
std::placeholders::_1, std::placeholders::_2)});
}
void newDeviceAttachmentSpecInd2(
@@ -125,14 +126,14 @@ public:
void DeviceManager::newDeviceAttachmentSpecInd(
std::shared_ptr<DeviceAttachmentSpec> spec,
newDeviceAttachmentSpecIndCbFn callback)
Callback<newDeviceAttachmentSpecIndCbFn> callback)
{
// Check if a DeviceAttachmentSpec already matches
for (const auto& existingSpec : deviceAttachmentSpecs)
{
if (!(*existingSpec == *spec)) { continue; }
// Already exists, callback with error
callback(false, nullptr, spec);
callback.callbackFn(false, nullptr, spec);
return;
}
+3 -2
View File
@@ -3,6 +3,7 @@
#include <component.h>
#include <functional>
#include <callback.h>
namespace smo {
@@ -19,8 +20,8 @@ public:
~Body() = default;
typedef std::function<void(bool)> bodyLifetimeMgmtOpCbFn;
void initializeReq(bodyLifetimeMgmtOpCbFn callback);
void finalizeReq(bodyLifetimeMgmtOpCbFn callback);
void initializeReq(Callback<bodyLifetimeMgmtOpCbFn> callback);
void finalizeReq(Callback<bodyLifetimeMgmtOpCbFn> callback);
private:
class InitializeReq;
+3 -2
View File
@@ -4,6 +4,7 @@
#include <config.h>
#include <memory>
#include <functional>
#include <callback.h>
namespace smo {
@@ -44,8 +45,8 @@ public:
public:
typedef std::function<void(bool)> mrnttLifetimeMgmtOpCbFn;
void initializeReq(mrnttLifetimeMgmtOpCbFn callback);
void finalizeReq(mrnttLifetimeMgmtOpCbFn callback);
void initializeReq(Callback<mrnttLifetimeMgmtOpCbFn> callback);
void finalizeReq(Callback<mrnttLifetimeMgmtOpCbFn> callback);
private:
class MrnttLifetimeMgmtOp;
+6 -5
View File
@@ -12,6 +12,7 @@
#include <sched.h>
#include <unistd.h>
#include <memory>
#include <callback.h>
namespace smo {
@@ -137,10 +138,10 @@ public:
// Thread management methods
typedef std::function<void()> threadLifetimeMgmtOpCbFn;
void startThreadReq(threadLifetimeMgmtOpCbFn callback);
void exitThreadReq(threadLifetimeMgmtOpCbFn callback);
void pauseThreadReq(threadLifetimeMgmtOpCbFn callback);
void resumeThreadReq(threadLifetimeMgmtOpCbFn callback);
void startThreadReq(Callback<threadLifetimeMgmtOpCbFn> callback);
void exitThreadReq(Callback<threadLifetimeMgmtOpCbFn> callback);
void pauseThreadReq(Callback<threadLifetimeMgmtOpCbFn> callback);
void resumeThreadReq(Callback<threadLifetimeMgmtOpCbFn> callback);
/**
* JOLTs this thread to begin processing after global initialization.
@@ -149,7 +150,7 @@ public:
* event loops and set up TLS vars after all global constructors have
* completed. This prevents race conditions during system startup.
*/
void joltThreadReq(threadLifetimeMgmtOpCbFn callback);
void joltThreadReq(Callback<threadLifetimeMgmtOpCbFn> callback);
// CPU management methods
void pinToCpu(int cpuId);
@@ -10,6 +10,7 @@
#include <functional>
#include <user/deviceAttachmentSpec.h>
#include <deviceManager/device.h>
#include <callback.h>
namespace smo {
namespace device {
@@ -41,7 +42,7 @@ public:
newDeviceAttachmentSpecIndCbFn;
void newDeviceAttachmentSpecInd(
std::shared_ptr<DeviceAttachmentSpec> spec,
newDeviceAttachmentSpecIndCbFn callback);
Callback<newDeviceAttachmentSpecIndCbFn> callback);
private:
DeviceManager() = default;
+11 -7
View File
@@ -7,6 +7,7 @@
#include <memory>
#include <unordered_map>
#include <string>
#include <callback.h>
#include <component.h>
#include <componentThread.h>
@@ -23,8 +24,8 @@ public:
~Mind(void) = default;
typedef std::function<void(bool)> mindLifetimeMgmtOpCbFn;
void initializeReq(mindLifetimeMgmtOpCbFn callback);
void finalizeReq(mindLifetimeMgmtOpCbFn callback);
void initializeReq(Callback<mindLifetimeMgmtOpCbFn> callback);
void finalizeReq(Callback<mindLifetimeMgmtOpCbFn> callback);
// ComponentThread access methods
std::shared_ptr<MindThread> getComponentThread(
@@ -36,11 +37,14 @@ public:
// Thread management methods (moved from ComponentThread)
typedef std::function<void()> mindThreadLifetimeMgmtOpCbFn;
void joltAllMindThreadsReq(mindThreadLifetimeMgmtOpCbFn callback);
void startAllMindThreadsReq(mindThreadLifetimeMgmtOpCbFn callback);
void pauseAllMindThreadsReq(mindThreadLifetimeMgmtOpCbFn callback);
void resumeAllMindThreadsReq(mindThreadLifetimeMgmtOpCbFn callback);
void exitAllMindThreadsReq(mindThreadLifetimeMgmtOpCbFn callback);
void joltAllMindThreadsReq(Callback<mindThreadLifetimeMgmtOpCbFn> callback);
void startAllMindThreadsReq(
Callback<mindThreadLifetimeMgmtOpCbFn> callback);
void pauseAllMindThreadsReq(
Callback<mindThreadLifetimeMgmtOpCbFn> callback);
void resumeAllMindThreadsReq(
Callback<mindThreadLifetimeMgmtOpCbFn> callback);
void exitAllMindThreadsReq(Callback<mindThreadLifetimeMgmtOpCbFn> callback);
// CPU distribution method
void distributeAndPinThreadsAcrossCpus();
+5 -4
View File
@@ -11,6 +11,7 @@
#include <asynchronousLoop.h>
#include <senseApis/senseApiLib.h>
#include <user/deviceAttachmentSpec.h>
#include <callback.h>
namespace smo {
namespace sense_api {
@@ -54,10 +55,10 @@ public:
void attachSenseDeviceReq(
const std::shared_ptr<device::DeviceAttachmentSpec>& spec,
attachSenseDeviceReqCbFn cb);
Callback<attachSenseDeviceReqCbFn> cb);
void detachSenseDeviceReq(
const std::shared_ptr<device::DeviceAttachmentSpec>& spec,
detachSenseDeviceReqCbFn cb);
Callback<detachSenseDeviceReqCbFn> cb);
typedef std::function<void(AsynchronousLoop &results)>
attachAllSenseDevicesFromSpecsReqCbFn;
@@ -65,9 +66,9 @@ public:
detachAllSenseDevicesReqCbFn;
void attachAllSenseDevicesFromSpecsReq(
attachAllSenseDevicesFromSpecsReqCbFn cb);
Callback<attachAllSenseDevicesFromSpecsReqCbFn> cb);
void detachAllSenseDevicesReq(
detachAllSenseDevicesReqCbFn cb);
Callback<detachAllSenseDevicesReqCbFn> cb);
std::string stringifyLibs() const;
+12 -11
View File
@@ -1,6 +1,7 @@
#include <iostream>
#include <asynchronousContinuation.h>
#include <asynchronousLoop.h>
#include <callback.h>
#include <component.h>
#include <componentThread.h>
#include <mindManager/mindManager.h>
@@ -15,7 +16,7 @@ class MarionetteComponent::MrnttLifetimeMgmtOp
public:
MrnttLifetimeMgmtOp(
MarionetteComponent &parent, const std::shared_ptr<ComponentThread> &caller,
mrnttLifetimeMgmtOpCbFn callback)
Callback<mrnttLifetimeMgmtOpCbFn> callback)
: PostedAsynchronousContinuation<mrnttLifetimeMgmtOpCbFn>(
caller, callback),
parent(parent)
@@ -37,10 +38,9 @@ public:
}
smo::mind::globalMind = std::make_shared<Mind>();
smo::mind::globalMind->initializeReq(
std::bind(
&MrnttLifetimeMgmtOp::initializeReq2,
this, context, std::placeholders::_1));
smo::mind::globalMind->initializeReq({context, std::bind(
&MrnttLifetimeMgmtOp::initializeReq2,
this, context, std::placeholders::_1)});
}
void initializeReq2(
@@ -70,10 +70,9 @@ public:
+ ": Must be executed on Marionette thread");
}
smo::mind::globalMind->finalizeReq(
std::bind(
&MrnttLifetimeMgmtOp::finalizeReq2,
this, context, std::placeholders::_1));
smo::mind::globalMind->finalizeReq({context, std::bind(
&MrnttLifetimeMgmtOp::finalizeReq2,
this, context, std::placeholders::_1)});
}
void finalizeReq2(
@@ -93,7 +92,8 @@ public:
}
};
void MarionetteComponent::initializeReq(mrnttLifetimeMgmtOpCbFn callback)
void MarionetteComponent::initializeReq(
Callback<mrnttLifetimeMgmtOpCbFn> callback)
{
auto mrntt = ComponentThread::getSelf();
@@ -112,7 +112,8 @@ void MarionetteComponent::initializeReq(mrnttLifetimeMgmtOpCbFn callback)
request.get(), request));
}
void MarionetteComponent::finalizeReq(mrnttLifetimeMgmtOpCbFn callback)
void MarionetteComponent::finalizeReq(
Callback<mrnttLifetimeMgmtOpCbFn> callback)
{
auto mrntt = ComponentThread::getSelf();
+11 -15
View File
@@ -56,10 +56,9 @@ void marionetteInitializeReqCb(bool success)
std::cerr << __func__ << ": Failed to initialize Marionette. Shutting down."
<< '\n';
mrntt::mrntt.finalizeReq(
std::bind(
&mrntt::marionetteFinalizeReqCb,
std::placeholders::_1));
mrntt::mrntt.finalizeReq({nullptr, std::bind(
&mrntt::marionetteFinalizeReqCb,
std::placeholders::_1)});
}
} // namespace mrntt
@@ -92,10 +91,9 @@ void MarionetteThread::main(MarionetteThread& self)
default:
break;
}
mrntt::mrntt.finalizeReq(
std::bind(
&mrntt::marionetteFinalizeReqCb,
std::placeholders::_1));
mrntt::mrntt.finalizeReq({nullptr, std::bind(
&mrntt::marionetteFinalizeReqCb,
std::placeholders::_1)});
}
);
@@ -137,9 +135,8 @@ void MarionetteThread::main(MarionetteThread& self)
callShutdownSalmanoff = true;
// Create new Mind instance just before initializeReq
mrntt::mrntt.initializeReq(
std::bind(
&mrntt::marionetteInitializeReqCb, std::placeholders::_1));
mrntt::mrntt.initializeReq({nullptr, std::bind(
&mrntt::marionetteInitializeReqCb, std::placeholders::_1)});
std::cout << __func__ << ": Entering event loop" << "\n";
@@ -183,10 +180,9 @@ void MarionetteThread::main(MarionetteThread& self)
if (sendExceptionInd)
{
mrntt::exitCode = EXIT_FAILURE;
mrntt::mrntt.finalizeReq(
std::bind(
&mrntt::marionetteFinalizeReqCb,
std::placeholders::_1));
mrntt::mrntt.finalizeReq({nullptr, std::bind(
&mrntt::marionetteFinalizeReqCb,
std::placeholders::_1)});
}
}
+53 -42
View File
@@ -2,6 +2,7 @@
#include <opts.h>
#include <asynchronousContinuation.h>
#include <asynchronousLoop.h>
#include <callback.h>
#include <mind.h>
#include <componentThread.h>
#include <director/director.h>
@@ -89,7 +90,7 @@ class Mind::MindLifetimeMgmtOp
public:
MindLifetimeMgmtOp(
Mind &parent, const std::shared_ptr<ComponentThread> &caller,
mindLifetimeMgmtOpCbFn callback)
Callback<mindLifetimeMgmtOpCbFn> callback)
: PostedAsynchronousContinuation<mindLifetimeMgmtOpCbFn>(
caller, callback),
parent(parent)
@@ -105,9 +106,9 @@ public:
{
/* Jolt the threads, then start them */
parent.joltAllMindThreadsReq(
std::bind(
{context, std::bind(
&MindLifetimeMgmtOp::initializeReq2,
context.get(), context));
context.get(), context)});
}
void initializeReq2(
@@ -117,9 +118,9 @@ public:
std::cout << "Mrntt: All mind threads JOLTed." << "\n";
parent.startAllMindThreadsReq(
std::bind(
{context, std::bind(
&MindLifetimeMgmtOp::initializeReq3,
context.get(), context));
context.get(), context)});
}
void initializeReq3(
@@ -129,9 +130,9 @@ public:
std::cout << "Mrntt: All mind threads started." << "\n";
parent.body.initializeReq(
std::bind(
{context, std::bind(
&MindLifetimeMgmtOp::initializeReq4,
context.get(), context, std::placeholders::_1));
context.get(), context, std::placeholders::_1)});
}
void initializeReq4(
@@ -148,9 +149,9 @@ public:
)
{
parent.body.finalizeReq(
std::bind(
{context, std::bind(
&MindLifetimeMgmtOp::finalizeReq2,
context.get(), context, std::placeholders::_1));
context.get(), context, std::placeholders::_1)});
}
void finalizeReq2(
@@ -169,9 +170,9 @@ public:
* messages from mrntt after processing the exit request.
*/
parent.joltAllMindThreadsReq(
std::bind(
{context, std::bind(
&MindLifetimeMgmtOp::finalizeReq3,
context.get(), context));
context.get(), context)});
}
void finalizeReq3(
@@ -181,9 +182,9 @@ public:
std::cout << "Mrntt: All mind threads JOLTed for finalization." << "\n";
parent.exitAllMindThreadsReq(
std::bind(
{context, std::bind(
&MindLifetimeMgmtOp::finalizeReq4,
context.get(), context));
context.get(), context)});
}
void finalizeReq4(
@@ -195,7 +196,7 @@ public:
}
};
void Mind::initializeReq(mindLifetimeMgmtOpCbFn callback)
void Mind::initializeReq(Callback<mindLifetimeMgmtOpCbFn> callback)
{
/* Distribute threads across available CPUs */
try
@@ -219,7 +220,7 @@ void Mind::initializeReq(mindLifetimeMgmtOpCbFn callback)
request.get(), request));
}
void Mind::finalizeReq(mindLifetimeMgmtOpCbFn callback)
void Mind::finalizeReq(Callback<mindLifetimeMgmtOpCbFn> callback)
{
const auto& caller = ComponentThread::getSelf();
auto request = std::make_shared<MindLifetimeMgmtOp>(
@@ -258,7 +259,7 @@ class Mind::MindThreadLifetimeMgmtOp
public:
MindThreadLifetimeMgmtOp(
Mind &parent,unsigned int nThreads,
mindThreadLifetimeMgmtOpCbFn callback)
Callback<mindThreadLifetimeMgmtOpCbFn> callback)
: NonPostedAsynchronousContinuation<mindThreadLifetimeMgmtOpCbFn>(callback),
loop(nThreads),
parent(parent)
@@ -311,21 +312,23 @@ public:
}
};
void Mind::joltAllMindThreadsReq(mindThreadLifetimeMgmtOpCbFn callback)
void Mind::joltAllMindThreadsReq(
Callback<mindThreadLifetimeMgmtOpCbFn> callback
)
{
if (threadsHaveBeenJolted)
{
std::cout << "Mrntt: All mind threads already JOLTed. "
<< "Skipping JOLT request." << "\n";
callback();
callback.callbackFn();
return;
}
// If no threads, set flag and call callback immediately
if (componentThreads.size() == 0 && callback)
if (componentThreads.size() == 0 && callback.callbackFn)
{
threadsHaveBeenJolted = true;
callback();
callback.callbackFn();
return;
}
@@ -336,19 +339,21 @@ void Mind::joltAllMindThreadsReq(mindThreadLifetimeMgmtOpCbFn callback)
for (auto& thread : componentThreads)
{
thread->joltThreadReq(
std::bind(
{request, std::bind(
&MindThreadLifetimeMgmtOp::joltAllMindThreadsReq1,
request.get(), request));
request.get(), request)});
}
}
// Thread management methods (moved from ComponentThread)
void Mind::startAllMindThreadsReq(mindThreadLifetimeMgmtOpCbFn callback)
void Mind::startAllMindThreadsReq(
Callback<mindThreadLifetimeMgmtOpCbFn> callback
)
{
// If no threads, call callback immediately
if (componentThreads.size() == 0 && callback)
if (componentThreads.size() == 0 && callback.callbackFn)
{
callback();
callback.callbackFn();
return;
}
@@ -359,18 +364,20 @@ void Mind::startAllMindThreadsReq(mindThreadLifetimeMgmtOpCbFn callback)
for (auto& thread : componentThreads)
{
thread->startThreadReq(
std::bind(
{request, std::bind(
&MindThreadLifetimeMgmtOp::executeGenericOpOnAllMindThreadsReq1,
request.get(), request));
request.get(), request)});
}
}
void Mind::pauseAllMindThreadsReq(mindThreadLifetimeMgmtOpCbFn callback)
void Mind::pauseAllMindThreadsReq(
Callback<mindThreadLifetimeMgmtOpCbFn> callback
)
{
// If no threads, call callback immediately
if (componentThreads.size() == 0 && callback)
if (componentThreads.size() == 0 && callback.callbackFn)
{
callback();
callback.callbackFn();
return;
}
@@ -381,18 +388,20 @@ void Mind::pauseAllMindThreadsReq(mindThreadLifetimeMgmtOpCbFn callback)
for (auto& thread : componentThreads)
{
thread->pauseThreadReq(
std::bind(
{request, std::bind(
&MindThreadLifetimeMgmtOp::executeGenericOpOnAllMindThreadsReq1,
request.get(), request));
request.get(), request)});
}
}
void Mind::resumeAllMindThreadsReq(mindThreadLifetimeMgmtOpCbFn callback)
void Mind::resumeAllMindThreadsReq(
Callback<mindThreadLifetimeMgmtOpCbFn> callback
)
{
// If no threads, call callback immediately
if (componentThreads.size() == 0 && callback)
if (componentThreads.size() == 0 && callback.callbackFn)
{
callback();
callback.callbackFn();
return;
}
@@ -403,18 +412,20 @@ void Mind::resumeAllMindThreadsReq(mindThreadLifetimeMgmtOpCbFn callback)
for (auto& thread : componentThreads)
{
thread->resumeThreadReq(
std::bind(
{request, std::bind(
&MindThreadLifetimeMgmtOp::executeGenericOpOnAllMindThreadsReq1,
request.get(), request));
request.get(), request)});
}
}
void Mind::exitAllMindThreadsReq(mindThreadLifetimeMgmtOpCbFn callback)
void Mind::exitAllMindThreadsReq(
Callback<mindThreadLifetimeMgmtOpCbFn> callback
)
{
// If no threads, call callback immediately
if (componentThreads.size() == 0 && callback)
if (componentThreads.size() == 0 && callback.callbackFn)
{
callback();
callback.callbackFn();
return;
}
@@ -425,9 +436,9 @@ void Mind::exitAllMindThreadsReq(mindThreadLifetimeMgmtOpCbFn callback)
for (auto& thread : componentThreads)
{
thread->exitThreadReq(
std::bind(
{request, std::bind(
&MindThreadLifetimeMgmtOp::executeGenericOpOnAllMindThreadsReq1,
request.get(), request));
request.get(), request)});
}
}
+17 -16
View File
@@ -8,6 +8,7 @@
#include <asynchronousBridge.h>
#include <asynchronousContinuation.h>
#include <asynchronousLoop.h>
#include <callback.h>
#include <user/senseApiDesc.h>
#include <mind.h>
#include <deviceManager/deviceManager.h>
@@ -268,7 +269,7 @@ public:
AttachSenseDeviceReq(
const std::shared_ptr<device::DeviceAttachmentSpec>& spec,
const std::shared_ptr<ComponentThread> &caller,
attachSenseDeviceReqCbFn cb)
Callback<attachSenseDeviceReqCbFn> cb)
: PostedAsynchronousContinuation<attachSenseDeviceReqCbFn>(
caller, cb),
spec(spec)
@@ -335,10 +336,10 @@ public:
lib.senseApiDesc.sal_mgmt_libOps.attachDeviceReq(
spec, threadForAttachment,
std::bind(
{context, std::bind(
&AttachSenseDeviceReq::attachSenseDeviceReq2,
context.get(), context,
std::placeholders::_1, std::placeholders::_2));
std::placeholders::_1, std::placeholders::_2)});
}
void attachSenseDeviceReq2(
@@ -386,10 +387,10 @@ public:
}
lib.senseApiDesc.sal_mgmt_libOps.detachDeviceReq(
spec,
std::bind(
{context, std::bind(
&DetachSenseDeviceReq::detachSenseDeviceReq2,
context.get(), context,
std::placeholders::_1, std::placeholders::_2));
std::placeholders::_1, std::placeholders::_2)});
}
void detachSenseDeviceReq2(
@@ -407,7 +408,7 @@ public:
void SenseApiManager::attachSenseDeviceReq(
const std::shared_ptr<device::DeviceAttachmentSpec>& spec,
attachSenseDeviceReqCbFn cb
Callback<attachSenseDeviceReqCbFn> cb
)
{
const auto& caller = ComponentThread::getSelf();
@@ -422,7 +423,7 @@ void SenseApiManager::attachSenseDeviceReq(
void SenseApiManager::detachSenseDeviceReq(
const std::shared_ptr<device::DeviceAttachmentSpec>& spec,
detachSenseDeviceReqCbFn cb
Callback<detachSenseDeviceReqCbFn> cb
)
{
const auto& caller = ComponentThread::getSelf();
@@ -443,7 +444,7 @@ public:
AttachAllSenseDevicesFromSpecsReq(
const unsigned int totalNSpecs,
const std::shared_ptr<ComponentThread>& caller,
attachAllSenseDevicesFromSpecsReqCbFn cb)
Callback<attachAllSenseDevicesFromSpecsReqCbFn> cb)
: PostedAsynchronousContinuation<attachAllSenseDevicesFromSpecsReqCbFn>(
caller, cb),
loop(totalNSpecs)
@@ -458,10 +459,10 @@ public:
{
SenseApiManager::getInstance().attachSenseDeviceReq(
spec,
std::bind(
{context, std::bind(
&AttachAllSenseDevicesFromSpecsReq::attachAllSenseDevicesFromSpecsReq2,
context.get(), context,
std::placeholders::_1, std::placeholders::_2));
std::placeholders::_1, std::placeholders::_2)});
}
}
@@ -499,13 +500,13 @@ public:
};
void SenseApiManager::attachAllSenseDevicesFromSpecsReq(
attachAllSenseDevicesFromSpecsReqCbFn cb
Callback<attachAllSenseDevicesFromSpecsReqCbFn> cb
)
{
if (device::DeviceManager::getInstance().deviceAttachmentSpecs.size() == 0)
{
AsynchronousLoop tmp(0);
cb(tmp);
cb.callbackFn(tmp);
return;
}
@@ -534,10 +535,10 @@ public:
{
SenseApiManager::getInstance().detachSenseDeviceReq(
spec,
std::bind(
{context, std::bind(
&DetachAllSenseDevicesReq::detachAllSenseDevicesReq2,
context.get(), context,
std::placeholders::_1, std::placeholders::_2));
std::placeholders::_1, std::placeholders::_2)});
}
}
@@ -571,13 +572,13 @@ public:
};
void SenseApiManager::detachAllSenseDevicesReq(
detachAllSenseDevicesReqCbFn cb
Callback<detachAllSenseDevicesReqCbFn> cb
)
{
if (device::DeviceManager::getInstance().deviceAttachmentSpecs.size() == 0)
{
AsynchronousLoop tmp(0);
cb(tmp);
cb.callbackFn(tmp);
return;
}