Agora  1.2.0
Agora project
null_mutex.h
Go to the documentation of this file.
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 {
14  void lock() const {}
15  void unlock() const {}
16  bool try_lock() const
17  {
18  return true;
19  }
20 };
21 
23 {
24  int value;
25  null_atomic_int() = default;
26 
27  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
spdlog::details::null_atomic_int::store
void store(int new_value, std::memory_order=std::memory_order_relaxed)
Definition: null_mutex.h:36
spdlog::details::null_mutex::unlock
void unlock() const
Definition: null_mutex.h:15
spdlog::details::null_atomic_int::load
int load(std::memory_order=std::memory_order_relaxed) const
Definition: null_mutex.h:31
std::swap
void swap(nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType > &j1, nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType > &j2) noexcept(//NOLINT(readability-inconsistent-declaration-parameter-name) is_nothrow_move_constructible< nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType > >::value &&//NOLINT(misc-redundant-expression) is_nothrow_move_assignable< nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType > >::value)
exchanges the values of two JSON objects
Definition: json.hpp:24114
spdlog::details::null_atomic_int::exchange
int exchange(int new_value, std::memory_order=std::memory_order_relaxed)
Definition: null_mutex.h:41
spdlog
Definition: async.h:25
spdlog::details::null_atomic_int::null_atomic_int
null_atomic_int(int new_value)
Definition: null_mutex.h:27
spdlog::details::null_atomic_int
Definition: null_mutex.h:22
spdlog::details::null_mutex::try_lock
bool try_lock() const
Definition: null_mutex.h:16
spdlog::details::null_atomic_int::null_atomic_int
null_atomic_int()=default
spdlog::details::null_atomic_int::value
int value
Definition: null_mutex.h:24
spdlog::details::null_mutex
Definition: null_mutex.h:12
spdlog::details::null_mutex::lock
void lock() const
Definition: null_mutex.h:14