Skip to content

Commit

Permalink
libcamera: base: Make the registration of log categories atomic
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-by: Kieran Bingham <[email protected]>
Reviewed-by: Laurent Pinchart <[email protected]>
Signed-off-by: Kieran Bingham <[email protected]>
  • Loading branch information
ndufresne authored and kbingham committed Mar 21, 2023
1 parent f852b7f commit 2ccca09
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/libcamera/base/log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 2ccca09

Please sign in to comment.