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));
|
||||
}
|
||||
|
||||
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(
|
||||
Callback<attachAllUnattachedDevicesFromReqCbFn> cb
|
||||
)
|
||||
{
|
||||
// Create a vector to hold unattached device specs
|
||||
auto unattachedSpecs = std::make_shared<
|
||||
std::vector<DeviceAttachmentSpec>>();
|
||||
const auto& caller = ComponentThread::getSelf();
|
||||
|
||||
auto request = std::make_shared<AttachAllUnattachedDevicesFromKnownListReq>(
|
||||
caller, cb,
|
||||
LockSet<attachAllUnattachedDevicesFromReqCbFn>::Set{
|
||||
std::ref(DeviceManager::getInstance().qutex)
|
||||
});
|
||||
|
||||
// Cycle through all DA specs in deviceAttachmentSpecs
|
||||
for (const auto& spec : deviceAttachmentSpecs)
|
||||
{
|
||||
bool isAttached = false;
|
||||
|
||||
// Cross reference with attachedDeviceRoles
|
||||
for (const auto& role : attachedDeviceRoles)
|
||||
{
|
||||
if (*role->deviceAttachmentSpec == *spec)
|
||||
{
|
||||
isAttached = true;
|
||||
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));
|
||||
AttachAllUnattachedDevicesFromKnownListReq::LockerAndInvoker lockvoker(
|
||||
*request, mrntt::mrntt.thread,
|
||||
std::bind(
|
||||
&AttachAllUnattachedDevicesFromKnownListReq
|
||||
::attachAllUnattachedDevicesFromKnownListReq1_posted,
|
||||
request.get(), request));
|
||||
}
|
||||
|
||||
class DeviceManager::DetachAllAttachedDeviceRoles
|
||||
|
||||
Reference in New Issue
Block a user