diff --git a/src/bees-context.cc b/src/bees-context.cc index 7d53893..b15cc1f 100644 --- a/src/bees-context.cc +++ b/src/bees-context.cc @@ -21,18 +21,19 @@ using namespace crucible; using namespace std; -BeesFdCache::BeesFdCache() +BeesFdCache::BeesFdCache(shared_ptr ctx) : + m_ctx(ctx) { - m_root_cache.func([&](shared_ptr ctx, uint64_t root) -> Fd { + m_root_cache.func([&](uint64_t root) -> Fd { Timer open_timer; - auto rv = ctx->roots()->open_root_nocache(root); + auto rv = m_ctx->roots()->open_root_nocache(root); BEESCOUNTADD(open_root_ms, open_timer.age() * 1000); return rv; }); m_root_cache.max_size(BEES_ROOT_FD_CACHE_SIZE); - m_file_cache.func([&](shared_ptr ctx, uint64_t root, uint64_t ino) -> Fd { + m_file_cache.func([&](uint64_t root, uint64_t ino) -> Fd { Timer open_timer; - auto rv = ctx->roots()->open_root_ino_nocache(root, ino); + auto rv = m_ctx->roots()->open_root_ino_nocache(root, ino); BEESCOUNTADD(open_ino_ms, open_timer.age() * 1000); return rv; }); @@ -51,15 +52,15 @@ BeesFdCache::clear() } Fd -BeesFdCache::open_root(shared_ptr ctx, uint64_t root) +BeesFdCache::open_root(uint64_t root) { - return m_root_cache(ctx, root); + return m_root_cache(root); } Fd -BeesFdCache::open_root_ino(shared_ptr ctx, uint64_t root, uint64_t ino) +BeesFdCache::open_root_ino(uint64_t root, uint64_t ino) { - return m_file_cache(ctx, root, ino); + return m_file_cache(root, ino); } void @@ -1107,7 +1108,7 @@ BeesContext::fd_cache() throw BeesHalt(); } if (!m_fd_cache) { - m_fd_cache = make_shared(); + m_fd_cache = make_shared(shared_from_this()); } auto rv = m_fd_cache; return rv; diff --git a/src/bees-roots.cc b/src/bees-roots.cc index f183b42..92c6a1c 100644 --- a/src/bees-roots.cc +++ b/src/bees-roots.cc @@ -709,7 +709,7 @@ BeesRoots::open_root(uint64_t rootid) return Fd(); } - return m_ctx->fd_cache()->open_root(m_ctx, rootid); + return m_ctx->fd_cache()->open_root(rootid); } bool @@ -906,7 +906,7 @@ BeesRoots::open_root_ino_nocache(uint64_t root, uint64_t ino) Fd BeesRoots::open_root_ino(uint64_t root, uint64_t ino) { - return m_ctx->fd_cache()->open_root_ino(m_ctx, root, ino); + return m_ctx->fd_cache()->open_root_ino(root, ino); } RateEstimator & diff --git a/src/bees.h b/src/bees.h index 699c78c..4ebb9b7 100644 --- a/src/bees.h +++ b/src/bees.h @@ -697,15 +697,16 @@ public: }; class BeesFdCache { - LRUCache, uint64_t> m_root_cache; - LRUCache, uint64_t, uint64_t> m_file_cache; - Timer m_root_cache_timer; - Timer m_file_cache_timer; + shared_ptr m_ctx; + LRUCache m_root_cache; + LRUCache m_file_cache; + Timer m_root_cache_timer; + Timer m_file_cache_timer; public: - BeesFdCache(); - Fd open_root(shared_ptr ctx, uint64_t root); - Fd open_root_ino(shared_ptr ctx, uint64_t root, uint64_t ino); + BeesFdCache(shared_ptr ctx); + Fd open_root(uint64_t root); + Fd open_root_ino(uint64_t root, uint64_t ino); void clear(); };