[{"id":35257,"web_url":"https://patchwork.libcamera.org/comment/35257/","msgid":"<e4a9d92c-244a-4e8b-ae2c-7480bfe5196c@ideasonboard.com>","date":"2025-07-31T07:36:23","subject":"Re: [PATCH v3 1/2] libcamera: utils: Add scope_exit class","submitter":{"id":216,"url":"https://patchwork.libcamera.org/api/people/216/","name":"Barnabás Pőcze","email":"barnabas.pocze@ideasonboard.com"},"content":"Hi\n\n2025. 07. 30. 12:27 keltezéssel, Laurent Pinchart írta:\n> The scope_exit class is an implementation of the identically named C++\n> library fundamentals TS v3 class, as documented in [1]. It is a simpler\n> version of the libcamera-specific ScopeExitActions class and doesn't\n> require dynamic heap memory allocation, making it more suitable for hot\n> paths.\n> \n> The class is not documented as it implements a C++ standard (even if\n> experimental) API.\n> \n> [1] https://en.cppreference.com/w/cpp/experimental/scope_exit/scope_exit.html\n> \n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> ---\n> Changes since v2:\n> \n> - Drop lvalue reference constraint in constructor\n> - Delete move constructor\n> \n> I have named the class scope_exit instead of ScopeExit to match the C++\n> library fundamentals TS v3 class, and have not documented it as it's\n> meant as an implementation of the standard. It is however not clear if\n> and when scope_exit would become part of a ratified C++ standard, so I'm\n> open to instead create a libcamera-specific ScopeExit class and document\n> it.\n> ---\n>   include/libcamera/base/utils.h | 38 ++++++++++++++++++++++++++++++++++\n>   1 file changed, 38 insertions(+)\n> \n> diff --git a/include/libcamera/base/utils.h b/include/libcamera/base/utils.h\n> index 8d5c35782ee3..808e0255b004 100644\n> --- a/include/libcamera/base/utils.h\n> +++ b/include/libcamera/base/utils.h\n> @@ -428,6 +428,44 @@ private:\n>   \tstd::vector<std::function<void()>> actions_;\n>   };\n> \n> +#ifndef __DOXYGEN__\n> +template<typename EF>\n> +class scope_exit\n> +{\n> +public:\n> +\ttemplate<typename Fn,\n> +\t\t std::enable_if_t<!std::is_same_v<std::remove_cv_t<std::remove_reference_t<Fn>>, scope_exit> &&\n> +\t\t\t\t  std::is_constructible_v<EF, Fn>> * = nullptr>\n> +\texplicit scope_exit(Fn &&fn)\n> +\t\t: exitFunction_(std::forward<Fn>(fn))\n> +\t{\n> +\t\tstatic_assert(std::is_nothrow_constructible_v<EF, Fn>);\n> +\t}\n> +\n> +\tscope_exit(scope_exit &&other) = delete;\n> +\tscope_exit(const scope_exit &) = delete;\n\nI think I would probably explicitly delete the other 2 as well, but based on\nthe implicit copy/move ctor/assignment rules, they should be deleted \"already\".\n\nReviewed-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>\n\n> +\n> +\t~scope_exit()\n> +\t{\n> +\t\tif (active_)\n> +\t\t\texitFunction_();\n> +\t}\n> +\n> +\tvoid release()\n> +\t{\n> +\t\tactive_ = false;\n> +\t}\n> +\n> +private:\n> +\tEF exitFunction_;\n> +\tbool active_ = true;\n> +};\n> +\n> +template<typename EF>\n> +scope_exit(EF) -> scope_exit<EF>;\n> +\n> +#endif /* __DOXYGEN__ */\n> +\n>   } /* namespace utils */\n> \n>   #ifndef __DOXYGEN__\n> --\n> Regards,\n> \n> Laurent Pinchart\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 811FDBDCC1\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 31 Jul 2025 07:36:31 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id ED19969212;\n\tThu, 31 Jul 2025 09:36:29 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 82EF769137\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 31 Jul 2025 09:36:27 +0200 (CEST)","from [192.168.33.14] (185.221.140.213.nat.pool.zt.hu\n\t[185.221.140.213])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 514605250;\n\tThu, 31 Jul 2025 09:35:43 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"MVnTVBe9\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1753947343;\n\tbh=9CDiOhsHlSogmr8oYEHzUR4K0bS+lbyOQZh7vzU+bcQ=;\n\th=Date:Subject:To:References:From:In-Reply-To:From;\n\tb=MVnTVBe9q+fQTYVRKcyZXdbrtUAMzmeNaEf23tCM+fRcJupyWA0NcJ8YPDAV+kc6t\n\tXq1y4GjPwwDlf9vlo0dVH3eStlf9CbrwY0OWJSkBCDPwlSi/DXEbW24YizrQrRWHJu\n\tFXItsvS8bxkqXo/rpoQ36qew+ZCpGp19v3HcbtGg=","Message-ID":"<e4a9d92c-244a-4e8b-ae2c-7480bfe5196c@ideasonboard.com>","Date":"Thu, 31 Jul 2025 09:36:23 +0200","MIME-Version":"1.0","User-Agent":"Mozilla Thunderbird","Subject":"Re: [PATCH v3 1/2] libcamera: utils: Add scope_exit class","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","References":"<20250730102733.21314-1-laurent.pinchart@ideasonboard.com>\n\t<20250730102733.21314-2-laurent.pinchart@ideasonboard.com>","From":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <barnabas.pocze@ideasonboard.com>","Content-Language":"en-US, hu-HU","In-Reply-To":"<20250730102733.21314-2-laurent.pinchart@ideasonboard.com>","Content-Type":"text/plain; charset=UTF-8; format=flowed","Content-Transfer-Encoding":"8bit","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>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":35279,"web_url":"https://patchwork.libcamera.org/comment/35279/","msgid":"<20250804224027.GA31914@pendragon.ideasonboard.com>","date":"2025-08-04T22:40:27","subject":"Re: [PATCH v3 1/2] libcamera: utils: Add scope_exit class","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"On Thu, Jul 31, 2025 at 09:36:23AM +0200, Barnabás Pőcze wrote:\n> 2025. 07. 30. 12:27 keltezéssel, Laurent Pinchart írta:\n> > The scope_exit class is an implementation of the identically named C++\n> > library fundamentals TS v3 class, as documented in [1]. It is a simpler\n> > version of the libcamera-specific ScopeExitActions class and doesn't\n> > require dynamic heap memory allocation, making it more suitable for hot\n> > paths.\n> > \n> > The class is not documented as it implements a C++ standard (even if\n> > experimental) API.\n> > \n> > [1] https://en.cppreference.com/w/cpp/experimental/scope_exit/scope_exit.html\n> > \n> > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> > ---\n> > Changes since v2:\n> > \n> > - Drop lvalue reference constraint in constructor\n> > - Delete move constructor\n> > \n> > I have named the class scope_exit instead of ScopeExit to match the C++\n> > library fundamentals TS v3 class, and have not documented it as it's\n> > meant as an implementation of the standard. It is however not clear if\n> > and when scope_exit would become part of a ratified C++ standard, so I'm\n> > open to instead create a libcamera-specific ScopeExit class and document\n> > it.\n> > ---\n> >   include/libcamera/base/utils.h | 38 ++++++++++++++++++++++++++++++++++\n> >   1 file changed, 38 insertions(+)\n> > \n> > diff --git a/include/libcamera/base/utils.h b/include/libcamera/base/utils.h\n> > index 8d5c35782ee3..808e0255b004 100644\n> > --- a/include/libcamera/base/utils.h\n> > +++ b/include/libcamera/base/utils.h\n> > @@ -428,6 +428,44 @@ private:\n> >   \tstd::vector<std::function<void()>> actions_;\n> >   };\n> > \n> > +#ifndef __DOXYGEN__\n> > +template<typename EF>\n> > +class scope_exit\n> > +{\n> > +public:\n> > +\ttemplate<typename Fn,\n> > +\t\t std::enable_if_t<!std::is_same_v<std::remove_cv_t<std::remove_reference_t<Fn>>, scope_exit> &&\n> > +\t\t\t\t  std::is_constructible_v<EF, Fn>> * = nullptr>\n> > +\texplicit scope_exit(Fn &&fn)\n> > +\t\t: exitFunction_(std::forward<Fn>(fn))\n> > +\t{\n> > +\t\tstatic_assert(std::is_nothrow_constructible_v<EF, Fn>);\n> > +\t}\n> > +\n> > +\tscope_exit(scope_exit &&other) = delete;\n> > +\tscope_exit(const scope_exit &) = delete;\n> \n> I think I would probably explicitly delete the other 2 as well, but based on\n> the implicit copy/move ctor/assignment rules, they should be deleted \"already\".\n\nI'll use LIBCAMERA_DISABLE_COPY_AND_MOVE()\n\n> Reviewed-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>\n> \n> > +\n> > +\t~scope_exit()\n> > +\t{\n> > +\t\tif (active_)\n> > +\t\t\texitFunction_();\n> > +\t}\n> > +\n> > +\tvoid release()\n> > +\t{\n> > +\t\tactive_ = false;\n> > +\t}\n> > +\n> > +private:\n> > +\tEF exitFunction_;\n> > +\tbool active_ = true;\n> > +};\n> > +\n> > +template<typename EF>\n> > +scope_exit(EF) -> scope_exit<EF>;\n> > +\n> > +#endif /* __DOXYGEN__ */\n> > +\n> >   } /* namespace utils */\n> > \n> >   #ifndef __DOXYGEN__","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 54EC0BE086\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon,  4 Aug 2025 22:40:46 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 70C936921D;\n\tTue,  5 Aug 2025 00:40:45 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id D1B6D691D5\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  5 Aug 2025 00:40:43 +0200 (CEST)","from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi\n\t[81.175.209.231])\n\tby perceval.ideasonboard.com (Postfix) with UTF8SMTPSA id 2ACB51FE4; \n\tTue,  5 Aug 2025 00:39:56 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"t9C2GpTT\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1754347196;\n\tbh=FOpRQWKYAdCFx2r95dKnmwQN9sv7bvNvw27yJgEjLRU=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=t9C2GpTTLtXXjY2uNJD2aKR0pjUtQBjuTAYs3VOCRz9qZdymPPUhr4rQi+eYUn6VO\n\tIG+o0+9O3BuZ561PenkibjYH8m91XEm6uCz20TGAnLvqhdIT2wmMmVgKReNqIzHIiK\n\t4CmyxXC4mUkvSQOSoIiVUu7ccY1O1925k/d8dMOc=","Date":"Tue, 5 Aug 2025 01:40:27 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <barnabas.pocze@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Subject":"Re: [PATCH v3 1/2] libcamera: utils: Add scope_exit class","Message-ID":"<20250804224027.GA31914@pendragon.ideasonboard.com>","References":"<20250730102733.21314-1-laurent.pinchart@ideasonboard.com>\n\t<20250730102733.21314-2-laurent.pinchart@ideasonboard.com>\n\t<e4a9d92c-244a-4e8b-ae2c-7480bfe5196c@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<e4a9d92c-244a-4e8b-ae2c-7480bfe5196c@ideasonboard.com>","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>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]