From patchwork Tue Jul 28 10:57:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 9043 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 E48B8BD878 for ; Tue, 28 Jul 2020 10:57:29 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id AE1D8613C6; Tue, 28 Jul 2020 12:57:29 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=uajain.com header.i=@uajain.com header.b="bkXCQ4FK"; dkim-atps=neutral Received: from o1.f.az.sendgrid.net (o1.f.az.sendgrid.net [208.117.55.132]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 2DCAF616FF for ; Tue, 28 Jul 2020 12:57:27 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=uajain.com; h=from:subject:in-reply-to:references:mime-version:to:cc: content-transfer-encoding:content-type; s=s1; bh=LKCN+mo/nQECRcf0uO/mA1y+PjqUsP1EpSA93LxFroY=; b=bkXCQ4FKggoC8whK4vzVIagKwJLbEFHPSGdTwcz1aV4hf8KCC2HeSUaag/8QdZr3Nv0g 0pW3Zrfx8rrr6iCqKQVyYG9glZbBc2vOc0evkk5nK0n8elU+kvMM2G9wNjT5bSsZPDxeht kEBzh9+USozgbRm6ZqaTqp4sFy5I6QP8I= Received: by filterdrecv-p3mdw1-75c584b9c6-q9wps with SMTP id filterdrecv-p3mdw1-75c584b9c6-q9wps-21-5F200495-4C 2020-07-28 10:57:25.902086811 +0000 UTC m=+2742468.798483178 Received: from mail.uajain.com (unknown) by ismtpd0005p1maa1.sendgrid.net (SG) with ESMTP id V5L735IlQI6Vdnx2fPbSrQ for ; Tue, 28 Jul 2020 10:57:25.496 +0000 (UTC) From: Umang Jain Date: Tue, 28 Jul 2020 10:57:25 +0000 (UTC) Message-Id: <20200728105541.13326-3-email@uajain.com> In-Reply-To: <20200728105541.13326-1-email@uajain.com> References: <20200728105541.13326-1-email@uajain.com> Mime-Version: 1.0 X-SG-EID: 1Q40EQ7YGir8a9gjSIAdTjhngY657NMk9ckeo4dbHZDiOpywc/L3L9rFqlwE4KPc/qk5sBUbMs3SDc71Zia+EPPl8QFrE3sWnDV6QCaTwNApz2N86mNxUJ0CEM2nVAO4uPigtjdaq0fQErk0X4IuyMqCQpDBXU/HGO3jBYfp1Zs0F9smtLq97JRdtgwGWI20x5BKhpUTfRAvx0oqlewpBqgUQ16jvxVOwMoDNEwQ4J38YV7ceXs/XYYRNITyMD9WQg5g3fcFl1/1X756JpnDSw== To: libcamera-devel@lists.libcamera.org Subject: [libcamera-devel] [PATCH 2/2] libcamera: camera: Ensure deletion via deleteLater() 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" Object::deleteLater() ensures that the deletion of the Object takes place in a thread it is bound to. Deleting the Object in a different thread is a violation according to the threading model. On hot-unplug of a currently streaming camera, the last reference of Camera when dropped from the application thread (for e.g. QCam's thread), the destructor is then called from this thread. This is not allowed by the threading model. Camera is meant to be deleted in the thread it is bound to - in this case the CameraManager's thread. Signed-off-by: Umang Jain Reviewed-by: Laurent Pinchart Reviewed-by: Laurent Pinchart --- include/libcamera/camera.h | 2 +- src/libcamera/camera.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/libcamera/camera.h b/include/libcamera/camera.h index 4d1a4a9..beb87e6 100644 --- a/include/libcamera/camera.h +++ b/include/libcamera/camera.h @@ -66,7 +66,7 @@ protected: std::vector config_; }; -class Camera final : public std::enable_shared_from_this +class Camera final : public Object, public std::enable_shared_from_this { public: static std::shared_ptr create(PipelineHandler *pipe, diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp index 69a1b44..034f341 100644 --- a/src/libcamera/camera.cpp +++ b/src/libcamera/camera.cpp @@ -464,7 +464,7 @@ std::shared_ptr Camera::create(PipelineHandler *pipe, struct Deleter : std::default_delete { void operator()(Camera *camera) { - delete camera; + camera->deleteLater(); } };