Asynchronous GeometryTile deletion (#2051)
Co-authored-by: Tim Sylvester <tim@wetdogweather.com>
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
#include "run_loop_impl.hpp"
|
||||
|
||||
#include <mbgl/util/platform.hpp>
|
||||
#include <mbgl/util/thread_local.hpp>
|
||||
#include <mbgl/util/thread.hpp>
|
||||
#include <mbgl/util/timer.hpp>
|
||||
#include <mbgl/actor/scheduler.hpp>
|
||||
#include <mbgl/util/event.hpp>
|
||||
#include <mbgl/util/logging.hpp>
|
||||
#include <mbgl/util/monotonic_timer.hpp>
|
||||
#include <mbgl/util/platform.hpp>
|
||||
#include <mbgl/util/thread.hpp>
|
||||
#include <mbgl/util/thread_local.hpp>
|
||||
#include <mbgl/util/timer.hpp>
|
||||
|
||||
#include <android/looper.h>
|
||||
|
||||
@@ -18,7 +20,6 @@
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <mbgl/util/logging.hpp>
|
||||
|
||||
#define PIPE_OUT 0
|
||||
#define PIPE_IN 1
|
||||
@@ -167,6 +168,9 @@ void RunLoop::Impl::addRunnable(Runnable* runnable) {
|
||||
void RunLoop::Impl::removeRunnable(Runnable* runnable) {
|
||||
std::lock_guard<std::mutex> lock(mutex);
|
||||
runnables.remove(runnable);
|
||||
if (runnables.empty()) {
|
||||
cvEmpty.notify_all();
|
||||
}
|
||||
}
|
||||
|
||||
Milliseconds RunLoop::Impl::processRunnables() {
|
||||
@@ -196,6 +200,10 @@ Milliseconds RunLoop::Impl::processRunnables() {
|
||||
runnable->runTask();
|
||||
}
|
||||
|
||||
if (runnables.empty()) {
|
||||
cvEmpty.notify_all();
|
||||
}
|
||||
|
||||
if (runnables.empty() || nextDue == TimePoint::max()) {
|
||||
return Milliseconds(-1);
|
||||
}
|
||||
@@ -208,6 +216,25 @@ Milliseconds RunLoop::Impl::processRunnables() {
|
||||
return timeout;
|
||||
}
|
||||
|
||||
std::size_t RunLoop::Impl::waitForEmpty(Milliseconds timeout) {
|
||||
const auto startTime = mbgl::util::MonotonicTimer::now();
|
||||
while (true) {
|
||||
std::size_t remaining;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex);
|
||||
remaining = runnables.size();
|
||||
}
|
||||
|
||||
const auto elapsed = mbgl::util::MonotonicTimer::now() - startTime;
|
||||
const auto elapsedMillis = std::chrono::duration_cast<Milliseconds>(elapsed);
|
||||
if (remaining == 0 || (Milliseconds::zero() < timeout && timeout <= elapsedMillis)) {
|
||||
return remaining;
|
||||
}
|
||||
|
||||
runLoop->runOnce();
|
||||
}
|
||||
}
|
||||
|
||||
RunLoop* RunLoop::Get() {
|
||||
assert(static_cast<RunLoop*>(Scheduler::GetCurrent()));
|
||||
return static_cast<RunLoop*>(Scheduler::GetCurrent());
|
||||
@@ -230,6 +257,10 @@ void RunLoop::wake() {
|
||||
impl->wake();
|
||||
}
|
||||
|
||||
std::size_t RunLoop::waitForEmpty(std::chrono::milliseconds timeout) {
|
||||
return impl->waitForEmpty(timeout);
|
||||
}
|
||||
|
||||
void RunLoop::run() {
|
||||
MBGL_VERIFY_THREAD(tid);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user