[{"id":28559,"web_url":"https://patchwork.libcamera.org/comment/28559/","msgid":"<8734up6rha.fsf@redhat.com>","date":"2024-01-22T20:30:25","subject":"Re: [PATCH 11/12] libcamera: object: Document and ensure Object\n\tdeletion constraints","submitter":{"id":177,"url":"https://patchwork.libcamera.org/api/people/177/","name":"Milan Zamazal","email":"mzamazal@redhat.com"},"content":"Laurent Pinchart <laurent.pinchart@ideasonboard.com> writes:\n\n> Object instances are meant to be deleted from the thread they are bound\n> to, and this requirement is documented. There are however exceptions to\n> the rule, as threads may be stopped and restarted, with objects bound to\n> them not being deleted and recreated for every stop/restart cycle. Bound\n> objects may therefore need to be deleted after the thread has stopped,\n> making it impossible to use Object::deleteLater().\n>\n> Document the lifetime requirements more precisely, and enforce them with\n> an assertion.\n>\n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\nReviewed-by: Milan Zamazal <mzamazal@redhat.com>\n\n> ---\n>  src/libcamera/base/object.cpp | 16 ++++++++++++++--\n>  1 file changed, 14 insertions(+), 2 deletions(-)\n>\n> diff --git a/src/libcamera/base/object.cpp b/src/libcamera/base/object.cpp\n> index 1fce5a2af9af..8af0337f5448 100644\n> --- a/src/libcamera/base/object.cpp\n> +++ b/src/libcamera/base/object.cpp\n> @@ -40,8 +40,9 @@ LOG_DEFINE_CATEGORY(Object)\n>   * Object class.\n>   *\n>   * Deleting an object from a thread other than the one the object is bound to is\n> - * unsafe, unless the caller ensures that the object isn't processing any\n> - * message concurrently.\n> + * unsafe, unless the caller ensures that the object's thread is stopped and no\n> + * parent or child of the object gets deleted concurrently. See\n> + * Object::~Object() for more information.\n>   *\n>   * Object slots connected to signals will also run in the context of the\n>   * object's thread, regardless of whether the signal is emitted in the same or\n> @@ -84,9 +85,20 @@ Object::Object(Object *parent)\n>   * Object instances shall be destroyed from the thread they are bound to,\n>   * otherwise undefined behaviour may occur. If deletion of an Object needs to\n>   * be scheduled from a different thread, deleteLater() shall be used.\n> + *\n> + * As an exception to this rule, Object instances may be deleted from a\n> + * different thread if the thread the instance is bound to is stopped through\n> + * the whole duration of the object's destruction, *and* the parent and children\n> + * of the object do not get deleted concurrently. The caller is responsible for\n> + * fulfilling those requirements.\n> + *\n> + * In all cases Object instances shall be deleted before the Thread they are\n> + * bound to.\n>   */\n>  Object::~Object()\n>  {\n> +\tASSERT(Thread::current() == thread_ || !thread_->isRunning());\n> +\n>  \t/*\n>  \t * Move signals to a private list to avoid concurrent iteration and\n>  \t * deletion of items from Signal::disconnect().","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 EBF44BDB1C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 22 Jan 2024 20:30:33 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id E78A062936;\n\tMon, 22 Jan 2024 21:30:32 +0100 (CET)","from us-smtp-delivery-124.mimecast.com\n\t(us-smtp-delivery-124.mimecast.com [170.10.129.124])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 2295F61D30\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 22 Jan 2024 21:30:32 +0100 (CET)","from mail-ed1-f69.google.com (mail-ed1-f69.google.com\n\t[209.85.208.69]) by relay.mimecast.com with ESMTP with STARTTLS\n\t(version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id\n\tus-mta-203-m9G-bBXHMm-77ZoR9uImdw-1; Mon, 22 Jan 2024 15:30:29 -0500","by mail-ed1-f69.google.com with SMTP id\n\t4fb4d7f45d1cf-55c795a8a74so34170a12.0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 22 Jan 2024 12:30:29 -0800 (PST)","from nuthatch (ip-77-48-47-2.net.vodafone.cz. [77.48.47.2])\n\tby smtp.gmail.com with ESMTPSA id\n\tdh14-20020a0564021d2e00b0055c2d7eac0bsm1873862edb.74.2024.01.22.12.30.25\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tMon, 22 Jan 2024 12:30:26 -0800 (PST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=redhat.com header.i=@redhat.com\n\theader.b=\"IKT3X5OF\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n\ts=mimecast20190719; t=1705955431;\n\th=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n\tto:to:cc:cc:mime-version:mime-version:content-type:content-type:\n\tin-reply-to:in-reply-to:references:references;\n\tbh=a+BNy/C3Woy6E2P3zini86hHClrAGElrVACN/Ba2MuA=;\n\tb=IKT3X5OFVF0yac88JMLFZbbSWrYxrgW+7uO+J4Shtp4J04sCwx3wACnjavLyWLq8m9cG0F\n\tw3OoMTI4Y5w6vVzu0HqMitMNU0v6PC+RS9HJagjlE0gJHHRnOkiQ4ncqtsHDoHCB30j6Mx\n\tDmSovdbrx8uLU5Hbm8s4qfeOAtYzDRI=","X-MC-Unique":"m9G-bBXHMm-77ZoR9uImdw-1","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1705955427; x=1706560227;\n\th=mime-version:user-agent:message-id:date:references:in-reply-to\n\t:subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date\n\t:message-id:reply-to;\n\tbh=a+BNy/C3Woy6E2P3zini86hHClrAGElrVACN/Ba2MuA=;\n\tb=HI2BfDGnceLm7Gai7O0rf5Uk5V9WVo6HJIh4Z9zJcUXgiGz0mltY5gub6Pj+QZQnfp\n\tzsGzogbWTHCQFstfH3JZqPR/7WR1PutxT4Jj8d/MoOqn++GEqrgNN+AgU+tbeBMtwnwy\n\tsSsTZg4CWbDgrucW3N1e+Fy/GUpe5vsy/GYToRthyl2ckNd6/QD/l+qpsXWgKD4Msn5J\n\tzvPbvcMI4N0HIHb13msTozego3qzyObU0zs1tya1Mn4BgItj36yKVFeBa1NdGL8LSG9l\n\tyAtlmHov/V0AcQhbmHCLbXnUAF7091e17IRkIp47vLhK0MMcaO7VG0jYZD5NDPwIS2u4\n\tOmWA==","X-Gm-Message-State":"AOJu0Yz20bqieY3EzLs1YtY+WzpBS9/t4kesqTia7TNfSiIFNaZI21O3\n\tVtmGm+nE/flTz0HcT1CJ9+GNYiq/yY3ZEdjE6CqMSQtPwbLS0tS8H/R7QZuFRxM9kr7gHO11yr+\n\t0/DtEe4VG4uzQS+Jw/kbzVsPb3tbpizIPlc1rLymynDanJI4q87zyqPf7MpvYuSnoACOexWAYOO\n\tOYChRjkSPacfsU8JYL2+2XyaGbr0XZsRq/mncSP6cpNVRJuMpLnRPmp4U=","X-Received":["by 2002:a05:6402:28af:b0:55a:7227:cedf with SMTP id\n\teg47-20020a05640228af00b0055a7227cedfmr253453edb.57.1705955426924; \n\tMon, 22 Jan 2024 12:30:26 -0800 (PST)","by 2002:a05:6402:28af:b0:55a:7227:cedf with SMTP id\n\teg47-20020a05640228af00b0055a7227cedfmr253444edb.57.1705955426564; \n\tMon, 22 Jan 2024 12:30:26 -0800 (PST)"],"X-Google-Smtp-Source":"AGHT+IGYQtdvhhEXQ114UsmCkbO5dLOVmkMbmU8qxSrmDvBuX3U36I9LOd4gb0jWGfovAOosoV5EdA==","From":"Milan Zamazal <mzamazal@redhat.com>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Subject":"Re: [PATCH 11/12] libcamera: object: Document and ensure Object\n\tdeletion constraints","In-Reply-To":"<20240121035948.4226-12-laurent.pinchart@ideasonboard.com>\n\t(Laurent Pinchart's message of \"Sun, 21 Jan 2024 05:59:47 +0200\")","References":"<20240121035948.4226-1-laurent.pinchart@ideasonboard.com>\n\t<20240121035948.4226-12-laurent.pinchart@ideasonboard.com>","Date":"Mon, 22 Jan 2024 21:30:25 +0100","Message-ID":"<8734up6rha.fsf@redhat.com>","User-Agent":"Gnus/5.13 (Gnus v5.13)","MIME-Version":"1.0","X-Mimecast-Spam-Score":"0","X-Mimecast-Originator":"redhat.com","Content-Type":"text/plain","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","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]