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