Asynchronous GeometryTile deletion (#2051)

Co-authored-by: Tim Sylvester <tim@wetdogweather.com>
This commit is contained in:
mwilsnd
2024-02-28 17:18:08 -05:00
committed by GitHub
parent e3cbdb63a8
commit 4fff8a5d33
80 changed files with 1180 additions and 334 deletions

View File

@@ -1,5 +1,6 @@
#include "scheduler.hpp"
#include <mbgl/util/monotonic_timer.hpp>
#include <mbgl/util/util.hpp>
#include <cassert>
@@ -12,7 +13,7 @@ Scheduler::~Scheduler() {
MBGL_VERIFY_THREAD(tid);
}
void Scheduler::schedule(std::function<void()> function) {
void Scheduler::schedule(std::function<void()>&& function) {
const std::lock_guard<std::mutex> lock(m_taskQueueMutex);
m_taskQueue.push(std::move(function));
@@ -26,6 +27,7 @@ void Scheduler::processEvents() {
{
const std::unique_lock<std::mutex> lock(m_taskQueueMutex);
std::swap(taskQueue, m_taskQueue);
pendingItems += taskQueue.size();
}
while (!taskQueue.empty()) {
@@ -34,7 +36,29 @@ void Scheduler::processEvents() {
function();
}
taskQueue.pop();
pendingItems--;
}
cvEmpty.notify_all();
}
std::size_t Scheduler::waitForEmpty(std::chrono::milliseconds timeout) {
MBGL_VERIFY_THREAD(tid);
const auto startTime = mbgl::util::MonotonicTimer::now();
std::unique_lock<std::mutex> lock(m_taskQueueMutex);
const auto isDone = [&] {
return m_taskQueue.empty() && pendingItems == 0;
};
while (!isDone()) {
const auto elapsed = mbgl::util::MonotonicTimer::now() - startTime;
if (timeout <= elapsed || !cvEmpty.wait_for(lock, timeout - elapsed, isDone)) {
assert(isDone());
break;
}
}
return m_taskQueue.size() + pendingItems;
}
} // namespace QMapLibre