You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
spdlog/include/spdlog/details/null_mutex.h

39 lines
1004 B
C

// Copyright(c) 2015-present, Gabi Melman & spdlog contributors.
10 years ago
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
11 years ago
11 years ago
#pragma once
#include <atomic>
6 years ago
#include <utility>
#include "../common.h"
2 years ago
// null, no cost dummy "mutex" and dummy "atomic" log level
11 years ago
8 years ago
namespace spdlog {
namespace details {
struct SPDLOG_API null_mutex {
6 years ago
void lock() const {}
void unlock() const {}
11 years ago
};
template <typename T>
struct SPDLOG_API null_atomic {
2 years ago
T value;
2 years ago
null_atomic() = default;
explicit constexpr null_atomic(T new_value)
: value(new_value) {}
[[nodiscard]] T load(std::memory_order = std::memory_order_seq_cst) const { return value; }
void store(T new_value, std::memory_order = std::memory_order_seq_cst) { value = new_value; }
6 years ago
T exchange(T new_value, std::memory_order = std::memory_order_seq_cst) {
6 years ago
std::swap(new_value, value);
return new_value; // return value before the call
9 years ago
}
};
} // namespace details
} // namespace spdlog