close all files in background
This commit is contained in:
@@ -86,23 +86,15 @@ file_manager::~file_manager() {
|
||||
}
|
||||
|
||||
void file_manager::close(std::uint64_t handle) {
|
||||
unique_recur_mutex_lock file_lock(open_file_mtx_);
|
||||
recur_mutex_lock file_lock(open_file_mtx_);
|
||||
auto closeable_file = get_open_file_by_handle(handle);
|
||||
if (closeable_file) {
|
||||
closeable_file->remove(handle);
|
||||
|
||||
if (closeable_file->can_close()) {
|
||||
auto api_path = closeable_file->get_api_path();
|
||||
open_file_lookup_.erase(api_path);
|
||||
file_lock.unlock();
|
||||
|
||||
closeable_file->close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void file_manager::close_all(const std::string &api_path) {
|
||||
unique_recur_mutex_lock file_lock(open_file_mtx_);
|
||||
recur_mutex_lock file_lock(open_file_mtx_);
|
||||
std::vector<std::uint64_t> handles;
|
||||
auto iter = open_file_lookup_.find(api_path);
|
||||
if (iter == open_file_lookup_.end()) {
|
||||
@@ -115,11 +107,6 @@ void file_manager::close_all(const std::string &api_path) {
|
||||
for (auto handle : handles) {
|
||||
closeable_file->remove(handle);
|
||||
}
|
||||
|
||||
open_file_lookup_.erase(api_path);
|
||||
file_lock.unlock();
|
||||
|
||||
closeable_file->close();
|
||||
}
|
||||
|
||||
void file_manager::close_timed_out_files() {
|
||||
@@ -141,7 +128,7 @@ void file_manager::close_timed_out_files() {
|
||||
|
||||
for (auto &closeable_file : closeable_list) {
|
||||
closeable_file->close();
|
||||
event_system::instance().raise<download_timeout>(
|
||||
event_system::instance().raise<item_timeout>(
|
||||
closeable_file->get_api_path());
|
||||
}
|
||||
closeable_list.clear();
|
||||
@@ -838,7 +825,7 @@ void file_manager::stop() {
|
||||
while (not upload_lookup_.empty()) {
|
||||
upload_lock.lock();
|
||||
if (not upload_lookup_.empty()) {
|
||||
upload_notify_.wait_for(upload_lock, 1s);
|
||||
upload_notify_.wait_for(upload_lock, 1ms);
|
||||
}
|
||||
upload_notify_.notify_all();
|
||||
upload_lock.unlock();
|
||||
|
Reference in New Issue
Block a user