mirror of
https://github.com/gabime/spdlog.git
synced 2024-11-15 16:35:45 +08:00
Fix #1215
This commit is contained in:
parent
bd9e1475e2
commit
1857a44c7c
@ -4,6 +4,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "spdlog/tweakme.h"
|
#include "spdlog/tweakme.h"
|
||||||
|
#include "spdlog/details/null_mutex.h"
|
||||||
|
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
@ -4,15 +4,16 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
|
#include <utility>
|
||||||
// null, no cost dummy "mutex" and dummy "atomic" int
|
// null, no cost dummy "mutex" and dummy "atomic" int
|
||||||
|
|
||||||
namespace spdlog {
|
namespace spdlog {
|
||||||
namespace details {
|
namespace details {
|
||||||
struct null_mutex
|
struct null_mutex
|
||||||
{
|
{
|
||||||
void lock() {}
|
void lock() const {}
|
||||||
void unlock() {}
|
void unlock() const {}
|
||||||
bool try_lock()
|
bool try_lock() const
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -23,18 +24,24 @@ struct null_atomic_int
|
|||||||
int value;
|
int value;
|
||||||
null_atomic_int() = default;
|
null_atomic_int() = default;
|
||||||
|
|
||||||
explicit null_atomic_int(int val)
|
explicit null_atomic_int(int new_value)
|
||||||
: value(val)
|
: value(new_value)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
int load(std::memory_order) const
|
int load(std::memory_order = std::memory_order_relaxed) const
|
||||||
{
|
{
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
void store(int val)
|
void store(int new_value, std::memory_order = std::memory_order_relaxed)
|
||||||
{
|
{
|
||||||
value = val;
|
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
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user