From patchwork Tue Sep 8 07:54:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 9529 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 0DAB6BDB1D for ; Tue, 8 Sep 2020 07:54:39 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id A67CF62931; Tue, 8 Sep 2020 09:54:38 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="m/93tI17"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id C817E60534 for ; Tue, 8 Sep 2020 09:54:36 +0200 (CEST) Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 57F6239; Tue, 8 Sep 2020 09:54:36 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1599551676; bh=WQmF94xBZ6D8cdYlZg7HAx0zeHGTIbkWaMjB3lSg1xM=; h=From:To:Cc:Subject:Date:From; b=m/93tI17JsVPsTH9TBr3m8qAMb7kGTMd61ipN+B72lQP3OoUBvESit/co4zdP9BkX 2faYyS0n/8fei58YF/H67AP1msZkxCpWXWRc8m5akG92weBlbkxegU0v54RXHj6eUV 2Amdp4U7obA4WBaBfjpR5e+oc2QDiXqC/INzu8OI= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Tue, 8 Sep 2020 10:54:06 +0300 Message-Id: <20200908075406.14039-1-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH] libcamera: camera: Optimize camera deletion X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" 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 Reviewed-by: Umang Jain --- Umang, would you be able to test this patch with the Android HAL ? src/libcamera/camera.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp index 4a9c19c33cfb..ae16a64a3b44 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::create(PipelineHandler *pipe, struct Deleter : std::default_delete { void operator()(Camera *camera) { - camera->deleteLater(); + if (Thread::current() == camera->thread()) + delete camera; + else + camera->deleteLater(); } };