refactor
This commit is contained in:
@ -22,12 +22,10 @@
|
|||||||
#ifndef REPERTORY_INCLUDE_DRIVES_DIRECTORY_CACHE_HPP_
|
#ifndef REPERTORY_INCLUDE_DRIVES_DIRECTORY_CACHE_HPP_
|
||||||
#define REPERTORY_INCLUDE_DRIVES_DIRECTORY_CACHE_HPP_
|
#define REPERTORY_INCLUDE_DRIVES_DIRECTORY_CACHE_HPP_
|
||||||
|
|
||||||
#include "utils/single_thread_service_base.hpp"
|
|
||||||
|
|
||||||
namespace repertory {
|
namespace repertory {
|
||||||
class directory_iterator;
|
class directory_iterator;
|
||||||
|
|
||||||
class directory_cache final : public single_thread_service_base {
|
class directory_cache final {
|
||||||
public:
|
public:
|
||||||
using execute_callback = std::function<void(directory_iterator &)>;
|
using execute_callback = std::function<void(directory_iterator &)>;
|
||||||
|
|
||||||
@ -35,13 +33,11 @@ private:
|
|||||||
struct open_directory final {
|
struct open_directory final {
|
||||||
std::shared_ptr<directory_iterator> iterator;
|
std::shared_ptr<directory_iterator> iterator;
|
||||||
std::vector<std::uint64_t> handles;
|
std::vector<std::uint64_t> handles;
|
||||||
std::chrono::system_clock::time_point last_update{
|
|
||||||
std::chrono::system_clock::now()};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
directory_cache() : single_thread_service_base("directory_cache") {}
|
directory_cache() = default;
|
||||||
~directory_cache() override = default;
|
~directory_cache() = default;
|
||||||
|
|
||||||
directory_cache(const directory_cache &) = delete;
|
directory_cache(const directory_cache &) = delete;
|
||||||
directory_cache(directory_cache &&) = delete;
|
directory_cache(directory_cache &&) = delete;
|
||||||
@ -51,17 +47,13 @@ public:
|
|||||||
private:
|
private:
|
||||||
std::unordered_map<std::string, open_directory> directory_lookup_;
|
std::unordered_map<std::string, open_directory> directory_lookup_;
|
||||||
std::recursive_mutex directory_mutex_;
|
std::recursive_mutex directory_mutex_;
|
||||||
std::unique_ptr<std::thread> refresh_thread_;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
void service_function() override;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void execute_action(const std::string &api_path,
|
void execute_action(const std::string &api_path,
|
||||||
const execute_callback &execute);
|
const execute_callback &execute);
|
||||||
|
|
||||||
[[nodiscard]] auto
|
[[nodiscard]] auto get_directory(std::uint64_t handle)
|
||||||
get_directory(std::uint64_t handle) -> std::shared_ptr<directory_iterator>;
|
-> std::shared_ptr<directory_iterator>;
|
||||||
|
|
||||||
auto remove_directory(const std::string &api_path)
|
auto remove_directory(const std::string &api_path)
|
||||||
-> std::shared_ptr<directory_iterator>;
|
-> std::shared_ptr<directory_iterator>;
|
||||||
|
@ -84,33 +84,6 @@ void directory_cache::remove_directory(std::uint64_t handle) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void directory_cache::service_function() {
|
|
||||||
unique_recur_mutex_lock directory_lock(directory_mutex_);
|
|
||||||
auto lookup = directory_lookup_;
|
|
||||||
directory_lock.unlock();
|
|
||||||
|
|
||||||
for (const auto &item : lookup) {
|
|
||||||
if (std::chrono::duration_cast<std::chrono::seconds>(
|
|
||||||
std::chrono::system_clock::now() - item.second.last_update) >=
|
|
||||||
120s) {
|
|
||||||
directory_lock.lock();
|
|
||||||
directory_lookup_.erase(item.first);
|
|
||||||
directory_lock.unlock();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (get_stop_requested()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
unique_mutex_lock shutdown_lock(get_mutex());
|
|
||||||
if (get_stop_requested()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
get_notify().wait_for(shutdown_lock, 15s);
|
|
||||||
}
|
|
||||||
|
|
||||||
void directory_cache::set_directory(
|
void directory_cache::set_directory(
|
||||||
const std::string &api_path, std::uint64_t handle,
|
const std::string &api_path, std::uint64_t handle,
|
||||||
std::shared_ptr<directory_iterator> iterator) {
|
std::shared_ptr<directory_iterator> iterator) {
|
||||||
|
@ -270,10 +270,6 @@ void fuse_drive::stop_all() {
|
|||||||
|
|
||||||
provider_.stop();
|
provider_.stop();
|
||||||
|
|
||||||
if (directory_cache_) {
|
|
||||||
directory_cache_->stop();
|
|
||||||
}
|
|
||||||
|
|
||||||
directory_cache_.reset();
|
directory_cache_.reset();
|
||||||
eviction_.reset();
|
eviction_.reset();
|
||||||
server_.reset();
|
server_.reset();
|
||||||
@ -298,11 +294,11 @@ void fuse_drive::destroy_impl(void *ptr) {
|
|||||||
|
|
||||||
stop_all();
|
stop_all();
|
||||||
|
|
||||||
event_system::instance().raise<drive_unmounted>(get_mount_location());
|
|
||||||
|
|
||||||
config_.save();
|
config_.save();
|
||||||
|
|
||||||
fuse_base::destroy_impl(ptr);
|
fuse_base::destroy_impl(ptr);
|
||||||
|
|
||||||
|
event_system::instance().raise<drive_unmounted>(get_mount_location());
|
||||||
}
|
}
|
||||||
|
|
||||||
auto fuse_drive::fallocate_impl(std::string /*api_path*/, int mode,
|
auto fuse_drive::fallocate_impl(std::string /*api_path*/, int mode,
|
||||||
@ -589,7 +585,6 @@ void *fuse_drive::init_impl(struct fuse_conn_info *conn) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
directory_cache_ = std::make_unique<directory_cache>();
|
directory_cache_ = std::make_unique<directory_cache>();
|
||||||
directory_cache_->start();
|
|
||||||
server_->start();
|
server_->start();
|
||||||
|
|
||||||
if (not provider_.start(
|
if (not provider_.start(
|
||||||
|
Reference in New Issue
Block a user