From 84d612535193710bba807dd0031cb0170af7b397 Mon Sep 17 00:00:00 2001 From: Rambo6Glaz <39063367+EpicUsername12@users.noreply.github.com> Date: Tue, 26 Mar 2024 16:21:43 +0100 Subject: [PATCH] Make the HTTP upload queue an actual std::queue (instead of std::vector) --- source/utils/http.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/source/utils/http.cpp b/source/utils/http.cpp index df7ac24..e42a383 100644 --- a/source/utils/http.cpp +++ b/source/utils/http.cpp @@ -3,7 +3,7 @@ static std::atomic is_http_initialized = false; static std::mutex uploadQueueAccessMutex; -static std::vector uploadQueue; +static std::queue uploadQueue; static float currentUploadProgress = 0.0f; @@ -77,17 +77,15 @@ void http_uploadQueueWorker() { continue; } - UploadQueueEntry& entry = uploadQueue.at(0); + UploadQueueEntry entry = uploadQueue.front(); + uploadQueue.pop(); + uploadQueueAccessMutex.unlock(); WHBLogPrintf("Uploading %lu bytes to %s", entry.data.size(), entry.url.c_str()); http_handleUpload(entry); entry.callback(entry, currentUploadProgress); - uploadQueueAccessMutex.lock(); - uploadQueue.erase(uploadQueue.begin()); - uploadQueueAccessMutex.unlock(); - } } @@ -99,7 +97,7 @@ float http_getCurrentProgress() { void http_submitUploadQueue(const std::string& url, const std::vector& data, UploadQueueCallback updateCallback, void* userdata) { uploadQueueAccessMutex.lock(); UploadQueueEntry entry { .curl = nullptr, .url = url, .data = data, .started = false, .finished = false, .error = false, .callback = updateCallback, .userdata = userdata}; - uploadQueue.push_back(entry); + uploadQueue.push(entry); uploadQueueAccessMutex.unlock(); }