Skip to content

Commit

Permalink
Make the HTTP upload queue an actual std::queue (instead of std::vector)
Browse files Browse the repository at this point in the history
  • Loading branch information
EpicUsername12 committed Mar 26, 2024
1 parent 52fe504 commit 84d6125
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions source/utils/http.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
static std::atomic<bool> is_http_initialized = false;

static std::mutex uploadQueueAccessMutex;
static std::vector<UploadQueueEntry> uploadQueue;
static std::queue<UploadQueueEntry> uploadQueue;

static float currentUploadProgress = 0.0f;

Expand Down Expand Up @@ -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();

}
}

Expand All @@ -99,7 +97,7 @@ float http_getCurrentProgress() {
void http_submitUploadQueue(const std::string& url, const std::vector<uint8_t>& 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();
}

Expand Down

0 comments on commit 84d6125

Please sign in to comment.