Asynchronous GeometryTile deletion (#2051)
Co-authored-by: Tim Sylvester <tim@wetdogweather.com>
This commit is contained in:
@@ -71,7 +71,7 @@ public:
|
||||
ActorRef<std::decay_t<Object>> self() { return parent.self(); }
|
||||
|
||||
private:
|
||||
std::shared_ptr<Scheduler> retainer;
|
||||
const std::shared_ptr<Scheduler> retainer;
|
||||
AspiringActor<Object> parent;
|
||||
EstablishedActor<Object> target;
|
||||
};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include <atomic>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
@@ -28,6 +28,9 @@ public:
|
||||
void open(Scheduler& scheduler_);
|
||||
void close();
|
||||
|
||||
// Indicate this mailbox will no longer be checked for messages
|
||||
void abandon();
|
||||
|
||||
bool isOpen() const;
|
||||
|
||||
void push(std::unique_ptr<Message>);
|
||||
@@ -37,11 +40,18 @@ public:
|
||||
static std::function<void()> makeClosure(std::weak_ptr<Mailbox>);
|
||||
|
||||
private:
|
||||
enum class State : uint32_t {
|
||||
Idle = 0,
|
||||
Processing,
|
||||
Abandoned
|
||||
};
|
||||
|
||||
mapbox::base::WeakPtr<Scheduler> weakScheduler;
|
||||
|
||||
std::recursive_mutex receivingMutex;
|
||||
std::mutex pushingMutex;
|
||||
|
||||
std::atomic<State> state{State::Idle};
|
||||
bool closed{false};
|
||||
|
||||
std::mutex queueMutex;
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <mbgl/util/chrono.hpp>
|
||||
|
||||
#include <mapbox/std/weak.hpp>
|
||||
|
||||
#include <functional>
|
||||
@@ -36,9 +38,12 @@ public:
|
||||
virtual ~Scheduler() = default;
|
||||
|
||||
/// Enqueues a function for execution.
|
||||
virtual void schedule(std::function<void()>) = 0;
|
||||
virtual void schedule(std::function<void()>&&) = 0;
|
||||
/// Makes a weak pointer to this Scheduler.
|
||||
virtual mapbox::base::WeakPtr<Scheduler> makeWeakPtr() = 0;
|
||||
/// Enqueues a function for execution on the render thread.
|
||||
virtual void runOnRenderThread(std::function<void()>&&){};
|
||||
virtual void runRenderJobs() {}
|
||||
|
||||
/// Returns a closure wrapping the given one.
|
||||
///
|
||||
@@ -62,6 +67,11 @@ public:
|
||||
scheduleAndReplyValue(task, reply, GetCurrent()->makeWeakPtr());
|
||||
}
|
||||
|
||||
/// Wait until there's nothing pending or in process
|
||||
/// Must not be called from a task provided to this scheduler.
|
||||
/// @param timeout Time to wait, or zero to wait forever.
|
||||
virtual std::size_t waitForEmpty(Milliseconds timeout = Milliseconds{0}) = 0;
|
||||
|
||||
/// Set/Get the current Scheduler for this thread
|
||||
static Scheduler* GetCurrent();
|
||||
static void SetCurrent(Scheduler*);
|
||||
@@ -84,6 +94,9 @@ public:
|
||||
/// on the same thread-unsafe object.
|
||||
[[nodiscard]] static std::shared_ptr<Scheduler> GetSequenced();
|
||||
|
||||
/// Set a function to be called when an exception occurs on a thread controlled by the scheduler
|
||||
void setExceptionHandler(std::function<void(const std::exception_ptr)> handler_) { handler = std::move(handler_); }
|
||||
|
||||
protected:
|
||||
template <typename TaskFn, typename ReplyFn>
|
||||
void scheduleAndReplyValue(const TaskFn& task,
|
||||
@@ -97,9 +110,10 @@ protected:
|
||||
};
|
||||
replyScheduler->schedule(std::move(scheduledReply));
|
||||
};
|
||||
|
||||
schedule(std::move(scheduled));
|
||||
}
|
||||
|
||||
std::function<void(const std::exception_ptr)> handler;
|
||||
};
|
||||
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <mbgl/actor/scheduler.hpp>
|
||||
#include <mbgl/gfx/backend.hpp>
|
||||
#include <mbgl/gfx/command_encoder.hpp>
|
||||
#include <mbgl/gfx/draw_scope.hpp>
|
||||
@@ -53,7 +54,8 @@ using VertexAttributeArrayPtr = std::shared_ptr<VertexAttributeArray>;
|
||||
class Context {
|
||||
protected:
|
||||
Context(uint32_t maximumVertexBindingCount_)
|
||||
: maximumVertexBindingCount(maximumVertexBindingCount_) {}
|
||||
: maximumVertexBindingCount(maximumVertexBindingCount_),
|
||||
backgroundScheduler(Scheduler::GetBackground()) {}
|
||||
|
||||
public:
|
||||
static constexpr const uint32_t minimumRequiredVertexBindingCount = 8;
|
||||
@@ -161,6 +163,8 @@ protected:
|
||||
virtual std::unique_ptr<DrawScopeResource> createDrawScopeResource() = 0;
|
||||
|
||||
gfx::RenderingStats stats;
|
||||
|
||||
std::shared_ptr<Scheduler> backgroundScheduler;
|
||||
};
|
||||
|
||||
} // namespace gfx
|
||||
|
||||
@@ -78,9 +78,11 @@ public:
|
||||
return std::make_unique<WorkRequest>(task);
|
||||
}
|
||||
|
||||
void schedule(std::function<void()> fn) override { invoke(std::move(fn)); }
|
||||
void schedule(std::function<void()>&& fn) override { invoke(std::move(fn)); }
|
||||
::mapbox::base::WeakPtr<Scheduler> makeWeakPtr() override { return weakFactory.makeWeakPtr(); }
|
||||
|
||||
std::size_t waitForEmpty(Milliseconds timeout) override;
|
||||
|
||||
class Impl;
|
||||
|
||||
private:
|
||||
|
||||
21
include/mbgl/util/scoped.hpp
Normal file
21
include/mbgl/util/scoped.hpp
Normal file
@@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
/// Run a lambda on scope exit
|
||||
template <typename Func>
|
||||
struct Scoped {
|
||||
Scoped(Func&& fn)
|
||||
: cb(std::move(fn)){};
|
||||
~Scoped() { cb(); }
|
||||
|
||||
Scoped(const Scoped&) = delete;
|
||||
Scoped(Scoped&&) noexcept = delete;
|
||||
Scoped& operator=(const Scoped&) = delete;
|
||||
Scoped& operator=(Scoped&&) noexcept = delete;
|
||||
|
||||
private:
|
||||
Func cb;
|
||||
};
|
||||
|
||||
} // namespace mbgl
|
||||
@@ -1,10 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
#include <type_traits>
|
||||
#include <exception>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <type_traits>
|
||||
|
||||
// Polyfill needed by Qt when building for Android with GCC
|
||||
#if defined(__ANDROID__) && defined(__GLIBCXX__)
|
||||
@@ -76,6 +78,10 @@ inline std::string toString(long double t, bool decimal = false) {
|
||||
return toString(static_cast<double>(t), decimal);
|
||||
}
|
||||
|
||||
inline std::string toString(std::thread::id threadId) {
|
||||
return (std::ostringstream() << threadId).str();
|
||||
}
|
||||
|
||||
std::string toString(const std::exception_ptr &);
|
||||
|
||||
template <class T>
|
||||
|
||||
Reference in New Issue
Block a user