summaryrefslogtreecommitdiff
path: root/src/libcamera/ipa_manager.cpp
diff options
context:
space:
mode:
authorPaul Elder <paul.elder@ideasonboard.com>2020-06-02 11:15:37 +0900
committerPaul Elder <paul.elder@ideasonboard.com>2020-06-08 17:11:21 +0900
commit46d544345cbae270da533a737e334880720ceea5 (patch)
treeb1b64b33c086e78093a96f1d5eaea64d9b7cd348 /src/libcamera/ipa_manager.cpp
parent79d666247182b0e42560ab505c29173ca94bdbb0 (diff)
libcamera: IPAManager: make IPAManager lifetime explicitly managed
If any ipa_context instances are destroyed after the IPAManager is destroyed, then a segfault will occur, since the modules have been unloaded by the IPAManager and the context function pointers have been freed. Fix this by making the lifetime of the IPAManager explicit, and make the CameraManager construct and deconstruct (automatically, via a unique pointer) the IPAManager. Also update the IPA interface test to do the construction and deconstruction of the IPAManager, as it does not use the CameraManager. Signed-off-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Diffstat (limited to 'src/libcamera/ipa_manager.cpp')
-rw-r--r--src/libcamera/ipa_manager.cpp25
1 files changed, 20 insertions, 5 deletions
diff --git a/src/libcamera/ipa_manager.cpp b/src/libcamera/ipa_manager.cpp
index 505cf610..e7fddf42 100644
--- a/src/libcamera/ipa_manager.cpp
+++ b/src/libcamera/ipa_manager.cpp
@@ -93,8 +93,21 @@ LOG_DEFINE_CATEGORY(IPAManager)
* plain C API, or to transmit the data to the isolated process through IPC.
*/
+IPAManager *IPAManager::self_ = nullptr;
+
+/**
+ * \brief Construct an IPAManager instance
+ *
+ * The IPAManager class is meant to only be instantiated once, by the
+ * CameraManager. Pipeline handlers shall use the instance() function to access
+ * the IPAManager instance.
+ */
IPAManager::IPAManager()
{
+ if (self_)
+ LOG(IPAManager, Fatal)
+ << "Multiple IPAManager objects are not allowed";
+
unsigned int ipaCount = 0;
/* User-specified paths take precedence. */
@@ -134,27 +147,29 @@ IPAManager::IPAManager()
if (!ipaCount)
LOG(IPAManager, Warning)
<< "No IPA found in '" IPA_MODULE_DIR "'";
+
+ self_ = this;
}
IPAManager::~IPAManager()
{
for (IPAModule *module : modules_)
delete module;
+
+ self_ = nullptr;
}
/**
* \brief Retrieve the IPA manager instance
*
- * The IPAManager is a singleton and can't be constructed manually. This
- * function shall instead be used to retrieve the single global instance of the
- * manager.
+ * The IPAManager is constructed by the CameraManager. This function shall be
+ * used to retrieve the single instance of the manager.
*
* \return The IPA manager instance
*/
IPAManager *IPAManager::instance()
{
- static IPAManager ipaManager;
- return &ipaManager;
+ return self_;
}
/**