mirror of
https://github.com/NixOS/nix.git
synced 2025-11-09 12:06:01 +01:00
Merge pull request #13478 from NixOS/posix-source-accessor-concurrent-map
PosixSourceAccessor: Use concurrent_flat_map
This commit is contained in:
commit
cbdb497c79
1 changed files with 10 additions and 12 deletions
|
|
@ -3,7 +3,7 @@
|
|||
#include "nix/util/signals.hh"
|
||||
#include "nix/util/sync.hh"
|
||||
|
||||
#include <unordered_map>
|
||||
#include <boost/unordered/concurrent_flat_map.hpp>
|
||||
|
||||
namespace nix {
|
||||
|
||||
|
|
@ -88,25 +88,23 @@ bool PosixSourceAccessor::pathExists(const CanonPath & path)
|
|||
|
||||
std::optional<struct stat> PosixSourceAccessor::cachedLstat(const CanonPath & path)
|
||||
{
|
||||
static SharedSync<std::unordered_map<Path, std::optional<struct stat>>> _cache;
|
||||
using Cache = boost::concurrent_flat_map<Path, std::optional<struct stat>>;
|
||||
static Cache cache;
|
||||
|
||||
// Note: we convert std::filesystem::path to Path because the
|
||||
// former is not hashable on libc++.
|
||||
Path absPath = makeAbsPath(path).string();
|
||||
|
||||
{
|
||||
auto cache(_cache.readLock());
|
||||
auto i = cache->find(absPath);
|
||||
if (i != cache->end())
|
||||
return i->second;
|
||||
}
|
||||
std::optional<Cache::mapped_type> res;
|
||||
cache.cvisit(absPath, [&](auto & x) { res.emplace(x.second); });
|
||||
if (res)
|
||||
return *res;
|
||||
|
||||
auto st = nix::maybeLstat(absPath.c_str());
|
||||
|
||||
auto cache(_cache.lock());
|
||||
if (cache->size() >= 16384)
|
||||
cache->clear();
|
||||
cache->emplace(absPath, st);
|
||||
if (cache.size() >= 16384)
|
||||
cache.clear();
|
||||
cache.emplace(absPath, st);
|
||||
|
||||
return st;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue