[PATCH v4 8/8] libcamera: base: log: Avoid manual `LogCategory` deletion
Jacopo Mondi
jacopo.mondi at ideasonboard.com
Wed Feb 26 08:55:33 CET 2025
Hi Barnabás
On Tue, Feb 25, 2025 at 05:36:22PM +0000, Barnabás Pőcze wrote:
> Wrap the `LogCategory` pointers in `std::unique_ptr` to avoid
> the need for manual deletion in the destructor.
>
> Signed-off-by: Barnabás Pőcze <pobrn at protonmail.com>
> Reviewed-by: Laurent Pinchart <laurent.pinchart at ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo.mondi at ideasonboard.com>
> ---
> src/libcamera/base/log.cpp | 13 +++++--------
> 1 file changed, 5 insertions(+), 8 deletions(-)
>
> diff --git a/src/libcamera/base/log.cpp b/src/libcamera/base/log.cpp
> index 155355f0c..72614eeb1 100644
> --- a/src/libcamera/base/log.cpp
> +++ b/src/libcamera/base/log.cpp
> @@ -322,7 +322,7 @@ private:
> static bool destroyed_;
>
> Mutex mutex_;
> - std::vector<LogCategory *> categories_ LIBCAMERA_TSA_GUARDED_BY(mutex_);
> + std::vector<std::unique_ptr<LogCategory>> categories_ LIBCAMERA_TSA_GUARDED_BY(mutex_);
> std::list<std::pair<std::string, LogSeverity>> levels_;
>
> std::shared_ptr<LogOutput> output_;
> @@ -439,9 +439,6 @@ void logSetLevel(const char *category, const char *level)
> Logger::~Logger()
> {
> destroyed_ = true;
> -
> - for (LogCategory *category : categories_)
> - delete category;
> }
>
> /**
> @@ -574,7 +571,7 @@ void Logger::logSetLevel(const char *category, const char *level)
>
> MutexLocker locker(mutex_);
>
> - for (LogCategory *c : categories_) {
> + for (const auto &c : categories_) {
> if (c->name() == category) {
> c->setSeverity(severity);
> break;
> @@ -718,12 +715,12 @@ LogCategory *Logger::findOrCreateCategory(std::string_view name)
> {
> MutexLocker locker(mutex_);
>
> - for (LogCategory *category : categories_) {
> + for (const auto &category : categories_) {
> if (category->name() == name)
> - return category;
> + return category.get();
> }
>
> - LogCategory *category = categories_.emplace_back(new LogCategory(name));
> + LogCategory *category = categories_.emplace_back(std::unique_ptr<LogCategory>(new LogCategory(name))).get();
> const char *categoryName = category->name().c_str();
>
> for (const auto &[pattern, severity] : levels_) {
> --
> 2.48.1
>
>
More information about the libcamera-devel
mailing list