DevMgr:attachAllUnattachedDevicesFromKnownListReq: acquire qutex
We should acquire the qutex here before iterating through the list of DA specs.
This commit is contained in:
@@ -623,37 +623,92 @@ void DeviceManager::attachAllUnattachedDevicesFromCmdlineReq(
|
|||||||
attachAllUnattachedDevicesFromReq(specs, std::move(cb));
|
attachAllUnattachedDevicesFromReq(specs, std::move(cb));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class DeviceManager::AttachAllUnattachedDevicesFromKnownListReq
|
||||||
|
: 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
|
||||||
|
auto unattachedSpecs = std::make_shared<
|
||||||
|
std::vector<DeviceAttachmentSpec>>();
|
||||||
|
|
||||||
|
// Cycle through all DA specs in deviceAttachmentSpecs
|
||||||
|
for (const auto& spec : DeviceManager::deviceAttachmentSpecs)
|
||||||
|
{
|
||||||
|
bool isAttached = false;
|
||||||
|
|
||||||
|
// Cross reference with attachedDeviceRoles
|
||||||
|
for (const auto& role : DeviceManager::attachedDeviceRoles)
|
||||||
|
{
|
||||||
|
if (*role->deviceAttachmentSpec == *spec)
|
||||||
|
{
|
||||||
|
isAttached = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If spec doesn't appear in attachedDeviceRoles, add it to vector
|
||||||
|
if (!isAttached) {
|
||||||
|
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
|
||||||
|
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(
|
void DeviceManager::attachAllUnattachedDevicesFromKnownListReq(
|
||||||
Callback<attachAllUnattachedDevicesFromReqCbFn> cb
|
Callback<attachAllUnattachedDevicesFromReqCbFn> cb
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
// Create a vector to hold unattached device specs
|
const auto& caller = ComponentThread::getSelf();
|
||||||
auto unattachedSpecs = std::make_shared<
|
|
||||||
std::vector<DeviceAttachmentSpec>>();
|
|
||||||
|
|
||||||
// Cycle through all DA specs in deviceAttachmentSpecs
|
auto request = std::make_shared<AttachAllUnattachedDevicesFromKnownListReq>(
|
||||||
for (const auto& spec : deviceAttachmentSpecs)
|
caller, cb,
|
||||||
{
|
LockSet<attachAllUnattachedDevicesFromReqCbFn>::Set{
|
||||||
bool isAttached = false;
|
std::ref(DeviceManager::getInstance().qutex)
|
||||||
|
});
|
||||||
|
|
||||||
// Cross reference with attachedDeviceRoles
|
AttachAllUnattachedDevicesFromKnownListReq::LockerAndInvoker lockvoker(
|
||||||
for (const auto& role : attachedDeviceRoles)
|
*request, mrntt::mrntt.thread,
|
||||||
{
|
std::bind(
|
||||||
if (*role->deviceAttachmentSpec == *spec)
|
&AttachAllUnattachedDevicesFromKnownListReq
|
||||||
{
|
::attachAllUnattachedDevicesFromKnownListReq1_posted,
|
||||||
isAttached = true;
|
request.get(), request));
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// If spec doesn't appear in attachedDeviceRoles, add it to the vector
|
|
||||||
if (!isAttached) {
|
|
||||||
unattachedSpecs->push_back(*spec);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Pass the vector to the existing function
|
|
||||||
attachAllUnattachedDevicesFromReq(unattachedSpecs, std::move(cb));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user