From f8beae4a1d07673af16130f7ca2480704d72d947 Mon Sep 17 00:00:00 2001 From: J-D-K Date: Thu, 11 Sep 2025 20:01:51 -0400 Subject: [PATCH] zip.cpp: threadpooled. --- source/fs/zip.cpp | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/source/fs/zip.cpp b/source/fs/zip.cpp index 5afabf8..f70c312 100644 --- a/source/fs/zip.cpp +++ b/source/fs/zip.cpp @@ -79,13 +79,16 @@ static void zip_read_thread_function(sys::threadpool::JobData jobData) } // Function for reading data from Zip to buffer. -static void unzipReadThreadFunction(fs::MiniUnzip &unzip, std::shared_ptr sharedData) +static void unzip_read_thread_function(sys::threadpool::JobData jobData) { - std::mutex &lock = sharedData->lock; - std::condition_variable &condition = sharedData->condition; - ssize_t &readSize = sharedData->readSize; - bool &bufferReady = sharedData->bufferReady; - std::unique_ptr &sharedBuffer = sharedData->sharedBuffer; + auto castData = std::static_pointer_cast(jobData); + + std::mutex &lock = castData->lock; + std::condition_variable &condition = castData->condition; + ssize_t &readSize = castData->readSize; + bool &bufferReady = castData->bufferReady; + std::unique_ptr &sharedBuffer = castData->sharedBuffer; + fs::MiniUnzip &unzip = *castData->unzip; const int64_t fileSize = unzip.get_uncompressed_size(); for (int64_t i = 0; i < fileSize;) @@ -221,7 +224,9 @@ void fs::copy_zip_to_directory(fs::MiniUnzip &unzip, const fslib::Path &dest, in auto sharedData = std::make_shared(); sharedData->sharedBuffer = std::make_unique(SIZE_UNZIP_BUFFER); - auto localBuffer = std::make_unique(SIZE_UNZIP_BUFFER); + sharedData->unzip = &unzip; + + auto localBuffer = std::make_unique(SIZE_UNZIP_BUFFER); std::mutex &lock = sharedData->lock; std::condition_variable &condition = sharedData->condition; @@ -230,7 +235,7 @@ void fs::copy_zip_to_directory(fs::MiniUnzip &unzip, const fslib::Path &dest, in std::unique_ptr &sharedBuffer = sharedData->sharedBuffer; int64_t journalCount{}; - std::thread readThread(unzipReadThreadFunction, std::ref(unzip), sharedData); + sys::threadpool::push_job(unzip_read_thread_function, sharedData); for (int64_t i = 0; i < fileSize;) { ssize_t localRead{}; @@ -263,7 +268,6 @@ void fs::copy_zip_to_directory(fs::MiniUnzip &unzip, const fslib::Path &dest, in journalCount += localRead; if (task) { task->update_current(static_cast(i)); } } - readThread.join(); destFile.close(); const bool commitError = needCommits && error::fslib(fslib::commit_data_to_file_system(dest.get_device_name()));