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>
This commit is contained in:
@@ -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();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user