1// Copyright(c) 2015-present, Gabi Melman & spdlog contributors.
2// Distributed under the MIT License (http://opensource.org/licenses/MIT)
3
4#pragma once
5
6#include <atomic>
7#include <utility>
8// null, no cost dummy "mutex" and dummy "atomic" int
9
10namespace spdlog {
11namespace details {
12struct null_mutex {
13 void lock() const {}
14 void unlock() const {}
15};
16
17struct null_atomic_int {
18 int value;
19 null_atomic_int() = default;
20
21 explicit null_atomic_int(int new_value)
22 : value(new_value) {}
23
24 int load(std::memory_order = std::memory_order_relaxed) const { return value; }
25
26 void store(int new_value, std::memory_order = std::memory_order_relaxed) { value = new_value; }
27
28 int exchange(int new_value, std::memory_order = std::memory_order_relaxed) {
29 std::swap(a&: new_value, b&: value);
30 return new_value; // return value before the call
31 }
32};
33
34} // namespace details
35} // namespace spdlog
36