[{"id":11671,"web_url":"https://patchwork.libcamera.org/comment/11671/","msgid":"<20200728152544.GE13753@pendragon.ideasonboard.com>","date":"2020-07-28T15:25:44","subject":"Re: [libcamera-devel] [PATCH 2/2] libcamera: camera: Ensure\n\tdeletion via deleteLater()","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Umang,\n\nThank you for the patch.\n\nOn Tue, Jul 28, 2020 at 10:57:25AM +0000, Umang Jain wrote:\n> Object::deleteLater() ensures that the deletion of the Object\n> takes place in a thread it is bound to. Deleting the Object\n> in a different thread is a violation according to the threading\n> model.\n> \n> On hot-unplug of a currently streaming camera, the last reference\n> of Camera when dropped from the application thread (for e.g. QCam's\n> thread), the destructor is then called from this thread. This is not\n> allowed by the threading model. Camera is meant to be deleted in the\n> thread it is bound to - in this case the CameraManager's thread.\n> \n> Signed-off-by: Umang Jain <email@uajain.com>\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n> ---\n>  include/libcamera/camera.h | 2 +-\n>  src/libcamera/camera.cpp   | 2 +-\n>  2 files changed, 2 insertions(+), 2 deletions(-)\n> \n> diff --git a/include/libcamera/camera.h b/include/libcamera/camera.h\n> index 4d1a4a9..beb87e6 100644\n> --- a/include/libcamera/camera.h\n> +++ b/include/libcamera/camera.h\n> @@ -66,7 +66,7 @@ protected:\n>  \tstd::vector<StreamConfiguration> config_;\n>  };\n>  \n> -class Camera final : public std::enable_shared_from_this<Camera>\n> +class Camera final : public Object, public std::enable_shared_from_this<Camera>\n\nYou should include object.h at the top of the file.\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n>  {\n>  public:\n>  \tstatic std::shared_ptr<Camera> create(PipelineHandler *pipe,\n> diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp\n> index 69a1b44..034f341 100644\n> --- a/src/libcamera/camera.cpp\n> +++ b/src/libcamera/camera.cpp\n> @@ -464,7 +464,7 @@ std::shared_ptr<Camera> Camera::create(PipelineHandler *pipe,\n>  \tstruct Deleter : std::default_delete<Camera> {\n>  \t\tvoid operator()(Camera *camera)\n>  \t\t{\n> -\t\t\tdelete camera;\n> +\t\t\tcamera->deleteLater();\n>  \t\t}\n>  \t};\n>","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 81799BD86F\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 28 Jul 2020 15:25:58 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 3566C613C6;\n\tTue, 28 Jul 2020 17:25:58 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 55C8D60923\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 28 Jul 2020 17:25:56 +0200 (CEST)","from pendragon.ideasonboard.com (81-175-216-236.bb.dnainternet.fi\n\t[81.175.216.236])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 068B6563;\n\tTue, 28 Jul 2020 17:25:52 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"SxKOw9lP\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1595949953;\n\tbh=bxZltLh96BWqc37Ao0Mmn1frFhZP4h1YCtGLQMov+Ng=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=SxKOw9lPpyI9a52Bfg8lcpos42ClUTL291hSECCVc3Z6Rw0MMdWgAfT3NuZ96ymOn\n\tX3IIX53SK/QCjn5DSdqlrmUIiipB7DkZ7lhwxOXlW1DF6ZOs9jqGY7oo+bYZU1GGLv\n\tDycrlGpFeOlEYFr3n3qVavzQuacTIwDWGLkEYKc4=","Date":"Tue, 28 Jul 2020 18:25:44 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Umang Jain <email@uajain.com>","Message-ID":"<20200728152544.GE13753@pendragon.ideasonboard.com>","References":"<20200728105541.13326-1-email@uajain.com>\n\t<20200728105541.13326-3-email@uajain.com>","MIME-Version":"1.0","Content-Disposition":"inline","In-Reply-To":"<20200728105541.13326-3-email@uajain.com>","Subject":"Re: [libcamera-devel] [PATCH 2/2] libcamera: camera: Ensure\n\tdeletion via deleteLater()","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Cc":"libcamera-devel@lists.libcamera.org","Content-Type":"text/plain; charset=\"us-ascii\"","Content-Transfer-Encoding":"7bit","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]