2019-06-04 05:09:16 +08:00
|
|
|
// Copyright(c) 2015-present, Gabi Melman & spdlog contributors.
|
2015-11-29 00:24:20 +08:00
|
|
|
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
2014-11-01 09:20:54 +08:00
|
|
|
|
2014-10-11 02:36:32 +08:00
|
|
|
#pragma once
|
|
|
|
|
2016-04-10 06:37:11 +08:00
|
|
|
#include <atomic>
|
2019-09-08 01:11:58 +08:00
|
|
|
#include <utility>
|
2016-04-10 06:37:11 +08:00
|
|
|
// null, no cost dummy "mutex" and dummy "atomic" int
|
2014-10-11 02:36:32 +08:00
|
|
|
|
2018-03-17 18:47:46 +08:00
|
|
|
namespace spdlog {
|
|
|
|
namespace details {
|
2014-10-11 02:36:32 +08:00
|
|
|
struct null_mutex
|
|
|
|
{
|
2019-09-08 01:11:58 +08:00
|
|
|
void lock() const {}
|
|
|
|
void unlock() const {}
|
|
|
|
bool try_lock() const
|
2014-12-21 08:47:04 +08:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2014-10-11 02:36:32 +08:00
|
|
|
};
|
2016-04-10 06:37:11 +08:00
|
|
|
|
|
|
|
struct null_atomic_int
|
|
|
|
{
|
2016-04-20 16:57:49 +08:00
|
|
|
int value;
|
|
|
|
null_atomic_int() = default;
|
2016-04-10 06:37:11 +08:00
|
|
|
|
2019-09-08 01:11:58 +08:00
|
|
|
explicit null_atomic_int(int new_value)
|
|
|
|
: value(new_value)
|
2019-05-12 05:22:39 +08:00
|
|
|
{}
|
2016-04-10 06:37:11 +08:00
|
|
|
|
2019-09-08 01:11:58 +08:00
|
|
|
int load(std::memory_order = std::memory_order_relaxed) const
|
2016-04-20 16:57:49 +08:00
|
|
|
{
|
|
|
|
return value;
|
|
|
|
}
|
2016-04-10 06:37:11 +08:00
|
|
|
|
2019-09-08 01:11:58 +08:00
|
|
|
void store(int new_value, std::memory_order = std::memory_order_relaxed)
|
2016-04-20 16:57:49 +08:00
|
|
|
{
|
2019-09-08 01:11:58 +08:00
|
|
|
value = new_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
int exchange(int new_value, std::memory_order = std::memory_order_relaxed)
|
|
|
|
{
|
|
|
|
std::swap(new_value, value);
|
|
|
|
return new_value; // return value before the call
|
2016-04-20 16:57:49 +08:00
|
|
|
}
|
2016-04-10 06:37:11 +08:00
|
|
|
};
|
|
|
|
|
2018-03-17 18:47:46 +08:00
|
|
|
} // namespace details
|
|
|
|
} // namespace spdlog
|