diff options
author | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2020-09-08 10:00:25 +0300 |
---|---|---|
committer | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2020-09-20 15:09:53 +0300 |
commit | 54557e25f2d478623839fe17f82700bb97fff0b2 (patch) | |
tree | 2f93ba0a45e6d86cd63ef67780b3de9356dcd37d | |
parent | 7720c4aefa95ee9df6e5d464c187efa7141f1302 (diff) |
libcamera: camera: Optimize camera deletion
In most cases the last reference to a Camera instance will be the one
held by the CameraManager. That reference gets released when the
CameraManager thread cleans up, just before it stops. There's no need to
delete the camera with deleteLater() in that case.
To optimize this case, use deleteLater() only when the camera gets
deleted from a different thread, and delete is synchronously otherwise.
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Umang Jain <email@uajain.com>
-rw-r--r-- | src/libcamera/camera.cpp | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp index 4a9c19c3..ae16a64a 100644 --- a/src/libcamera/camera.cpp +++ b/src/libcamera/camera.cpp @@ -16,6 +16,7 @@ #include "libcamera/internal/log.h" #include "libcamera/internal/pipeline_handler.h" +#include "libcamera/internal/thread.h" #include "libcamera/internal/utils.h" /** @@ -470,7 +471,10 @@ std::shared_ptr<Camera> Camera::create(PipelineHandler *pipe, struct Deleter : std::default_delete<Camera> { void operator()(Camera *camera) { - camera->deleteLater(); + if (Thread::current() == camera->thread()) + delete camera; + else + camera->deleteLater(); } }; |