36 lines
930 B
C
Raw Normal View History

2021-07-08 07:07:27 -07:00
// Copyright(c) 2015-present, Gabi Melman & spdlog contributors.
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
#pragma once
#include <atomic>
#include <utility>
// null, no cost dummy "mutex" and dummy "atomic" int
namespace spdlog {
namespace details {
2024-02-04 13:43:17 +01:00
struct null_mutex {
2021-07-08 07:07:27 -07:00
void lock() const {}
void unlock() const {}
};
2024-02-04 13:43:17 +01:00
struct null_atomic_int {
2021-07-08 07:07:27 -07:00
int value;
null_atomic_int() = default;
explicit null_atomic_int(int new_value)
2024-02-04 13:43:17 +01:00
: value(new_value) {}
2021-07-08 07:07:27 -07:00
2024-02-04 13:43:17 +01:00
int load(std::memory_order = std::memory_order_relaxed) const { return value; }
2021-07-08 07:07:27 -07:00
2024-02-04 13:43:17 +01:00
void store(int new_value, std::memory_order = std::memory_order_relaxed) { value = new_value; }
2021-07-08 07:07:27 -07:00
2024-02-04 13:43:17 +01:00
int exchange(int new_value, std::memory_order = std::memory_order_relaxed) {
2021-07-08 07:07:27 -07:00
std::swap(new_value, value);
2024-02-04 13:43:17 +01:00
return new_value; // return value before the call
2021-07-08 07:07:27 -07:00
}
};
2024-02-04 13:43:17 +01:00
} // namespace details
} // namespace spdlog