refactor
This commit is contained in:
parent
a68eb0fadb
commit
8bb179c4dd
@ -40,25 +40,25 @@ public:
|
||||
|
||||
[[nodiscard]] virtual auto get_filesystem_item() const -> filesystem_item = 0;
|
||||
|
||||
[[nodiscard]] virtual auto get_open_data()
|
||||
-> std::map<std::uint64_t, open_file_data> & = 0;
|
||||
[[nodiscard]] virtual auto
|
||||
get_open_data() -> std::map<std::uint64_t, open_file_data> & = 0;
|
||||
|
||||
[[nodiscard]] virtual auto get_open_data() const
|
||||
-> const std::map<std::uint64_t, open_file_data> & = 0;
|
||||
[[nodiscard]] virtual auto
|
||||
get_open_data() const -> const std::map<std::uint64_t, open_file_data> & = 0;
|
||||
|
||||
[[nodiscard]] virtual auto get_open_data(std::uint64_t handle)
|
||||
-> open_file_data & = 0;
|
||||
[[nodiscard]] virtual auto
|
||||
get_open_data(std::uint64_t handle) -> open_file_data & = 0;
|
||||
|
||||
[[nodiscard]] virtual auto get_open_data(std::uint64_t handle) const
|
||||
-> const open_file_data & = 0;
|
||||
[[nodiscard]] virtual auto
|
||||
get_open_data(std::uint64_t handle) const -> const open_file_data & = 0;
|
||||
|
||||
[[nodiscard]] virtual auto get_open_file_count() const -> std::size_t = 0;
|
||||
|
||||
[[nodiscard]] virtual auto get_read_state() const
|
||||
-> boost::dynamic_bitset<> = 0;
|
||||
[[nodiscard]] virtual auto
|
||||
get_read_state() const -> boost::dynamic_bitset<> = 0;
|
||||
|
||||
[[nodiscard]] virtual auto get_read_state(std::size_t chunk) const
|
||||
-> bool = 0;
|
||||
[[nodiscard]] virtual auto
|
||||
get_read_state(std::size_t chunk) const -> bool = 0;
|
||||
|
||||
[[nodiscard]] virtual auto get_source_path() const -> std::string = 0;
|
||||
|
||||
@ -74,11 +74,11 @@ public:
|
||||
native_operation_callback callback) -> api_error = 0;
|
||||
|
||||
[[nodiscard]] virtual auto read(std::size_t read_size,
|
||||
std::uint64_t read_offset, data_buffer &data)
|
||||
-> api_error = 0;
|
||||
std::uint64_t read_offset,
|
||||
data_buffer &data) -> api_error = 0;
|
||||
|
||||
[[nodiscard]] virtual auto resize(std::uint64_t new_file_size)
|
||||
-> api_error = 0;
|
||||
[[nodiscard]] virtual auto
|
||||
resize(std::uint64_t new_file_size) -> api_error = 0;
|
||||
|
||||
virtual void set_api_path(const std::string &api_path) = 0;
|
||||
|
||||
@ -95,10 +95,10 @@ public:
|
||||
|
||||
[[nodiscard]] virtual auto can_close() const -> bool = 0;
|
||||
|
||||
virtual auto close() -> bool = 0;
|
||||
virtual void close() = 0;
|
||||
|
||||
[[nodiscard]] virtual auto get_handles() const
|
||||
-> std::vector<std::uint64_t> = 0;
|
||||
[[nodiscard]] virtual auto
|
||||
get_handles() const -> std::vector<std::uint64_t> = 0;
|
||||
|
||||
[[nodiscard]] virtual auto is_complete() const -> bool = 0;
|
||||
|
||||
|
@ -90,7 +90,7 @@ protected:
|
||||
}
|
||||
|
||||
public:
|
||||
auto close() -> bool override;
|
||||
void close() override;
|
||||
|
||||
[[nodiscard]] auto get_read_state() const -> boost::dynamic_bitset<> override;
|
||||
|
||||
@ -98,14 +98,16 @@ public:
|
||||
|
||||
[[nodiscard]] auto is_complete() const -> bool override;
|
||||
|
||||
[[nodiscard]] auto is_write_supported() const -> bool override { return true; }
|
||||
[[nodiscard]] auto is_write_supported() const -> bool override {
|
||||
return true;
|
||||
}
|
||||
|
||||
[[nodiscard]] auto native_operation(native_operation_callback callback)
|
||||
-> api_error override;
|
||||
[[nodiscard]] auto
|
||||
native_operation(native_operation_callback callback) -> api_error override;
|
||||
|
||||
[[nodiscard]] auto native_operation(std::uint64_t new_file_size,
|
||||
native_operation_callback callback)
|
||||
-> api_error override;
|
||||
[[nodiscard]] auto
|
||||
native_operation(std::uint64_t new_file_size,
|
||||
native_operation_callback callback) -> api_error override;
|
||||
|
||||
void remove(std::uint64_t handle) override;
|
||||
|
||||
|
@ -32,12 +32,13 @@ class i_provider;
|
||||
class open_file_base : public i_closeable_open_file {
|
||||
public:
|
||||
open_file_base(std::uint64_t chunk_size, std::uint8_t chunk_timeout,
|
||||
filesystem_item fsi, i_provider &provider);
|
||||
filesystem_item fsi, i_provider &provider,
|
||||
bool disable_io = false);
|
||||
|
||||
open_file_base(std::uint64_t chunk_size, std::uint8_t chunk_timeout,
|
||||
filesystem_item fsi,
|
||||
std::map<std::uint64_t, open_file_data> open_data,
|
||||
i_provider &provider);
|
||||
i_provider &provider, bool disable_io = false);
|
||||
|
||||
~open_file_base() override = default;
|
||||
|
||||
@ -141,7 +142,7 @@ public:
|
||||
|
||||
[[nodiscard]] auto can_close() const -> bool override;
|
||||
|
||||
auto close() -> bool override;
|
||||
void close() override;
|
||||
|
||||
[[nodiscard]] auto get_api_error() const -> api_error;
|
||||
|
||||
|
@ -30,7 +30,7 @@ namespace repertory {
|
||||
direct_open_file::direct_open_file(std::uint64_t chunk_size,
|
||||
std::uint8_t chunk_timeout,
|
||||
filesystem_item fsi, i_provider &provider)
|
||||
: open_file_base(chunk_size, chunk_timeout, fsi, provider),
|
||||
: open_file_base(chunk_size, chunk_timeout, fsi, provider, true),
|
||||
total_chunks_(static_cast<std::size_t>(
|
||||
utils::divide_with_ceiling(fsi.size, chunk_size))) {}
|
||||
|
||||
|
@ -67,12 +67,14 @@ auto open_file_base::io_item::get_result() -> api_error {
|
||||
|
||||
open_file_base::open_file_base(std::uint64_t chunk_size,
|
||||
std::uint8_t chunk_timeout, filesystem_item fsi,
|
||||
i_provider &provider)
|
||||
: open_file_base(chunk_size, chunk_timeout, fsi, {}, provider) {}
|
||||
i_provider &provider, bool disable_io)
|
||||
: open_file_base(chunk_size, chunk_timeout, fsi, {}, provider, disable_io) {
|
||||
}
|
||||
|
||||
open_file_base::open_file_base(
|
||||
std::uint64_t chunk_size, std::uint8_t chunk_timeout, filesystem_item fsi,
|
||||
std::map<std::uint64_t, open_file_data> open_data, i_provider &provider)
|
||||
std::map<std::uint64_t, open_file_data> open_data, i_provider &provider,
|
||||
bool disable_io)
|
||||
: chunk_size_(chunk_size),
|
||||
chunk_timeout_(chunk_timeout),
|
||||
fsi_(std::move(fsi)),
|
||||
@ -82,7 +84,7 @@ open_file_base::open_file_base(
|
||||
: fsi.size % chunk_size)),
|
||||
open_data_(std::move(open_data)),
|
||||
provider_(provider) {
|
||||
if (not fsi.directory) {
|
||||
if (not fsi.directory && not disable_io) {
|
||||
io_thread_ = std::make_unique<std::thread>([this] { file_io_thread(); });
|
||||
}
|
||||
}
|
||||
@ -295,24 +297,19 @@ void open_file_base::set_api_path(const std::string &api_path) {
|
||||
fsi_.api_parent = utils::path::get_parent_api_path(api_path);
|
||||
}
|
||||
|
||||
auto open_file_base::close() -> bool {
|
||||
void open_file_base::close() {
|
||||
unique_mutex_lock io_lock(io_thread_mtx_);
|
||||
if (not fsi_.directory && not io_stop_requested_) {
|
||||
io_stop_requested_ = true;
|
||||
if (io_stop_requested_ || not io_thread_) {
|
||||
io_thread_notify_.notify_all();
|
||||
io_lock.unlock();
|
||||
|
||||
if (io_thread_) {
|
||||
io_thread_->join();
|
||||
io_thread_.reset();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
|
||||
io_stop_requested_ = true;
|
||||
io_thread_notify_.notify_all();
|
||||
io_lock.unlock();
|
||||
return false;
|
||||
|
||||
io_thread_->join();
|
||||
io_thread_.reset();
|
||||
}
|
||||
} // namespace repertory
|
||||
|
Loading…
x
Reference in New Issue
Block a user