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 | |
10 | namespace spdlog { |
11 | namespace details { |
12 | struct null_mutex |
13 | { |
14 | void lock() const {} |
15 | void unlock() const {} |
16 | }; |
17 | |
18 | struct null_atomic_int |
19 | { |
20 | int value; |
21 | null_atomic_int() = default; |
22 | |
23 | explicit null_atomic_int(int new_value) |
24 | : value(new_value) |
25 | {} |
26 | |
27 | int load(std::memory_order = std::memory_order_relaxed) const |
28 | { |
29 | return value; |
30 | } |
31 | |
32 | void store(int new_value, std::memory_order = std::memory_order_relaxed) |
33 | { |
34 | value = new_value; |
35 | } |
36 | |
37 | int exchange(int new_value, std::memory_order = std::memory_order_relaxed) |
38 | { |
39 | std::swap(new_value, value); |
40 | return new_value; // return value before the call |
41 | } |
42 | }; |
43 | |
44 | } // namespace details |
45 | } // namespace spdlog |
46 | |