From patchwork Wed Oct 23 16:58:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cheng-Hao Yang X-Patchwork-Id: 21746 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 5BBF2C0DA4 for ; Wed, 23 Oct 2024 16:58:22 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 22EA26538A; Wed, 23 Oct 2024 18:58:21 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="j7WpBKO5"; dkim-atps=neutral Received: from mail-pg1-x52a.google.com (mail-pg1-x52a.google.com [IPv6:2607:f8b0:4864:20::52a]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 52C736537E for ; Wed, 23 Oct 2024 18:58:19 +0200 (CEST) Received: by mail-pg1-x52a.google.com with SMTP id 41be03b00d2f7-7ea0ff74b15so4634925a12.3 for ; Wed, 23 Oct 2024 09:58:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1729702697; x=1730307497; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=cXQ/zFdKudlz8s25Cl5h6yz4gizr21nKE3SmdZrDzr4=; b=j7WpBKO5Xhmfc0MFCZLWE1IIkyLGJlzTkzRyT8Td6HUtT2bUVrGyfukIiWpiMcPhQA Be0rW8ATc+mXR8CvH+ZGPuCjkk3IcKdZAAahyE0+SocxbDMTKL+H1ZOOvouYPo4I5D0F zr7JnD/H8r9rgKEg/3A9lGzGvFWm4HlR+ad44= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729702697; x=1730307497; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=cXQ/zFdKudlz8s25Cl5h6yz4gizr21nKE3SmdZrDzr4=; b=MbEW28bskf0YL/e5rdlP3ta1yROHaZIIkeK0hlIk0/bRAoOWs1cdKlA/k6Z50F88eS MlK4L9WlKCAR3MKrsOedFBn3swi3VYCtflgg/H+8mQjSUeu6qNaDNJ++sERh+SMmaQ7J g9I9hyPmFgZ3Bb+CBzN92v+Sggx8/4bU7X0KuY7rxj3x5rOkAdEQmKc1F95dCgnPIhP6 nMKAV0E5Il4fPLbGrmNC93JChFxsM/0JaFEGu7B5S6uwzTEA+S77mDRwZxZpQyB6YsEB RpWpINs/RJHyKxJUJ0r2D1/xfB7IKIenmst75tU5kaL/wgY0lUM25kLa8fchPuvAZv/w oG8A== X-Gm-Message-State: AOJu0Ywj1ZLmLlk0nyPvNW34lbUOW1vDmpNO55PG69/81RGTRLCZie0G REnXyYI89s/qVTzjf6DaZiqWBb7Aa3EAW+LSrqH9zA0H4J6+xcKzA8EJ5btHAjnya/Unw713wuk = X-Google-Smtp-Source: AGHT+IH8vLxydn3zFaBIssb2jkWdEnK+CzFTghayk8RJGZJwRtchFI1dF8WgU3dG6zlDOGXQ+UCVQQ== X-Received: by 2002:a05:6a20:c797:b0:1d9:4837:ada1 with SMTP id adf61e73a8af0-1d978b9906dmr4217176637.35.1729702697353; Wed, 23 Oct 2024 09:58:17 -0700 (PDT) Received: from chenghaoyang-low.c.googlers.com.com (199.211.81.34.bc.googleusercontent.com. [34.81.211.199]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7eaeab1e31esm7054958a12.26.2024.10.23.09.58.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Oct 2024 09:58:16 -0700 (PDT) From: Harvey Yang To: libcamera-devel@lists.libcamera.org Cc: Harvey Yang Subject: [PATCH] libcamera: Add static Object::Deleter function Date: Wed, 23 Oct 2024 16:58:04 +0000 Message-ID: <20241023165812.868221-1-chenghaoyang@chromium.org> X-Mailer: git-send-email 2.47.0.105.g07ac214952-goog MIME-Version: 1.0 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" This patch allows a smart pointer of Object to be destructed in other threads. There will be multiple usages of smart pointers of Object. This patch adds the deleter function to avoid duplicated code. Signed-off-by: Harvey Yang --- include/libcamera/base/object.h | 2 ++ src/libcamera/base/object.cpp | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/include/libcamera/base/object.h b/include/libcamera/base/object.h index 508773cd0..c4522d480 100644 --- a/include/libcamera/base/object.h +++ b/include/libcamera/base/object.h @@ -24,6 +24,8 @@ class Thread; class Object { public: + static void Deleter(Object *obj); + Object(Object *parent = nullptr); virtual ~Object(); diff --git a/src/libcamera/base/object.cpp b/src/libcamera/base/object.cpp index 745d2565a..2c04b99a5 100644 --- a/src/libcamera/base/object.cpp +++ b/src/libcamera/base/object.cpp @@ -59,6 +59,17 @@ LOG_DEFINE_CATEGORY(Object) * \sa Message, Signal, Thread */ +/** + * \brief A deleter function that calls Object::deleteLater + * \param[in] obj The object itself + * + * The static deleter function that's used in smart pointers. + */ +void Object::Deleter(Object *obj) +{ + obj->deleteLater(); +} + /** * \brief Construct an Object instance * \param[in] parent The object parent