SenseApiLib:Add isBeingDestroyed atomic flag for getter bailout
Since we have no choice but to access the sh_ptr<SenseApiLib> for a lib before we can get its Qutex, we use this flag to ensure that we can know whether the SenseApiLib data structure and its Qutex are still valid when we enter -- i.e, we ensure that the SenseApiLib object wasn't destroyed under our feet.
This commit is contained in:
@@ -324,10 +324,11 @@ public:
|
||||
const std::shared_ptr<DeviceAttachmentSpec>& spec,
|
||||
const std::shared_ptr<ComponentThread> &caller,
|
||||
Callback<attachSenseDeviceReqCbFn> cb,
|
||||
std::shared_ptr<sense_api::SenseApiLib> &senseApiLib,
|
||||
std::vector<std::reference_wrapper<Qutex>> requiredLocks)
|
||||
: SerializedAsynchronousContinuation<attachSenseDeviceReqCbFn>(
|
||||
caller, cb, requiredLocks),
|
||||
spec(spec)
|
||||
spec(spec), senseApiLib(senseApiLib)
|
||||
{}
|
||||
|
||||
public:
|
||||
@@ -344,26 +345,18 @@ public:
|
||||
return;
|
||||
}
|
||||
|
||||
/** FIXME:
|
||||
* We should acquire a spinlock here to ensure that the device isn't
|
||||
* added in the interim while the async op executes.
|
||||
*/
|
||||
auto libOpt = sense_api::SenseApiManager::getInstance()
|
||||
.getSenseApiLibByApiName(spec->api);
|
||||
|
||||
if (!libOpt)
|
||||
if (senseApiLib->isBeingDestroyed.load())
|
||||
{
|
||||
std::cerr << std::string(__func__) + ": No library found for API '"
|
||||
<< spec->api << "'" << std::endl;
|
||||
std::cerr << std::string(__func__) + ": Library is being destroyed"
|
||||
<< " for API '" << spec->api << "'. Bailing out." << std::endl;
|
||||
callOriginalCb(false, spec);
|
||||
return;
|
||||
}
|
||||
|
||||
auto& lib = *libOpt.value();
|
||||
if (!lib.senseApiDesc.sal_mgmt_libOps.attachDeviceReq)
|
||||
if (!senseApiLib->senseApiDesc.sal_mgmt_libOps.attachDeviceReq)
|
||||
{
|
||||
std::cerr << std::string(__func__) + ": attachDeviceReq() is NULL "
|
||||
"for library '" << lib.libraryPath << "'" << std::endl;
|
||||
"for library '" << senseApiLib->libraryPath << "'" << std::endl;
|
||||
callOriginalCb(false, spec);
|
||||
return;
|
||||
}
|
||||
@@ -391,7 +384,7 @@ public:
|
||||
<< spec->deviceIdentifier << " to body thread" << "\n";
|
||||
}
|
||||
|
||||
lib.senseApiDesc.sal_mgmt_libOps.attachDeviceReq(
|
||||
senseApiLib->senseApiDesc.sal_mgmt_libOps.attachDeviceReq(
|
||||
spec, threadForAttachment,
|
||||
{context, std::bind(
|
||||
&AttachSenseDeviceReq::attachSenseDeviceReq2,
|
||||
@@ -421,32 +414,25 @@ public:
|
||||
return;
|
||||
}
|
||||
|
||||
/** FIXME:
|
||||
* We should acquire a spinlock here to ensure that the device isn't
|
||||
* removed in the interim while the async op executes.
|
||||
*/
|
||||
auto libOpt = sense_api::SenseApiManager::getInstance()
|
||||
.getSenseApiLibByApiName(spec->api);
|
||||
|
||||
if (!libOpt)
|
||||
if (senseApiLib->isBeingDestroyed.load())
|
||||
{
|
||||
std::cerr << std::string(__func__) + ": No library found for API '"
|
||||
<< spec->api << "'" << std::endl;
|
||||
std::cerr << std::string(__func__) + ": Library is being destroyed"
|
||||
<< " for API '" << spec->api << "'. Bailing out." << std::endl;
|
||||
callOriginalCb(false, spec);
|
||||
return;
|
||||
}
|
||||
auto& lib = *libOpt.value();
|
||||
if (!lib.senseApiDesc.sal_mgmt_libOps.detachDeviceReq)
|
||||
|
||||
if (!senseApiLib->senseApiDesc.sal_mgmt_libOps.detachDeviceReq)
|
||||
{
|
||||
std::cerr << std::string(__func__) + ": detachDeviceReq() is NULL "
|
||||
"for library '" << lib.libraryPath << "'" << std::endl;
|
||||
"for library '" << senseApiLib->libraryPath << "'" << std::endl;
|
||||
callOriginalCb(false, spec);
|
||||
return;
|
||||
}
|
||||
|
||||
sense_api::SenseApiManager::getInstance().qutex.release();
|
||||
|
||||
lib.senseApiDesc.sal_mgmt_libOps.detachDeviceReq(
|
||||
senseApiLib->senseApiDesc.sal_mgmt_libOps.detachDeviceReq(
|
||||
spec,
|
||||
{context, std::bind(
|
||||
&DetachSenseDeviceReq::detachSenseDeviceReq2,
|
||||
@@ -465,6 +451,7 @@ public:
|
||||
|
||||
public:
|
||||
std::shared_ptr<DeviceAttachmentSpec> spec;
|
||||
std::shared_ptr<sense_api::SenseApiLib> senseApiLib;
|
||||
};
|
||||
|
||||
void DeviceManager::attachSenseDeviceReq(
|
||||
@@ -489,7 +476,7 @@ void DeviceManager::attachSenseDeviceReq(
|
||||
auto& lib = *libOpt.value();
|
||||
|
||||
auto request = std::make_shared<AttachSenseDeviceReq>(
|
||||
spec, caller, cb,
|
||||
spec, caller, cb, libOpt.value(),
|
||||
LockSet<attachSenseDeviceReqCbFn>::Set{
|
||||
std::ref(sense_api::SenseApiManager::getInstance().qutex),
|
||||
std::ref(lib.qutex)
|
||||
@@ -524,7 +511,7 @@ void DeviceManager::detachSenseDeviceReq(
|
||||
auto& lib = *libOpt.value();
|
||||
|
||||
auto request = std::make_shared<DetachSenseDeviceReq>(
|
||||
spec, caller, cb,
|
||||
spec, caller, cb, libOpt.value(),
|
||||
LockSet<detachSenseDeviceReqCbFn>::Set{
|
||||
std::ref(sense_api::SenseApiManager::getInstance().qutex),
|
||||
std::ref(lib.qutex)
|
||||
|
||||
Reference in New Issue
Block a user