aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/AsyncImageLoader.hpp33
-rw-r--r--include/MessageQueue.hpp4
2 files changed, 25 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;
diff --git a/include/MessageQueue.hpp b/include/MessageQueue.hpp
index 286739d..ba28431 100644
--- a/include/MessageQueue.hpp
+++ b/include/MessageQueue.hpp
@@ -68,6 +68,10 @@ namespace QuickMedia {
++it;
}
}
+
+ bool is_running() const {
+ return running;
+ }
private:
std::deque<T> data_queue;
std::mutex mutex;