summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Dufresne <nicolas.dufresne@collabora.com>2023-03-13 16:41:35 -0400
committerKieran Bingham <kieran.bingham@ideasonboard.com>2023-03-21 23:30:22 +0000
commit2ccca099d3cbdfa32f0a8bfd2168873b7b803159 (patch)
tree655c58ac53e959f8090f9636f74c1e3d5982d70c
parentf852b7fbc4960ea83bab49b75408fb13462db8ba (diff)
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 <nicolas.dufresne@collabora.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
-rw-r--r--src/libcamera/base/log.cpp3
1 files changed, 3 insertions, 0 deletions
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 <libcamera/logging.h>
#include <libcamera/base/backtrace.h>
+#include <libcamera/base/mutex.h>
#include <libcamera/base/thread.h>
#include <libcamera/base/utils.h>
@@ -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) {