summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorBarnabás Pőcze <pobrn@protonmail.com>2025-01-29 16:12:06 +0100
committerBarnabás Pőcze <pobrn@protonmail.com>2025-02-27 11:30:23 +0100
commit9ac914c6341817c31c002932e943c932cbffe5db (patch)
tree7e039262573af74a7b116df1eca9fbb2352102da /include
parentaca8457d34e975c0b495636c2a4b8a1fb05e739c (diff)
libcamera: base: log: Protect log categories with lock
Log categories may be added from any thread, so it is important to synchronize access to the `Logger::categories_` list between its two users: category creation (by LogCategory::create(), which calls Logger::findCategory() and Logger::registerCategory()); and log level setting (by Logger::logSetLevel()). The LogCategory::create() function uses a mutex to serialize category creation, but Logger::logSetLevel() can access `Logger::categories_` concurrently without any protection. To fix the issue, move the mutex to the Logger class, and use it to protect all accesses to the categories list. This requires moving all the logic of LogCategory::create() to a new Logger::findOrCreateCategory() function that combines both Logger::findCategory() and Logger::registerCategory() in order to make the two operations exacute atomically. Signed-off-by: Barnabás Pőcze <pobrn@protonmail.com> Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Diffstat (limited to 'include')
-rw-r--r--include/libcamera/base/log.h1
1 files changed, 1 insertions, 0 deletions
diff --git a/include/libcamera/base/log.h b/include/libcamera/base/log.h
index 1fb92603..8af74b59 100644
--- a/include/libcamera/base/log.h
+++ b/include/libcamera/base/log.h
@@ -39,6 +39,7 @@ public:
static const LogCategory &defaultCategory();
private:
+ friend class Logger;
explicit LogCategory(std::string_view name);
const std::string name_;