Skip to content

Commit

Permalink
Fix #1215
Browse files Browse the repository at this point in the history
  • Loading branch information
gabime committed Sep 7, 2019
1 parent bd9e147 commit 1857a44
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
1 change: 1 addition & 0 deletions include/spdlog/common.h
Expand Up @@ -4,6 +4,7 @@
#pragma once

#include "spdlog/tweakme.h"
#include "spdlog/details/null_mutex.h"

#include <atomic>
#include <chrono>
Expand Down
23 changes: 15 additions & 8 deletions include/spdlog/details/null_mutex.h
Expand Up @@ -4,15 +4,16 @@
#pragma once

#include <atomic>
#include <utility>
// 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;
}
Expand All @@ -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
}
};

Expand Down

0 comments on commit 1857a44

Please sign in to comment.