DevMgr:removeDASpec: Make serialized; acquire DevMgr qutex

This commit is contained in:
2025-09-30 22:10:39 -04:00
parent ac3d97b3ec
commit 7ddbde1a2f
+55 -46
View File
@@ -170,26 +170,48 @@ public:
};
class DeviceManager::RemoveDeviceAttachmentSpecReq
: public PostedAsynchronousContinuation<removeDeviceAttachmentSpecReqCbFn>
: public SerializedAsynchronousContinuation<removeDeviceAttachmentSpecReqCbFn>
{
public:
RemoveDeviceAttachmentSpecReq(
const std::shared_ptr<DeviceAttachmentSpec> &s,
const DeviceAttachmentSpec &spec,
const std::shared_ptr<ComponentThread> &caller,
Callback<removeDeviceAttachmentSpecReqCbFn> cb)
: PostedAsynchronousContinuation<removeDeviceAttachmentSpecReqCbFn>(
caller, cb),
spec(s)
Callback<removeDeviceAttachmentSpecReqCbFn> cb,
std::vector<std::reference_wrapper<Qutex>> requiredLocks)
: SerializedAsynchronousContinuation<removeDeviceAttachmentSpecReqCbFn>(
caller, cb, requiredLocks),
spec(spec)
{}
public:
DeviceAttachmentSpec spec;
std::shared_ptr<DeviceAttachmentSpec> specPtr;
public:
void removeDeviceAttachmentSpecReq1_posted(
[[maybe_unused]] std::shared_ptr<RemoveDeviceAttachmentSpecReq> context
)
{
// Find the shared_ptr to the spec in the collection
for (const auto& existingSpec : DeviceManager::deviceAttachmentSpecs)
{
if (*existingSpec == spec)
{
specPtr = existingSpec;
break;
}
}
if (!specPtr)
{
// Spec not found, callback with failure and return
callOriginalCb(false, nullptr);
return;
}
// Call detachSenseDeviceReq first - only clean up metadata if this succeeds
DeviceManager::getInstance().detachSenseDeviceReq(
spec,
specPtr,
{context, std::bind(
&RemoveDeviceAttachmentSpecReq::removeDeviceAttachmentSpecReq2,
context.get(), context,
@@ -213,14 +235,14 @@ public:
try {
// Find the DeviceRole in attachedDeviceRoles
auto deviceRoleIt = std::find_if(
attachedDeviceRoles.begin(),
attachedDeviceRoles.end(),
[&spec = spec](const std::shared_ptr<DeviceRole> &role) {
return *role->deviceAttachmentSpec == *spec;
DeviceManager::attachedDeviceRoles.begin(),
DeviceManager::attachedDeviceRoles.end(),
[&specPtr = specPtr](const std::shared_ptr<DeviceRole> &role) {
return *role->deviceAttachmentSpec == *specPtr;
}
);
if (deviceRoleIt == attachedDeviceRoles.end())
if (deviceRoleIt == DeviceManager::attachedDeviceRoles.end())
{
// DeviceRole not found, callback with failure
callOriginalCb(false, deviceSpec);
@@ -231,7 +253,7 @@ public:
auto& device = deviceRole->parentDevice;
// Remove DeviceRole from DeviceManager's collection
attachedDeviceRoles.erase(deviceRoleIt);
DeviceManager::attachedDeviceRoles.erase(deviceRoleIt);
// Remove DeviceRole from Device's collection
auto deviceRoleIt2 = std::find(
@@ -245,14 +267,18 @@ public:
// Remove DeviceAttachmentSpec from deviceAttachmentSpecs collection
auto specIt = std::find_if(
deviceAttachmentSpecs.begin(),
deviceAttachmentSpecs.end(),
[&spec = spec](const std::shared_ptr<DeviceAttachmentSpec> &existingSpec) {
return *existingSpec == *spec;
});
if (specIt != deviceAttachmentSpecs.end())
DeviceManager::deviceAttachmentSpecs.begin(),
DeviceManager::deviceAttachmentSpecs.end(),
[&specPtr = specPtr](
const std::shared_ptr<DeviceAttachmentSpec> &existingSpec)
{
return *existingSpec == *specPtr;
}
);
if (specIt != DeviceManager::deviceAttachmentSpecs.end())
{
deviceAttachmentSpecs.erase(specIt);
DeviceManager::deviceAttachmentSpecs.erase(specIt);
}
// Callback with success
@@ -262,9 +288,6 @@ public:
callOriginalCb(false, deviceSpec);
}
}
public:
std::shared_ptr<DeviceAttachmentSpec> spec;
};
void DeviceManager::newDeviceAttachmentSpecInd(
@@ -290,33 +313,19 @@ void DeviceManager::removeDeviceAttachmentSpecReq(
const DeviceAttachmentSpec &spec,
Callback<removeDeviceAttachmentSpecReqCbFn> callback)
{
// Find the shared_ptr to the spec in the collection
std::shared_ptr<DeviceAttachmentSpec> specPtr = nullptr;
for (const auto& existingSpec : deviceAttachmentSpecs)
{
if (*existingSpec == spec)
{
specPtr = existingSpec;
break;
}
}
if (!specPtr)
{
// Spec not found, callback with failure
callback.callbackFn(false, nullptr);
return;
}
// Create async continuation
const auto& caller = ComponentThread::getSelf();
auto continuation = std::make_shared<RemoveDeviceAttachmentSpecReq>(
specPtr, caller, callback);
mrntt::mrntt.thread->getIoService().post(
auto request = std::make_shared<RemoveDeviceAttachmentSpecReq>(
spec, caller, callback,
LockSet<removeDeviceAttachmentSpecReqCbFn>::Set{
std::ref(DeviceManager::getInstance().qutex)
});
RemoveDeviceAttachmentSpecReq::LockerAndInvoker lockvoker(
*request, mrntt::mrntt.thread,
std::bind(
&RemoveDeviceAttachmentSpecReq::removeDeviceAttachmentSpecReq1_posted,
continuation.get(), continuation));
request.get(), request));
}
class DeviceManager::AttachSenseDeviceReq