diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2021-01-02 15:34:55 +0000 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2021-01-02 15:34:55 +0000 |
commit | dd5f6afa332fb95b936899159206a480a2724026 (patch) | |
tree | f6ae1282de35b106ddf5a32e3a19ab2b2c86b3bf | |
parent | Minor code tidy (diff) | |
download | netfs-dd5f6afa332fb95b936899159206a480a2724026.tar.bz2 netfs-dd5f6afa332fb95b936899159206a480a2724026.tar.xz netfs-dd5f6afa332fb95b936899159206a480a2724026.zip |
Fix EntCache locking
Scope for improvements in getEntry regarding multiple threads calling fillCache
-rw-r--r-- | netfs/lib/entCache.impl.h | 17 | ||||
-rw-r--r-- | netfs/unittests/testLib.cpp | 1 |
2 files changed, 9 insertions, 9 deletions
diff --git a/netfs/lib/entCache.impl.h b/netfs/lib/entCache.impl.h index 13263af..37aecfd 100644 --- a/netfs/lib/entCache.impl.h +++ b/netfs/lib/entCache.impl.h @@ -57,15 +57,19 @@ template<class key_t> typename EntCache<entry_t>::Resolution EntCache<entry_t>::getEntry(const key_t & key) const { - if (fillTime + 60 > time(nullptr)) { + SharedScopeLock(lock) { + if (fillTime + 60 > time(nullptr)) { + if (auto ent = getEntryNoFill<key_t>(key)) { + return ent; + } + } + } + ScopeLock(lock) { + fillCache(); if (auto ent = getEntryNoFill<key_t>(key)) { return ent; } } - fillCache(); - if (auto ent = getEntryNoFill<key_t>(key)) { - return ent; - } if (fallback) { return {fallback, ResolvedAs::Fallback}; } @@ -77,7 +81,6 @@ template<class key_t> typename EntCache<entry_t>::entry_ptr EntCache<entry_t>::getEntryNoFill(const key_t & key) const { - SharedLock(lock); auto & collection = idcache->template get<key_t>(); auto i = collection.find(key); if (i != collection.end()) { @@ -106,7 +109,6 @@ template<> void EntCache<User>::fillCache() const { - Lock(lock); setpwent(); idcache->clear(); std::array<char, BUFSIZ> buf {}; @@ -124,7 +126,6 @@ template<> void EntCache<Group>::fillCache() const { - Lock(lock); setgrent(); std::array<char, BUFSIZ> buf {}; idcache->clear(); diff --git a/netfs/unittests/testLib.cpp b/netfs/unittests/testLib.cpp index d3ce2fe..ff82040 100644 --- a/netfs/unittests/testLib.cpp +++ b/netfs/unittests/testLib.cpp @@ -27,7 +27,6 @@ template<> void EntCache<TestEntry>::fillCache() const { - Lock(lock); idcache->insert(std::make_shared<TestEntry>(1, "user1")); idcache->insert(std::make_shared<TestEntry>(2, "user2")); idcache->insert(std::make_shared<TestEntry>(3, "user3")); |