aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2021-11-19 03:05:52 +0100
committerdec05eba <dec05eba@protonmail.com>2021-11-19 03:05:52 +0100
commit633ccf9c8d1f32b2f3a312f0e95e4ed6fbd33dd8 (patch)
tree679577d83d6c50c9e40663e43f71e0d1cdedae30
parent7f538cf8187ca8107696ec22406aef1d44fe04e3 (diff)
Revert back to loading thumbnails with multiple threads instead of loading thumbnails after requested in render loop
-rw-r--r--include/AsyncImageLoader.hpp3
-rw-r--r--src/AsyncImageLoader.cpp34
2 files changed, 4 insertions, 33 deletions
diff --git a/include/AsyncImageLoader.hpp b/include/AsyncImageLoader.hpp
index 856e9cc..23c2889 100644
--- a/include/AsyncImageLoader.hpp
+++ b/include/AsyncImageLoader.hpp
@@ -90,8 +90,5 @@ namespace QuickMedia {
MessageQueue<ThumbnailLoadData> image_thumbnail_create_queue;
std::unordered_map<std::string, std::shared_ptr<ThumbnailData>> thumbnails;
size_t counter = 0;
-
- std::mutex image_load_mutex;
- ThumbnailLoadData current_loading_image;
};
}
diff --git a/src/AsyncImageLoader.cpp b/src/AsyncImageLoader.cpp
index c1d4aab..b9bcd30 100644
--- a/src/AsyncImageLoader.cpp
+++ b/src/AsyncImageLoader.cpp
@@ -253,23 +253,11 @@ namespace QuickMedia {
load_thread = AsyncTask<void>([this]() mutable {
std::optional<ThumbnailLoadData> thumbnail_load_data_opt;
while(image_thumbnail_create_queue.is_running()) {
- ThumbnailLoadData load_image_data;
- {
- std::lock_guard<std::mutex> lock(image_load_mutex);
- if(current_loading_image.thumbnail_data) {
- load_image_data = std::move(current_loading_image);
- current_loading_image = ThumbnailLoadData();
- }
- }
-
- if(load_image_data.thumbnail_data) {
- load_processed_thumbnail(load_image_data);
- load_image_data = ThumbnailLoadData();
- }
-
thumbnail_load_data_opt = image_thumbnail_create_queue.pop_if_available();
if(thumbnail_load_data_opt) {
process_thumbnail(thumbnail_load_data_opt.value());
+ if(thumbnail_load_data_opt.value().thumbnail_data->loading_state == LoadingState::READY_TO_LOAD)
+ load_processed_thumbnail(thumbnail_load_data_opt.value());
thumbnail_load_data_opt = std::nullopt;
}
@@ -285,7 +273,7 @@ namespace QuickMedia {
if(status == 0 && rename_atomic(tmp_thumbnail_path.data.c_str(), download.thumbnail_path.data.c_str()) == 0) {
fprintf(stderr, "Download duration for %s: %ld ms\n", download.url.c_str(), get_boottime_milliseconds() - download.download_start);
ThumbnailLoadData load_data = { std::move(download.url), std::move(download.thumbnail_path), false, download.thumbnail_data, download.resize_target_size };
- process_thumbnail(load_data);
+ image_thumbnail_create_queue.push(std::move(load_data));
} else {
fprintf(stderr, "Thumbnail download failed for %s\n", download.url.c_str());
}
@@ -379,15 +367,7 @@ namespace QuickMedia {
thumbnail_data->thumbnail_path = get_cache_dir().join("thumbnails").join(sha256.getHash());
}
- if(!load_thumbnail(url, local, resize_target_size, thumbnail_data, thumbnail_data->thumbnail_path))
- return thumbnail_data;
-
- if(thumbnail_data->loading_state == LoadingState::READY_TO_LOAD) {
- std::lock_guard<std::mutex> lock(image_load_mutex);
- if(!current_loading_image.thumbnail_data)
- current_loading_image = { url, thumbnail_data->thumbnail_path, local, thumbnail_data, resize_target_size };
- }
-
+ load_thumbnail(url, local, resize_target_size, thumbnail_data, thumbnail_data->thumbnail_path);
return thumbnail_data;
}
@@ -412,12 +392,6 @@ namespace QuickMedia {
return load_data.path.data == it->first;
});
- {
- std::lock_guard<std::mutex> lock(image_load_mutex);
- if(current_loading_image.thumbnail_data == it->second)
- current_loading_image = ThumbnailLoadData();
- }
-
it = thumbnails.erase(it);
loaded_textures_changed = true;
} else {