{"id":13494,"url":"https://patchwork.libcamera.org/api/1.1/patches/13494/?format=json","web_url":"https://patchwork.libcamera.org/patch/13494/","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":"<20210825211852.1207168-2-nicolas@ndufresne.ca>","date":"2021-08-25T21:18:50","name":"[libcamera-devel,v1,1/3] gstreamer: Fix deadlock when last allocator ref is held by buffer","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"21d5f46109b69cecc45d1edded7c0138359d5183","submitter":{"id":30,"url":"https://patchwork.libcamera.org/api/1.1/people/30/?format=json","name":"Nicolas Dufresne","email":"nicolas@ndufresne.ca"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/13494/mbox/","series":[{"id":2396,"url":"https://patchwork.libcamera.org/api/1.1/series/2396/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=2396","date":"2021-08-25T21:18:49","name":"Fix Gnome Cheese and multiple camera","version":1,"mbox":"https://patchwork.libcamera.org/series/2396/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/13494/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/13494/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 0C4F2BD87D\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 25 Aug 2021 21:19:15 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id D537968893;\n\tWed, 25 Aug 2021 23:19:14 +0200 (CEST)","from bhuna.collabora.co.uk (bhuna.collabora.co.uk\n\t[IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 03F9760288\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 25 Aug 2021 23:19:13 +0200 (CEST)","from [127.0.0.1] (localhost [127.0.0.1])\n\t(Authenticated sender: nicolas) with ESMTPSA id 49C0E1F435D8"],"From":"Nicolas Dufresne <nicolas@ndufresne.ca>","To":"libcamera-devel@lists.libcamera.org","Date":"Wed, 25 Aug 2021 17:18:50 -0400","Message-Id":"<20210825211852.1207168-2-nicolas@ndufresne.ca>","X-Mailer":"git-send-email 2.31.1","In-Reply-To":"<20210825211852.1207168-1-nicolas@ndufresne.ca>","References":"<20210825211852.1207168-1-nicolas@ndufresne.ca>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v1 1/3] gstreamer: Fix deadlock when last\n\tallocator ref is held by buffer","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":"Nicolas Dufresne <nicolas.dufresne@collabora.com>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"From: Nicolas Dufresne <nicolas.dufresne@collabora.com>\n\nThis deadlock occurs when a buffer is holding the last reference on\nthe allocator. In gst_libcamera_allocator_release() we must drop the\nobject lock before dropping the last ref of that object since the\ndestructor will lock it again causing deadlock.\n\nThis was notice while switching camera or resolution in Cheese software.\n\nSigned-off-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>\n---\n src/gstreamer/gstlibcameraallocator.cpp | 17 ++++++++++-------\n 1 file changed, 10 insertions(+), 7 deletions(-)","diff":"diff --git a/src/gstreamer/gstlibcameraallocator.cpp b/src/gstreamer/gstlibcameraallocator.cpp\nindex 7bd8ba2d..a8fa4f86 100644\n--- a/src/gstreamer/gstlibcameraallocator.cpp\n+++ b/src/gstreamer/gstlibcameraallocator.cpp\n@@ -108,15 +108,18 @@ gst_libcamera_allocator_release(GstMiniObject *mini_object)\n {\n \tGstMemory *mem = GST_MEMORY_CAST(mini_object);\n \tGstLibcameraAllocator *self = GST_LIBCAMERA_ALLOCATOR(mem->allocator);\n-\tGLibLocker lock(GST_OBJECT(self));\n-\tauto *frame = reinterpret_cast<FrameWrap *>(gst_mini_object_get_qdata(mini_object, FrameWrap::getQuark()));\n \n-\tgst_memory_ref(mem);\n+\t{\n+\t\tGLibLocker lock(GST_OBJECT(self));\n+\t\tauto *frame = reinterpret_cast<FrameWrap *>(gst_mini_object_get_qdata(mini_object, FrameWrap::getQuark()));\n+\n+\t\tgst_memory_ref(mem);\n \n-\tif (frame->releasePlane()) {\n-\t\tauto *pool = reinterpret_cast<GQueue *>(g_hash_table_lookup(self->pools, frame->stream_));\n-\t\tg_return_val_if_fail(pool, TRUE);\n-\t\tg_queue_push_tail(pool, frame);\n+\t\tif (frame->releasePlane()) {\n+\t\t\tauto *pool = reinterpret_cast<GQueue *>(g_hash_table_lookup(self->pools, frame->stream_));\n+\t\t\tg_return_val_if_fail(pool, TRUE);\n+\t\t\tg_queue_push_tail(pool, frame);\n+\t\t}\n \t}\n \n \t/* Keep last in case we are holding on the last allocator ref. */\n","prefixes":["libcamera-devel","v1","1/3"]}