DevMgr:attachAllUnattachedDevicesFromKnownListReq: acquire qutex

We should acquire the qutex here before iterating through the list
of DA specs.
This commit is contained in:
2025-09-30 21:24:51 -04:00
parent 07609c6d6c
commit 06f3f2eebe
2 changed files with 82 additions and 26 deletions
+62 -7
View File
@@ -623,21 +623,37 @@ void DeviceManager::attachAllUnattachedDevicesFromCmdlineReq(
attachAllUnattachedDevicesFromReq(specs, std::move(cb)); attachAllUnattachedDevicesFromReq(specs, std::move(cb));
} }
void DeviceManager::attachAllUnattachedDevicesFromKnownListReq( class DeviceManager::AttachAllUnattachedDevicesFromKnownListReq
Callback<attachAllUnattachedDevicesFromReqCbFn> cb : public SerializedAsynchronousContinuation<
) attachAllUnattachedDevicesFromReqCbFn>
{ {
public:
AttachAllUnattachedDevicesFromKnownListReq(
const std::shared_ptr<ComponentThread> &caller,
Callback<attachAllUnattachedDevicesFromReqCbFn> cb,
std::vector<std::reference_wrapper<Qutex>> requiredLocks)
: SerializedAsynchronousContinuation<
attachAllUnattachedDevicesFromReqCbFn>(
caller, cb, requiredLocks)
{}
public:
void attachAllUnattachedDevicesFromKnownListReq1_posted(
[[maybe_unused]]
std::shared_ptr<AttachAllUnattachedDevicesFromKnownListReq> context
)
{
// Create a vector to hold unattached device specs // Create a vector to hold unattached device specs
auto unattachedSpecs = std::make_shared< auto unattachedSpecs = std::make_shared<
std::vector<DeviceAttachmentSpec>>(); std::vector<DeviceAttachmentSpec>>();
// Cycle through all DA specs in deviceAttachmentSpecs // Cycle through all DA specs in deviceAttachmentSpecs
for (const auto& spec : deviceAttachmentSpecs) for (const auto& spec : DeviceManager::deviceAttachmentSpecs)
{ {
bool isAttached = false; bool isAttached = false;
// Cross reference with attachedDeviceRoles // Cross reference with attachedDeviceRoles
for (const auto& role : attachedDeviceRoles) for (const auto& role : DeviceManager::attachedDeviceRoles)
{ {
if (*role->deviceAttachmentSpec == *spec) if (*role->deviceAttachmentSpec == *spec)
{ {
@@ -646,14 +662,53 @@ void DeviceManager::attachAllUnattachedDevicesFromKnownListReq(
} }
} }
// If spec doesn't appear in attachedDeviceRoles, add it to the vector // If spec doesn't appear in attachedDeviceRoles, add it to vector
if (!isAttached) { if (!isAttached) {
unattachedSpecs->push_back(*spec); unattachedSpecs->push_back(*spec);
} }
} }
// Release the DeviceManager qutex early before calling the inner method
DeviceManager::getInstance().qutex.release();
// Pass the vector to the existing function // Pass the vector to the existing function
attachAllUnattachedDevicesFromReq(unattachedSpecs, std::move(cb)); DeviceManager::getInstance().attachAllUnattachedDevicesFromReq(
unattachedSpecs,
{context, std::bind(
&AttachAllUnattachedDevicesFromKnownListReq
::attachAllUnattachedDevicesFromKnownListReq2,
context.get(), context,
std::placeholders::_1)});
}
void attachAllUnattachedDevicesFromKnownListReq2(
[[maybe_unused]]
std::shared_ptr<AttachAllUnattachedDevicesFromKnownListReq> context,
AsynchronousLoop loop
)
{
callOriginalCb(loop);
}
};
void DeviceManager::attachAllUnattachedDevicesFromKnownListReq(
Callback<attachAllUnattachedDevicesFromReqCbFn> cb
)
{
const auto& caller = ComponentThread::getSelf();
auto request = std::make_shared<AttachAllUnattachedDevicesFromKnownListReq>(
caller, cb,
LockSet<attachAllUnattachedDevicesFromReqCbFn>::Set{
std::ref(DeviceManager::getInstance().qutex)
});
AttachAllUnattachedDevicesFromKnownListReq::LockerAndInvoker lockvoker(
*request, mrntt::mrntt.thread,
std::bind(
&AttachAllUnattachedDevicesFromKnownListReq
::attachAllUnattachedDevicesFromKnownListReq1_posted,
request.get(), request));
} }
class DeviceManager::DetachAllAttachedDeviceRoles class DeviceManager::DetachAllAttachedDeviceRoles
@@ -111,6 +111,7 @@ private:
class AttachSenseDeviceReq; class AttachSenseDeviceReq;
typedef AttachSenseDeviceReq DetachSenseDeviceReq; typedef AttachSenseDeviceReq DetachSenseDeviceReq;
class AttachAllUnattachedDevicesFromReq; class AttachAllUnattachedDevicesFromReq;
class AttachAllUnattachedDevicesFromKnownListReq;
class DetachAllAttachedDeviceRoles; class DetachAllAttachedDeviceRoles;
}; };