{"id":9086,"url":"https://patchwork.libcamera.org/api/1.1/patches/9086/?format=json","web_url":"https://patchwork.libcamera.org/patch/9086/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20200731105335.62014-4-email@uajain.com>","date":"2020-07-31T10:53:43","name":"[libcamera-devel,v2,3/3] libcamera: camera: Ensure deletion via deleteLater()","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"76adf0b1fc2a340921cc567c9b541d639d1abdc5","submitter":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/people/1/?format=json","name":"Umang Jain","email":"email@uajain.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/9086/mbox/","series":[{"id":1167,"url":"https://patchwork.libcamera.org/api/1.1/series/1167/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=1167","date":"2020-07-31T10:53:41","name":"Add Object::deleteLater() support","version":2,"mbox":"https://patchwork.libcamera.org/series/1167/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/9086/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/9086/checks/","tags":{},"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 DAFD8BD86F\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 31 Jul 2020 10:53:48 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 9927061EAB;\n\tFri, 31 Jul 2020 12:53:48 +0200 (CEST)","from o1.f.az.sendgrid.net (o1.f.az.sendgrid.net [208.117.55.132])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 4CD8061DC3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 31 Jul 2020 12:53:44 +0200 (CEST)","by filterdrecv-p3mdw1-7ff865655c-g882x with SMTP id\n\tfilterdrecv-p3mdw1-7ff865655c-g882x-20-5F23F836-56\n\t2020-07-31 10:53:43.011386453 +0000 UTC m=+146252.489555543","from mail.uajain.com (unknown)\n\tby ismtpd0005p1hnd1.sendgrid.net (SG) with ESMTP\n\tid W0LrwjoTRy25EnBiyiVl2w Fri, 31 Jul 2020 10:53:42.688 +0000 (UTC)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=uajain.com header.i=@uajain.com\n\theader.b=\"rTV8zgL4\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=uajain.com;\n\th=from:subject:in-reply-to:references:mime-version:to:cc:\n\tcontent-transfer-encoding:content-type;\n\ts=s1; bh=Q13Y/KIA9jXepafD4MdInIVxJgHdpkJml9AgdG7ctRo=;\n\tb=rTV8zgL4Kjur1x6RTQqEG8WDYxUOlT2iM3gZQ9nmE0x87jKDASt9mh036xAX3FcTZOBc\n\tGzGKlCXR8WocbZMjeq8bpUTgFZExfwEXYXn6HXBRSoP680/Z/zFc6SNR/qTXmqQdRfyFNI\n\tlNfgHUFIXDS1Lln5+SCMhkMq03y2JOuCc=","From":"Umang Jain <email@uajain.com>","Date":"Fri, 31 Jul 2020 10:53:43 +0000 (UTC)","Message-Id":"<20200731105335.62014-4-email@uajain.com>","In-Reply-To":"<20200731105335.62014-1-email@uajain.com>","References":"<20200731105335.62014-1-email@uajain.com>","Mime-Version":"1.0","X-SG-EID":"1Q40EQ7YGir8a9gjSIAdTjhngY657NMk9ckeo4dbHZDiOpywc/L3L9rFqlwE4KPcsL0v8VFFOnVCltD6I338jMD1MLjIeeAEM88dkYf60Kf3IBk5AwVG5GFoahk93LIUADk+7bCK7RTdEj/tdw6Ymf4UobQYlils4p1Xvqa3IvdZh50MHwRguXp98KzVR4KkTvcGyqei/wGQ7lMLe0uGRToa75BFG88HFwbmsHIS4KoJ9aKvgVXQ5VI8KY55C4TAADCbaMkj5pj7DtQgXtDtDw==","To":"libcamera-devel@lists.libcamera.org","Subject":"[libcamera-devel] [PATCH v2 3/3] libcamera: camera: Ensure deletion\n\tvia 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>","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>"},"content":"Object::deleteLater() ensures that the deletion of the Object\ntakes place in a thread it is bound to. Deleting the Object\nin a different thread is a violation according to the threading\nmodel.\n\nOn hot-unplug of a currently streaming camera, the last reference\nof Camera when dropped from the application thread (for e.g. QCam's\nthread), the destructor is then called from this thread. This is not\nallowed by the threading model. Camera is meant to be deleted in the\nthread it is bound to - in this case the CameraManager's thread.\n\nSigned-off-by: Umang Jain <email@uajain.com>\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n include/libcamera/camera.h       | 3 ++-\n src/libcamera/camera.cpp         | 2 +-\n src/libcamera/camera_manager.cpp | 6 +++++-\n 3 files changed, 8 insertions(+), 3 deletions(-)","diff":"diff --git a/include/libcamera/camera.h b/include/libcamera/camera.h\nindex 4d1a4a9..7dd23d7 100644\n--- a/include/libcamera/camera.h\n+++ b/include/libcamera/camera.h\n@@ -13,6 +13,7 @@\n #include <string>\n \n #include <libcamera/controls.h>\n+#include <libcamera/object.h>\n #include <libcamera/request.h>\n #include <libcamera/signal.h>\n #include <libcamera/stream.h>\n@@ -66,7 +67,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 {\n public:\n \tstatic std::shared_ptr<Camera> create(PipelineHandler *pipe,\ndiff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp\nindex 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 \ndiff --git a/src/libcamera/camera_manager.cpp b/src/libcamera/camera_manager.cpp\nindex f60491d..c45bf33 100644\n--- a/src/libcamera/camera_manager.cpp\n+++ b/src/libcamera/camera_manager.cpp\n@@ -164,9 +164,13 @@ void CameraManager::Private::cleanup()\n \n \t/*\n \t * Release all references to cameras to ensure they all get destroyed\n-\t * before the device enumerator deletes the media devices.\n+\t * before the device enumerator deletes the media devices. Cameras are\n+\t * destroyed via Object::deleteLater() API, hence we need to explicitly\n+\t * process deletion requests from the thread's message queue as the event\n+\t * loop is not in action here.\n \t */\n \tcameras_.clear();\n+\tdispatchMessages(Message::Type::DeferredDelete);\n \n \tenumerator_.reset(nullptr);\n }\n","prefixes":["libcamera-devel","v2","3/3"]}