Skip to content

Commit

Permalink
Use nano specific lock primitives
Browse files Browse the repository at this point in the history
  • Loading branch information
pwojcikdev committed Nov 11, 2023
1 parent bacfaae commit 4d52049
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions nano/lib/uniquer.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <nano/lib/interval.hpp>
#include <nano/lib/locks.hpp>
#include <nano/lib/utility.hpp>

#include <memory>
Expand All @@ -24,7 +25,7 @@ class uniquer final
// Types used as value need to provide full_hash()
Key hash = value->full_hash ();

std::lock_guard guard{ mutex };
nano::lock_guard<nano::mutex> guard{ mutex };

if (cleanup_interval.elapsed ())
{
Expand All @@ -46,13 +47,13 @@ class uniquer final

std::size_t size () const
{
std::lock_guard guard{ mutex };
nano::lock_guard<nano::mutex> guard{ mutex };
return values.size ();
}

std::unique_ptr<container_info_component> collect_container_info (std::string const & name) const
{
std::lock_guard guard{ mutex };
nano::lock_guard<nano::mutex> guard{ mutex };

auto composite = std::make_unique<container_info_composite> (name);
composite->add_component (std::make_unique<container_info_leaf> (container_info{ "cache", values.size (), sizeof (Value) }));
Expand All @@ -72,8 +73,8 @@ class uniquer final
}

private:
mutable std::mutex mutex{};
std::unordered_map<Key, std::weak_ptr<Value>> values{};
mutable nano::mutex mutex;
std::unordered_map<Key, std::weak_ptr<Value>> values;
nano::interval cleanup_interval{ cleanup_cutoff };
};
}

0 comments on commit 4d52049

Please sign in to comment.