From patchwork Mon Feb 3 17:59:39 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= X-Patchwork-Id: 22726 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 2F8C9BD80A for ; Mon, 3 Feb 2025 17:59:47 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 458E86859D; Mon, 3 Feb 2025 18:59:46 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=protonmail.com header.i=@protonmail.com header.b="Fl+gSCjd"; dkim-atps=neutral Received: from mail-10630.protonmail.ch (mail-10630.protonmail.ch [79.135.106.30]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id C40D761876 for ; Mon, 3 Feb 2025 18:59:44 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1738605583; x=1738864783; bh=iS7KFwtgjtdLe3sYFbSNvmj0wqHbsFaZ+7FduZfw03c=; h=Date:To:From:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector:List-Unsubscribe:List-Unsubscribe-Post; b=Fl+gSCjdD3ZRkS96j2znUC3VjR3UJOpW9QNocRJ7D18WNXbsKEtzMZp68sFeM09uy JxEm4oJurVvBuamBjKWDBEgT8VJT93SmDrZQBcumHHfabbGWMcvk8xGbSXSvzIhJyk iwgronNvdv3akJEQQe9ByDL07NEKSmK/SD3mZmpe/PI5RfHoj5rk2yypUF5I8eNIxP dKZNKcL/oY2S8WCUXx+Bh17RXokmxTCqtb+yK3OJIiNjlsA+S8wjKpJykV/uWixEjD WpPL46k0DG3ublQC1R6L/1EmSVdeFqJ+aryIRBuv1rCvHCjMjAZ0l1t5oqa2BvXg// UeQ3QpVbkUWbw== Date: Mon, 03 Feb 2025 17:59:39 +0000 To: libcamera-devel@lists.libcamera.org From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Subject: [RFC PATCH v2 9/9] libcamera: base: log: Store categories in list Message-ID: <20250203175936.206161-1-pobrn@protonmail.com> In-Reply-To: <20250130195811.1230581-1-pobrn@protonmail.com> References: <20250130195811.1230581-1-pobrn@protonmail.com> Feedback-ID: 20568564:user:proton X-Pm-Message-ID: f931f503d745fcf4965e1180b2ff1189a3d7bfee 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" Store the `LogCategory` objects in an `std::list`. This eliminates the need for manually deleting them in the destructor while guaranteeing address stability. Signed-off-by: Barnabás Pőcze Reviewed-by: Jacopo Mondi --- src/libcamera/base/log.cpp | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/src/libcamera/base/log.cpp b/src/libcamera/base/log.cpp index 69aa16c4c..003e2cf3a 100644 --- a/src/libcamera/base/log.cpp +++ b/src/libcamera/base/log.cpp @@ -407,7 +407,7 @@ private: static bool destroyed_; Mutex mutex_; - std::vector categories_; + std::list categories_; std::list> levels_; std::shared_ptr output_; @@ -524,9 +524,6 @@ void logSetLevel(const char *category, const char *level) Logger::~Logger() { destroyed_ = true; - - for (LogCategory *category : categories_) - delete category; } /** @@ -659,9 +656,9 @@ void Logger::logSetLevel(const char *category, const char *level) MutexLocker locker(mutex_); - for (LogCategory *c : categories_) { - if (c->name() == category) { - c->setSeverity(severity); + for (LogCategory &c : categories_) { + if (c.name() == category) { + c.setSeverity(severity); break; } } @@ -717,12 +714,12 @@ LogCategory *Logger::findOrCreateCategory(std::string_view name) { MutexLocker locker(mutex_); - for (LogCategory *category : categories_) { - if (category->name() == name) - return category; + for (LogCategory &category : categories_) { + if (category.name() == name) + return &category; } - LogCategory *category = categories_.emplace_back(new LogCategory(name)); + LogCategory &category = categories_.emplace_back(name); for (const std::pair &level : levels_) { bool match = true; @@ -739,12 +736,12 @@ LogCategory *Logger::findOrCreateCategory(std::string_view name) } if (match) { - category->setSeverity(level.second); + category.setSeverity(level.second); break; } } - return category; + return &category; } /**