aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2022-02-18 17:59:28 +0100
committerdec05eba <dec05eba@protonmail.com>2022-02-18 17:59:28 +0100
commitcfb6238ad7fe7dd7d2eca64676437bb871802375 (patch)
treed3b88c246301197654b6f60b9dcc62d25b0039f2 /include
parent08d6c26b6fc06bd7fc80bc168131998f95c12551 (diff)
Faster image loading/thumbnail creation by using multiple threads
Diffstat (limited to 'include')
-rw-r--r--include/AsyncImageLoader.hpp5
-rw-r--r--include/AsyncTask.hpp4
2 files changed, 5 insertions, 4 deletions
diff --git a/include/AsyncImageLoader.hpp b/include/AsyncImageLoader.hpp
index 23c2889..c482a3a 100644
--- a/include/AsyncImageLoader.hpp
+++ b/include/AsyncImageLoader.hpp
@@ -41,6 +41,7 @@ namespace QuickMedia {
// 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, mgl::vec2i resize_target_size, ContentType content_type, bool symlink_if_no_resize);
+ constexpr int NUM_IMAGE_DOWNLOAD_PARALLEL = 4;
constexpr int NUM_IMAGE_LOAD_PARALLEL = 4;
class AsyncImageLoader {
@@ -85,8 +86,8 @@ namespace QuickMedia {
private:
std::mutex download_mutex;
// TODO: Use curl single-threaded multi-download feature instead
- Download downloads[NUM_IMAGE_LOAD_PARALLEL];
- AsyncTask<void> load_thread;
+ Download downloads[NUM_IMAGE_DOWNLOAD_PARALLEL];
+ AsyncTask<void> load_threads[NUM_IMAGE_LOAD_PARALLEL];
MessageQueue<ThumbnailLoadData> image_thumbnail_create_queue;
std::unordered_map<std::string, std::shared_ptr<ThumbnailData>> thumbnails;
size_t counter = 0;
diff --git a/include/AsyncTask.hpp b/include/AsyncTask.hpp
index e256dc7..358e06a 100644
--- a/include/AsyncTask.hpp
+++ b/include/AsyncTask.hpp
@@ -20,14 +20,14 @@ namespace QuickMedia {
thread = std::thread(&AsyncTask::thread_handler, this, std::move(promise), std::move(callback_func), std::forward<Args>(args)...);
}
- AsyncTask(AsyncTask &&other) {
+ AsyncTask(AsyncTask &&other) noexcept {
cancel();
std::lock_guard<std::mutex> lock(mutex);
thread = std::move(other.thread);
future = std::move(other.future);
}
- AsyncTask& operator=(AsyncTask &&other) {
+ AsyncTask& operator=(AsyncTask &&other) noexcept {
cancel();
std::lock_guard<std::mutex> lock(mutex);
thread = std::move(other.thread);