1 // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 4 #pragma once 5 6 #include <atomic> 7 #include <utility> 8 // null, no cost dummy "mutex" and dummy "atomic" int 9 10 namespace spdlog { 11 namespace details { 12 struct null_mutex 13 { locknull_mutex14 void lock() const {} unlocknull_mutex15 void unlock() const {} try_locknull_mutex16 bool try_lock() const 17 { 18 return true; 19 } 20 }; 21 22 struct null_atomic_int 23 { 24 int value; 25 null_atomic_int() = default; 26 null_atomic_intnull_atomic_int27 explicit null_atomic_int(int new_value) 28 : value(new_value) 29 {} 30 31 int load(std::memory_order = std::memory_order_relaxed) const 32 { 33 return value; 34 } 35 36 void store(int new_value, std::memory_order = std::memory_order_relaxed) 37 { 38 value = new_value; 39 } 40 41 int exchange(int new_value, std::memory_order = std::memory_order_relaxed) 42 { 43 std::swap(new_value, value); 44 return new_value; // return value before the call 45 } 46 }; 47 48 } // namespace details 49 } // namespace spdlog 50