[PATCH v3 8/8] libcamera: base: log: Avoid manual `LogCategory` deletion
Barnabás Pőcze
pobrn at protonmail.com
Mon Feb 17 19:55:10 CET 2025
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>
---
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 fd6c11716..e05ffc1c4 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::atomic<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 *name_cstr = category->name().c_str();
for (const auto &[pattern, severity] : levels_) {
--
2.48.1
More information about the libcamera-devel
mailing list