aboutsummaryrefslogtreecommitdiff
path: root/include/AsyncImageLoader.hpp
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2021-10-14 16:59:27 +0200
committerdec05eba <dec05eba@protonmail.com>2021-10-14 16:59:27 +0200
commite1c8cd4430015a307dbcb32894a030d5a13aee67 (patch)
treee467cf115657f1cbf58f81aef96b5a6b67f11538 /include/AsyncImageLoader.hpp
parenta2a49eee1985ec13e52e477060a50da2fcbdb894 (diff)
Remove async image loader threads and instead check if the curl download process has finished
Diffstat (limited to 'include/AsyncImageLoader.hpp')
-rw-r--r--include/AsyncImageLoader.hpp33
1 files changed, 21 insertions, 12 deletions
diff --git a/include/AsyncImageLoader.hpp b/include/AsyncImageLoader.hpp
index 6258b02..77fd5b4 100644
--- a/include/AsyncImageLoader.hpp
+++ b/include/AsyncImageLoader.hpp
@@ -26,11 +26,19 @@ namespace QuickMedia {
size_t counter = 0;
};
+ struct ThumbnailLoadData {
+ Path path;
+ Path thumbnail_path;
+ bool local;
+ std::shared_ptr<ThumbnailData> thumbnail_data;
+ sf::Vector2i resize_target_size;
+ };
+
// If |symlink_if_no_resize| is false then a copy is made from |thumbnail_path| to |thumbnail_path_resized| instead of a symlink if |thumbnail_path| is not larger than |resize_target_size|.
// One example of why you might not want a symlink is if |thumbnail_path| is a temporary file.
bool create_thumbnail(const Path &thumbnail_path, const Path &thumbnail_path_resized, sf::Vector2i resize_target_size, ContentType content_type, bool symlink_if_no_resize);
- constexpr int NUM_IMAGE_LOAD_THREADS = 4;
+ constexpr int NUM_IMAGE_LOAD_PARALLEL = 4;
class AsyncImageLoader {
public:
@@ -51,14 +59,6 @@ namespace QuickMedia {
AsyncImageLoader(AsyncImageLoader &other) = delete;
AsyncImageLoader& operator=(AsyncImageLoader &other) = delete;
- struct ThumbnailLoadData {
- Path path;
- Path thumbnail_path;
- bool local;
- std::shared_ptr<ThumbnailData> thumbnail_data;
- sf::Vector2i resize_target_size;
- };
-
// set |resize_target_size| to {0, 0} to disable resizing.
// Note: this method is not thread-safe
void load_thumbnail(const std::string &url, bool local, sf::Vector2i resize_target_size, std::shared_ptr<ThumbnailData> thumbnail_data);
@@ -66,10 +66,19 @@ namespace QuickMedia {
// Returns -1 if all threads are busy
int get_free_load_index() const;
private:
- bool loading_image[NUM_IMAGE_LOAD_THREADS];
+ struct Download {
+ ReadProgram read_program;
+ int64_t download_start = 0;
+ Path thumbnail_path;
+ std::shared_ptr<ThumbnailData> thumbnail_data;
+ sf::Vector2i resize_target_size;
+ std::string url;
+ };
+
+ std::mutex download_mutex;
// TODO: Use curl single-threaded multi-download feature instead
- AsyncTask<void> download_image_thread[NUM_IMAGE_LOAD_THREADS];
- AsyncTask<void> load_image_thread;
+ Download downloads[NUM_IMAGE_LOAD_PARALLEL];
+ AsyncTask<void> load_thread;
MessageQueue<ThumbnailLoadData> image_load_queue;
std::unordered_map<std::string, std::shared_ptr<ThumbnailData>> thumbnails;
size_t counter = 0;