Use DynamicViralPostingInvoker in at/detachStimBuffDeviceCReq
This commit is contained in:
@@ -9,7 +9,9 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include <preprocessor.h>
|
#include <preprocessor.h>
|
||||||
#include <user/deviceAttachmentSpec.h>
|
#include <user/deviceAttachmentSpec.h>
|
||||||
|
#include <spinscale/co/dynamicPostingInvoker.h>
|
||||||
#include <spinscale/co/invokers.h>
|
#include <spinscale/co/invokers.h>
|
||||||
|
#include <spinscale/co/postTarget.h>
|
||||||
#include <spinscale/componentThread.h>
|
#include <spinscale/componentThread.h>
|
||||||
#define CL_TARGET_OPENCL_VERSION 120
|
#define CL_TARGET_OPENCL_VERSION 120
|
||||||
#include <CL/cl.h>
|
#include <CL/cl.h>
|
||||||
@@ -41,8 +43,9 @@ struct SmoThreadingModelDesc
|
|||||||
* SMO will usually pass in the Marionette thread here.
|
* SMO will usually pass in the Marionette thread here.
|
||||||
*
|
*
|
||||||
* State management that's tied to a particular attachment spec should be
|
* State management that's tied to a particular attachment spec should be
|
||||||
* done on the ComponentThread for the thread that SMO provided in the
|
* done on the ComponentThread passed to attachDeviceCReq. The attach and
|
||||||
* attachDeviceCReq call.
|
* detach coroutines run on the thread named by ExplicitPostTarget (post-TO);
|
||||||
|
* SMO orchestration stays on the marionette thread.
|
||||||
*/
|
*/
|
||||||
std::shared_ptr<sscl::ComponentThread> componentThread;
|
std::shared_ptr<sscl::ComponentThread> componentThread;
|
||||||
};
|
};
|
||||||
@@ -55,10 +58,14 @@ struct StimBuffDeviceOpResult
|
|||||||
|
|
||||||
using sal_mlo_initializeCIndFn = sscl::co::ViralNonPostingInvoker<int>(void);
|
using sal_mlo_initializeCIndFn = sscl::co::ViralNonPostingInvoker<int>(void);
|
||||||
using sal_mlo_finalizeCIndFn = sscl::co::ViralNonPostingInvoker<int>(void);
|
using sal_mlo_finalizeCIndFn = sscl::co::ViralNonPostingInvoker<int>(void);
|
||||||
using sal_mlo_attachDeviceCReqFn = sscl::co::ViralNonPostingInvoker<StimBuffDeviceOpResult>(
|
using sal_mlo_attachDeviceCReqFn =
|
||||||
|
sscl::co::DynamicViralPostingInvoker<StimBuffDeviceOpResult>(
|
||||||
|
sscl::co::ExplicitPostTarget postTarget,
|
||||||
const std::shared_ptr<device::DeviceAttachmentSpec>& desc,
|
const std::shared_ptr<device::DeviceAttachmentSpec>& desc,
|
||||||
const std::shared_ptr<sscl::ComponentThread>& componentThread);
|
const std::shared_ptr<sscl::ComponentThread>& componentThread);
|
||||||
using sal_mlo_detachDeviceCReqFn = sscl::co::ViralNonPostingInvoker<StimBuffDeviceOpResult>(
|
using sal_mlo_detachDeviceCReqFn =
|
||||||
|
sscl::co::DynamicViralPostingInvoker<StimBuffDeviceOpResult>(
|
||||||
|
sscl::co::ExplicitPostTarget postTarget,
|
||||||
const std::shared_ptr<device::DeviceAttachmentSpec>& desc);
|
const std::shared_ptr<device::DeviceAttachmentSpec>& desc);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+1
-1
Submodule libspinscale updated: a53e0ca325...c60854845d
@@ -14,6 +14,7 @@
|
|||||||
#include <marionette/marionette.h>
|
#include <marionette/marionette.h>
|
||||||
#include <marionette/marionetteThread.h>
|
#include <marionette/marionetteThread.h>
|
||||||
#include <mind.h>
|
#include <mind.h>
|
||||||
|
#include <spinscale/co/postTarget.h>
|
||||||
#include <spinscale/co/group.h>
|
#include <spinscale/co/group.h>
|
||||||
|
|
||||||
namespace smo {
|
namespace smo {
|
||||||
@@ -32,6 +33,16 @@ void assertMarionetteThread()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<sscl::ComponentThread> threadForDeviceOp(
|
||||||
|
const DeviceAttachmentSpec& spec)
|
||||||
|
{
|
||||||
|
if (spec.sensorType == 'e') {
|
||||||
|
return mind::globalMind->world.thread;
|
||||||
|
}
|
||||||
|
|
||||||
|
return mind::globalMind->body.thread;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
DeviceManager::~DeviceManager()
|
DeviceManager::~DeviceManager()
|
||||||
@@ -87,29 +98,30 @@ DeviceManager::attachStimBuffDeviceCReq(
|
|||||||
co_await lib.s.lock.getAcquireInvocationAndSuspensionPolicy();
|
co_await lib.s.lock.getAcquireInvocationAndSuspensionPolicy();
|
||||||
sbamGuard.release();
|
sbamGuard.release();
|
||||||
|
|
||||||
/** EXPLANATION:
|
/** EXPLANATION:
|
||||||
* We pass in either the body or world thread here, depending on whether
|
* We pass in either the body or world thread here, depending on whether
|
||||||
* the device is an introspector (idev) or extrospector (edev).
|
* the device is an introspector (idev) or extrospector (edev).
|
||||||
*
|
*
|
||||||
* Introspectors are attached to the body thread; extrospectors are
|
* Introspectors are attached to the body thread; extrospectors are
|
||||||
* attached to the world thread.
|
* attached to the world thread.
|
||||||
*/
|
*/
|
||||||
std::shared_ptr<sscl::ComponentThread> threadForAttachment;
|
std::shared_ptr<sscl::ComponentThread> targetThread =
|
||||||
|
threadForDeviceOp(*spec);
|
||||||
|
|
||||||
if (spec->sensorType == 'e')
|
if (spec->sensorType == 'e')
|
||||||
{
|
{
|
||||||
threadForAttachment = mind::globalMind->world.thread;
|
|
||||||
std::cout << __func__ << ": Attaching edev "
|
std::cout << __func__ << ": Attaching edev "
|
||||||
<< spec->deviceIdentifier << " to world thread" << "\n";
|
<< spec->deviceIdentifier << " to world thread" << "\n";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
threadForAttachment = mind::globalMind->body.thread;
|
|
||||||
std::cout << __func__ << ": Attaching non-edev "
|
std::cout << __func__ << ": Attaching non-edev "
|
||||||
<< spec->deviceIdentifier << " to body thread" << "\n";
|
<< spec->deviceIdentifier << " to body thread" << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
co_return co_await lib.stimBuffApiDesc.sal_mgmt_libOps.attachDeviceCReq(
|
co_return co_await lib.stimBuffApiDesc.sal_mgmt_libOps.attachDeviceCReq(
|
||||||
spec, threadForAttachment);
|
sscl::co::ExplicitPostTarget{targetThread->getIoContext()},
|
||||||
|
spec, targetThread);
|
||||||
}
|
}
|
||||||
|
|
||||||
mrntt::MrnttViralPostingInvoker<stim_buff::StimBuffDeviceOpResult>
|
mrntt::MrnttViralPostingInvoker<stim_buff::StimBuffDeviceOpResult>
|
||||||
@@ -150,7 +162,11 @@ DeviceManager::detachStimBuffDeviceCReq(
|
|||||||
co_await lib.s.lock.getAcquireInvocationAndSuspensionPolicy();
|
co_await lib.s.lock.getAcquireInvocationAndSuspensionPolicy();
|
||||||
sbamGuard.release();
|
sbamGuard.release();
|
||||||
|
|
||||||
|
std::shared_ptr<sscl::ComponentThread> targetThread =
|
||||||
|
threadForDeviceOp(*spec);
|
||||||
|
|
||||||
co_return co_await lib.stimBuffApiDesc.sal_mgmt_libOps.detachDeviceCReq(
|
co_return co_await lib.stimBuffApiDesc.sal_mgmt_libOps.detachDeviceCReq(
|
||||||
|
sscl::co::ExplicitPostTarget{targetThread->getIoContext()},
|
||||||
spec);
|
spec);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -452,11 +452,13 @@ attachByCreatingProducer(
|
|||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
sscl::co::ViralNonPostingInvoker<StimBuffDeviceOpResult>
|
sscl::co::DynamicViralPostingInvoker<StimBuffDeviceOpResult>
|
||||||
livoxGen1_attachDeviceCReq(
|
livoxGen1_attachDeviceCReq(
|
||||||
|
[[maybe_unused]] sscl::co::ExplicitPostTarget postTarget,
|
||||||
const std::shared_ptr<device::DeviceAttachmentSpec> &desc,
|
const std::shared_ptr<device::DeviceAttachmentSpec> &desc,
|
||||||
const std::shared_ptr<sscl::ComponentThread> &componentThread)
|
const std::shared_ptr<sscl::ComponentThread> &componentThread)
|
||||||
{
|
{
|
||||||
|
(void)postTarget;
|
||||||
if (!livoxProto1.livoxProto1_getOrCreateDeviceCReq)
|
if (!livoxProto1.livoxProto1_getOrCreateDeviceCReq)
|
||||||
{
|
{
|
||||||
throw std::runtime_error(
|
throw std::runtime_error(
|
||||||
@@ -482,10 +484,12 @@ livoxGen1_attachDeviceCReq(
|
|||||||
co_return co_await attachByCreatingProducer(desc, componentThread);
|
co_return co_await attachByCreatingProducer(desc, componentThread);
|
||||||
}
|
}
|
||||||
|
|
||||||
sscl::co::ViralNonPostingInvoker<StimBuffDeviceOpResult>
|
sscl::co::DynamicViralPostingInvoker<StimBuffDeviceOpResult>
|
||||||
livoxGen1_detachDeviceCReq(
|
livoxGen1_detachDeviceCReq(
|
||||||
|
[[maybe_unused]] sscl::co::ExplicitPostTarget postTarget,
|
||||||
const std::shared_ptr<device::DeviceAttachmentSpec> &desc)
|
const std::shared_ptr<device::DeviceAttachmentSpec> &desc)
|
||||||
{
|
{
|
||||||
|
(void)postTarget;
|
||||||
// Case 1: Check if StimBuffer doesn't exist (early return)
|
// Case 1: Check if StimBuffer doesn't exist (early return)
|
||||||
auto stimProducerBase = getStimulusProducer(desc);
|
auto stimProducerBase = getStimulusProducer(desc);
|
||||||
if (!stimProducerBase) {
|
if (!stimProducerBase) {
|
||||||
|
|||||||
@@ -46,10 +46,16 @@ bool ensureStimBufferAttachedWithoutDuplicates(
|
|||||||
|
|
||||||
sscl::co::ViralNonPostingInvoker<int> livoxGen1_initializeCInd();
|
sscl::co::ViralNonPostingInvoker<int> livoxGen1_initializeCInd();
|
||||||
sscl::co::ViralNonPostingInvoker<int> livoxGen1_finalizeCInd();
|
sscl::co::ViralNonPostingInvoker<int> livoxGen1_finalizeCInd();
|
||||||
sscl::co::ViralNonPostingInvoker<StimBuffDeviceOpResult> livoxGen1_attachDeviceCReq(
|
|
||||||
|
sscl::co::DynamicViralPostingInvoker<StimBuffDeviceOpResult>
|
||||||
|
livoxGen1_attachDeviceCReq(
|
||||||
|
sscl::co::ExplicitPostTarget postTarget,
|
||||||
const std::shared_ptr<device::DeviceAttachmentSpec> &desc,
|
const std::shared_ptr<device::DeviceAttachmentSpec> &desc,
|
||||||
const std::shared_ptr<sscl::ComponentThread> &componentThread);
|
const std::shared_ptr<sscl::ComponentThread> &componentThread);
|
||||||
sscl::co::ViralNonPostingInvoker<StimBuffDeviceOpResult> livoxGen1_detachDeviceCReq(
|
|
||||||
|
sscl::co::DynamicViralPostingInvoker<StimBuffDeviceOpResult>
|
||||||
|
livoxGen1_detachDeviceCReq(
|
||||||
|
sscl::co::ExplicitPostTarget postTarget,
|
||||||
const std::shared_ptr<device::DeviceAttachmentSpec> &desc);
|
const std::shared_ptr<device::DeviceAttachmentSpec> &desc);
|
||||||
|
|
||||||
} // namespace smo::stim_buff
|
} // namespace smo::stim_buff
|
||||||
|
|||||||
@@ -274,13 +274,15 @@ static sscl::co::ViralNonPostingInvoker<int> xcbWindow_finalizeCInd(void)
|
|||||||
co_return 0;
|
co_return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static sscl::co::ViralNonPostingInvoker<smo::stim_buff::StimBuffDeviceOpResult>
|
static sscl::co::DynamicViralPostingInvoker<smo::stim_buff::StimBuffDeviceOpResult>
|
||||||
xcbWindow_attachDeviceCReq(
|
xcbWindow_attachDeviceCReq(
|
||||||
const std::shared_ptr<smo::device::DeviceAttachmentSpec>& desc,
|
[[maybe_unused]] sscl::co::ExplicitPostTarget postTarget,
|
||||||
|
const std::shared_ptr<smo::device::DeviceAttachmentSpec>& desc,
|
||||||
const std::shared_ptr<sscl::ComponentThread>& componentThread)
|
const std::shared_ptr<sscl::ComponentThread>& componentThread)
|
||||||
{
|
{
|
||||||
|
(void)postTarget;
|
||||||
// Not used yet, but may be used later.
|
// Not used yet, but may be used later.
|
||||||
(void)componentThread;
|
(void)componentThread;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
g_attachedWindows.emplace_back(
|
g_attachedWindows.emplace_back(
|
||||||
@@ -298,10 +300,12 @@ xcbWindow_attachDeviceCReq(
|
|||||||
co_return smo::stim_buff::StimBuffDeviceOpResult{true, desc};
|
co_return smo::stim_buff::StimBuffDeviceOpResult{true, desc};
|
||||||
}
|
}
|
||||||
|
|
||||||
static sscl::co::ViralNonPostingInvoker<smo::stim_buff::StimBuffDeviceOpResult>
|
static sscl::co::DynamicViralPostingInvoker<smo::stim_buff::StimBuffDeviceOpResult>
|
||||||
xcbWindow_detachDeviceCReq(
|
xcbWindow_detachDeviceCReq(
|
||||||
const std::shared_ptr<smo::device::DeviceAttachmentSpec>& spec)
|
[[maybe_unused]] sscl::co::ExplicitPostTarget postTarget,
|
||||||
|
const std::shared_ptr<smo::device::DeviceAttachmentSpec>& spec)
|
||||||
{
|
{
|
||||||
|
(void)postTarget;
|
||||||
auto it = std::find_if(g_attachedWindows.begin(), g_attachedWindows.end(),
|
auto it = std::find_if(g_attachedWindows.begin(), g_attachedWindows.end(),
|
||||||
[&spec](const std::unique_ptr<xcb_window::AttachedWindow>& window) {
|
[&spec](const std::unique_ptr<xcb_window::AttachedWindow>& window) {
|
||||||
return window->getDeviceAttachmentSpec() == spec;
|
return window->getDeviceAttachmentSpec() == spec;
|
||||||
|
|||||||
Reference in New Issue
Block a user