From 2ccca099d3cbdfa32f0a8bfd2168873b7b803159 Mon Sep 17 00:00:00 2001 From: Nicolas Dufresne Date: Mon, 13 Mar 2023 16:41:35 -0400 Subject: libcamera: base: Make the registration of log categories atomic Logger::create() is not currently thread safe and causes crashes noticeable on RaspberryPi 4. This adds a mutex around the creation of categories. Signed-off-by: Nicolas Dufresne Reviewed-by: Kieran Bingham Reviewed-by: Laurent Pinchart Signed-off-by: Kieran Bingham --- src/libcamera/base/log.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/libcamera/base/log.cpp b/src/libcamera/base/log.cpp index 55fbd7b0..c8045ef7 100644 --- a/src/libcamera/base/log.cpp +++ b/src/libcamera/base/log.cpp @@ -21,6 +21,7 @@ #include #include +#include #include #include @@ -788,6 +789,8 @@ LogCategory *Logger::findCategory(const char *name) const */ LogCategory *LogCategory::create(const char *name) { + static Mutex mutex_; + MutexLocker locker(mutex_); LogCategory *category = Logger::instance()->findCategory(name); if (!category) { -- cgit v1.2.1