Fix: libcurl HTTP thread race at uninit preventing thread exit

This commit is contained in:
Jonathan G Rennison
2024-01-04 01:02:22 +00:00
committed by Patric Stout
parent c6dafb0865
commit 51ef416b49
2 changed files with 28 additions and 5 deletions

View File

@@ -75,13 +75,15 @@ public:
}
/**
* Wait till the queue is dequeued.
* Wait till the queue is dequeued, or a condition is met.
* @param condition Condition functor.
*/
void WaitTillEmpty()
template <typename T>
void WaitTillEmptyOrCondition(T condition)
{
std::unique_lock<std::mutex> lock(this->mutex);
while (!queue.empty()) {
while (!(queue.empty() || condition())) {
this->queue_cv.wait(lock);
}
}
@@ -95,6 +97,20 @@ public:
return this->queue.empty();
}
/**
* Clear everything in the queue.
*
* Should be called from the Game Thread.
*/
void ClearQueue()
{
std::lock_guard<std::mutex> lock(this->mutex);
this->queue.clear();
this->queue_cv.notify_all();
}
HTTPThreadSafeCallback(HTTPCallback *callback) : callback(callback) {}
~HTTPThreadSafeCallback()