From 1857a44c7c893b4526724d5a47875d163f9d2d1c Mon Sep 17 00:00:00 2001 From: gabime Date: Sat, 7 Sep 2019 20:11:58 +0300 Subject: [PATCH] Fix #1215 --- include/spdlog/common.h | 1 + include/spdlog/details/null_mutex.h | 23 +++++++++++++++-------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/include/spdlog/common.h b/include/spdlog/common.h index d1fa47766..7876e7617 100644 --- a/include/spdlog/common.h +++ b/include/spdlog/common.h @@ -4,6 +4,7 @@ #pragma once #include "spdlog/tweakme.h" +#include "spdlog/details/null_mutex.h" #include #include diff --git a/include/spdlog/details/null_mutex.h b/include/spdlog/details/null_mutex.h index d1062db7d..83533d4fe 100644 --- a/include/spdlog/details/null_mutex.h +++ b/include/spdlog/details/null_mutex.h @@ -4,15 +4,16 @@ #pragma once #include +#include // null, no cost dummy "mutex" and dummy "atomic" int namespace spdlog { namespace details { struct null_mutex { - void lock() {} - void unlock() {} - bool try_lock() + void lock() const {} + void unlock() const {} + bool try_lock() const { return true; } @@ -23,18 +24,24 @@ struct null_atomic_int int value; null_atomic_int() = default; - explicit null_atomic_int(int val) - : value(val) + explicit null_atomic_int(int new_value) + : value(new_value) {} - int load(std::memory_order) const + int load(std::memory_order = std::memory_order_relaxed) const { 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 } };