DevMgr:at/detachSenseDevReq: acquire Api lib Qutex

This commit is contained in:
2025-09-30 18:12:20 -04:00
parent b0d61c3e38
commit e600b0f96e
2 changed files with 45 additions and 4 deletions
+2
View File
@@ -34,6 +34,8 @@ public:
std::reference_wrapper<Qutex>, std::reference_wrapper<Qutex>,
typename LockerAndInvokerBase::List::iterator> LockUsageDesc; typename LockerAndInvokerBase::List::iterator> LockUsageDesc;
typedef std::vector<std::reference_wrapper<Qutex>> Set;
public: public:
/** /**
* @brief Constructor * @brief Constructor
+43 -4
View File
@@ -323,9 +323,10 @@ public:
AttachSenseDeviceReq( AttachSenseDeviceReq(
const std::shared_ptr<DeviceAttachmentSpec>& spec, const std::shared_ptr<DeviceAttachmentSpec>& spec,
const std::shared_ptr<ComponentThread> &caller, const std::shared_ptr<ComponentThread> &caller,
Callback<attachSenseDeviceReqCbFn> cb) Callback<attachSenseDeviceReqCbFn> cb,
std::vector<std::reference_wrapper<Qutex>> requiredLocks)
: SerializedAsynchronousContinuation<attachSenseDeviceReqCbFn>( : SerializedAsynchronousContinuation<attachSenseDeviceReqCbFn>(
caller, cb, {std::ref(DeviceManager::getInstance().qutex)}), caller, cb, requiredLocks),
spec(spec) spec(spec)
{} {}
@@ -467,8 +468,27 @@ void DeviceManager::attachSenseDeviceReq(
) )
{ {
const auto& caller = ComponentThread::getSelf(); const auto& caller = ComponentThread::getSelf();
// Get the sense API lib's qutex
auto libOpt = sense_api::SenseApiManager::getInstance()
.getSenseApiLibByApiName(spec->api);
if (!libOpt)
{
std::cerr << "attachSenseDeviceReq: No library found for API '"
<< spec->api << "'" << std::endl;
cb.callbackFn(false, spec);
return;
}
auto& lib = *libOpt.value();
auto request = std::make_shared<AttachSenseDeviceReq>( auto request = std::make_shared<AttachSenseDeviceReq>(
spec, caller, cb); spec, caller, cb,
LockSet<attachSenseDeviceReqCbFn>::Set{
std::ref(DeviceManager::getInstance().qutex),
std::ref(lib.qutex)
});
AttachSenseDeviceReq::LockerAndInvoker lockvoker( AttachSenseDeviceReq::LockerAndInvoker lockvoker(
*request, mrntt::mrntt.thread, *request, mrntt::mrntt.thread,
@@ -483,8 +503,27 @@ void DeviceManager::detachSenseDeviceReq(
) )
{ {
const auto& caller = ComponentThread::getSelf(); const auto& caller = ComponentThread::getSelf();
// Get the sense API lib's qutex
auto libOpt = sense_api::SenseApiManager::getInstance()
.getSenseApiLibByApiName(spec->api);
if (!libOpt)
{
std::cerr << "detachSenseDeviceReq: No library found for API '"
<< spec->api << "'" << std::endl;
cb.callbackFn(false, spec);
return;
}
auto& lib = *libOpt.value();
auto request = std::make_shared<DetachSenseDeviceReq>( auto request = std::make_shared<DetachSenseDeviceReq>(
spec, caller, cb); spec, caller, cb,
LockSet<detachSenseDeviceReqCbFn>::Set{
std::ref(DeviceManager::getInstance().qutex),
std::ref(lib.qutex)
});
DetachSenseDeviceReq::LockerAndInvoker lockvoker( DetachSenseDeviceReq::LockerAndInvoker lockvoker(
*request, mrntt::mrntt.thread, *request, mrntt::mrntt.thread,