libcamera: base: log: Make LogCategory::severity_
atomic
The severity of a log category may be changed from a different thread, so it is important to ensure that the reads and writes happen atomically. Using `std::memory_order_relaxed` should not introduce any synchronization overhead, it should only guarantee that the operation itself is atomic. Secondly, inline `LogCategory::setSeverity()`, as it is merely an assignment, so going through a DSO call is a big pessimization. `LogCategory` is not part of the public API, so this change has no external effects. Thirdly, assert that the atomic variable is lock free so as to ensure it won't silently fall back to libatomic (or similar) on any platform. If this assertion fails, this needs to be revisited. Signed-off-by: Barnabás Pőcze <pobrn@protonmail.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
This commit is contained in:
parent
5d0af9840b
commit
16bcc5a3e4
2 changed files with 7 additions and 7 deletions
|
@ -7,6 +7,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <atomic>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
#include <libcamera/base/private.h>
|
#include <libcamera/base/private.h>
|
||||||
|
@ -31,8 +32,8 @@ public:
|
||||||
static LogCategory *create(const char *name);
|
static LogCategory *create(const char *name);
|
||||||
|
|
||||||
const std::string &name() const { return name_; }
|
const std::string &name() const { return name_; }
|
||||||
LogSeverity severity() const { return severity_; }
|
LogSeverity severity() const { return severity_.load(std::memory_order_relaxed); }
|
||||||
void setSeverity(LogSeverity severity);
|
void setSeverity(LogSeverity severity) { severity_.store(severity, std::memory_order_relaxed); }
|
||||||
|
|
||||||
static const LogCategory &defaultCategory();
|
static const LogCategory &defaultCategory();
|
||||||
|
|
||||||
|
@ -40,7 +41,9 @@ private:
|
||||||
explicit LogCategory(const char *name);
|
explicit LogCategory(const char *name);
|
||||||
|
|
||||||
const std::string name_;
|
const std::string name_;
|
||||||
LogSeverity severity_;
|
|
||||||
|
std::atomic<LogSeverity> severity_;
|
||||||
|
static_assert(decltype(severity_)::is_always_lock_free);
|
||||||
};
|
};
|
||||||
|
|
||||||
#define LOG_DECLARE_CATEGORY(name) \
|
#define LOG_DECLARE_CATEGORY(name) \
|
||||||
|
|
|
@ -810,15 +810,12 @@ LogCategory::LogCategory(const char *name)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* \fn LogCategory::setSeverity(LogSeverity severity)
|
||||||
* \brief Set the severity of the log category
|
* \brief Set the severity of the log category
|
||||||
*
|
*
|
||||||
* Messages of severity higher than or equal to the severity of the log category
|
* Messages of severity higher than or equal to the severity of the log category
|
||||||
* are printed, other messages are discarded.
|
* are printed, other messages are discarded.
|
||||||
*/
|
*/
|
||||||
void LogCategory::setSeverity(LogSeverity severity)
|
|
||||||
{
|
|
||||||
severity_ = severity;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Retrieve the default log category
|
* \brief Retrieve the default log category
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue