Skip to content

Commit

Permalink
Bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
robomics committed Nov 7, 2024
1 parent 66efea2 commit 64fd056
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions src/hictk/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,15 @@ class GlobalLogger {
}

void enqueue_msg(const spdlog::details::log_msg &msg) noexcept {
if (msg.level < spdlog::level::warn) [[likely]] {
if (msg.level < spdlog::level::warn) {
return;
}

++_num_msg_enqueued;

try {
[[maybe_unused]] const std::scoped_lock lck(_mtx);
if (_msg_buffer.size() == CAPACITY) [[unlikely]] {
if (_msg_buffer.size() == CAPACITY) {
_msg_buffer.pop_front();
}
_msg_buffer.emplace_back(msg.level, std::string{msg.payload.begin(), msg.payload.end()});
Expand Down Expand Up @@ -122,10 +122,30 @@ class GlobalLogger {
}

GlobalLogger(const GlobalLogger &other) = delete;
GlobalLogger(GlobalLogger &&other) noexcept = default;
GlobalLogger(GlobalLogger &&other) noexcept
: _msg_buffer(std::move(other._msg_buffer)),
_num_msg_enqueued(other._num_msg_enqueued.load()),
_ok(other._ok.load()) {
other._num_msg_enqueued = 0;
other._ok = false;
}

GlobalLogger &operator=(const GlobalLogger &other) = delete;
GlobalLogger &operator=(GlobalLogger &&other) noexcept = default;
GlobalLogger &operator=(GlobalLogger &&other) noexcept {
if (this == &other) {
return *this;
}

[[maybe_unused]] const auto lck = std::scoped_lock(other._mtx);
_msg_buffer = std::move(other._msg_buffer);
_num_msg_enqueued = other._num_msg_enqueued.load();
_ok = other._ok.load();

other._num_msg_enqueued = 0;
other._ok = false;

return *this;
}

~GlobalLogger() noexcept {
if (!_ok) {
Expand Down

0 comments on commit 64fd056

Please sign in to comment.