summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--netfs/lib/entCache.cpp39
-rw-r--r--netfs/lib/entCache.h16
2 files changed, 39 insertions, 16 deletions
diff --git a/netfs/lib/entCache.cpp b/netfs/lib/entCache.cpp
index 6af0e24..9b78dff 100644
--- a/netfs/lib/entCache.cpp
+++ b/netfs/lib/entCache.cpp
@@ -3,6 +3,35 @@
#include <lockHelpers.h>
#include <pwd.h>
#include <grp.h>
+#include <type_traits>
+#include <boost/multi_index_container.hpp>
+#include <boost/multi_index/member.hpp>
+#include <boost/multi_index/ordered_index.hpp>
+
+static_assert(std::is_nothrow_move_constructible_v<User>);
+static_assert(std::is_nothrow_move_assignable_v<User>);
+static_assert(std::is_nothrow_move_constructible_v<Group>);
+static_assert(std::is_nothrow_move_assignable_v<Group>);
+
+
+template<class entry_t>
+class EntCache<entry_t>::Ids : public boost::multi_index::multi_index_container<std::shared_ptr<entry_t>,
+ boost::multi_index::indexed_by<
+ boost::multi_index::ordered_unique<
+ boost::multi_index::tag<id_t>, BOOST_MULTI_INDEX_MEMBER(entry_t, const id_t, id), std::less<>>,
+ boost::multi_index::ordered_unique<
+ boost::multi_index::tag<std::string>, BOOST_MULTI_INDEX_MEMBER(entry_t, const std::string, name), std::less<>>
+ > > {
+ };
+
+template<class entry_t>
+EntCache<entry_t>::EntCache() :
+ idcache(std::make_unique<Ids>())
+{
+}
+
+template<class entry_t>
+EntCache<entry_t>::~EntCache() = default;
template<class entry_t>
void
@@ -45,7 +74,7 @@ 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 & collection = idcache->template get<key_t>();
auto i = collection.find(key);
if (i != collection.end()) {
return *i;
@@ -68,11 +97,11 @@ EntCache<User>::fillCache() const
{
Lock(lock);
setpwent();
- idcache.clear();
+ idcache->clear();
std::array<char, BUFLEN> buf {};
struct passwd pwbuf {}, * pwp;
while (getpwent_r(&pwbuf, buf.data(), buf.size(), &pwp) == 0) {
- idcache.insert(std::make_shared<User>(pwp->pw_uid, pwp->pw_name, pwp->pw_gid));
+ idcache->insert(std::make_shared<User>(pwp->pw_uid, pwp->pw_name, pwp->pw_gid));
}
endpwent();
time(&fillTime);
@@ -91,7 +120,7 @@ EntCache<Group>::fillCache() const
Lock(lock);
setgrent();
std::array<char, BUFLEN> buf {};
- idcache.clear();
+ idcache->clear();
struct group grpbuf {}, * grp;
EntCache<User> instance;
while (getgrent_r(&grpbuf, buf.data(), buf.size(), &grp) == 0) {
@@ -103,7 +132,7 @@ EntCache<Group>::fillCache() const
catch (const NetFS::SystemError &) {
}
}
- idcache.insert(g);
+ idcache->insert(std::move(g));
}
endgrent();
time(&fillTime);
diff --git a/netfs/lib/entCache.h b/netfs/lib/entCache.h
index 2833141..73cd36d 100644
--- a/netfs/lib/entCache.h
+++ b/netfs/lib/entCache.h
@@ -3,9 +3,6 @@
#include <string>
#include <set>
-#include <boost/multi_index_container.hpp>
-#include <boost/multi_index/member.hpp>
-#include <boost/multi_index/ordered_index.hpp>
#include <shared_mutex>
#include <entryResolver.h>
@@ -31,6 +28,9 @@ class Group {
template<class entry_t>
class EntCache : public EntryResolver<decltype(entry_t::id)> {
public:
+ EntCache();
+ ~EntCache() override;
+
using id_t = decltype(entry_t::id);
using name_t = decltype(entry_t::name);
using entry_ptr = std::shared_ptr<entry_t>;
@@ -45,14 +45,8 @@ class EntCache : public EntryResolver<decltype(entry_t::id)> {
template<class key_t>
entry_ptr getEntryNoFill(const key_t &) const;
- using IDs = boost::multi_index::multi_index_container<std::shared_ptr<entry_t>,
- boost::multi_index::indexed_by<
- boost::multi_index::ordered_unique<
- boost::multi_index::tag<id_t>, BOOST_MULTI_INDEX_MEMBER(entry_t, const id_t, id), std::less<>>,
- boost::multi_index::ordered_unique<
- boost::multi_index::tag<std::string>, BOOST_MULTI_INDEX_MEMBER(entry_t, const std::string, name), std::less<>>
- > >;
- mutable IDs idcache;
+ class Ids;
+ std::unique_ptr<Ids> idcache;
mutable std::shared_mutex lock;
mutable time_t fillTime {0};
};