spdlog/include/spdlog/details/null_mutex.h

50 lines
1.0 KiB
C
Raw Normal View History

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