diff options
author | m-stephen <truestyle2005@163.com> | 2019-11-01 10:27:03 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-11-01 10:27:03 +0800 |
commit | 9427c04bc709c39f7e083b6d1597aaf33af8c302 (patch) | |
tree | 224fa2bffbc6a81b447c76b98e4c13a51baadc29 /include/mbgl/actor | |
parent | fc2c02bbc6abaef52077fe5e9e78f772e6009967 (diff) | |
parent | 5b38cfee18800cbb3c6a3186882744592662c3d6 (diff) | |
download | qtlocation-mapboxgl-9427c04bc709c39f7e083b6d1597aaf33af8c302.tar.gz |
Merge branch 'master' into stephen-improve-accuracy-for-cameraupstream/stephen-improve-accuracy-for-camera
Diffstat (limited to 'include/mbgl/actor')
-rw-r--r-- | include/mbgl/actor/mailbox.hpp | 2 | ||||
-rw-r--r-- | include/mbgl/actor/scheduler.hpp | 24 |
2 files changed, 20 insertions, 6 deletions
diff --git a/include/mbgl/actor/mailbox.hpp b/include/mbgl/actor/mailbox.hpp index 23c579917a..2b9838ef29 100644 --- a/include/mbgl/actor/mailbox.hpp +++ b/include/mbgl/actor/mailbox.hpp @@ -2,6 +2,7 @@ #include <mbgl/util/optional.hpp> +#include <functional> #include <memory> #include <mutex> #include <queue> @@ -34,6 +35,7 @@ public: void receive(); static void maybeReceive(std::weak_ptr<Mailbox>); + static std::function<void()> makeClosure(std::weak_ptr<Mailbox>); private: optional<Scheduler*> scheduler; diff --git a/include/mbgl/actor/scheduler.hpp b/include/mbgl/actor/scheduler.hpp index 6470ab1245..bb2cf124b8 100644 --- a/include/mbgl/actor/scheduler.hpp +++ b/include/mbgl/actor/scheduler.hpp @@ -1,5 +1,8 @@ #pragma once +#include <mapbox/weak.hpp> + +#include <functional> #include <memory> namespace mbgl { @@ -31,12 +34,21 @@ class Mailbox; class Scheduler { public: virtual ~Scheduler() = default; - - // Used by a Mailbox when it has a message in its queue to request that it - // be scheduled. Specifically, the scheduler is expected to asynchronously - // call `receive() on the given mailbox, provided it still exists at that - // time. - virtual void schedule(std::weak_ptr<Mailbox>) = 0; + + // Enqueues a function for execution. + virtual void schedule(std::function<void()>) = 0; + // Makes a weak pointer to this Scheduler. + virtual mapbox::base::WeakPtr<Scheduler> makeWeakPtr() = 0; + + // Returns a closure wrapping the given one. + // + // When the returned closure is invoked for the first time, it schedules + // the given closure to this scheduler, the consequent calls of the + // returned closure are ignored. + // + // If this scheduler is already deleted by the time the returnded closure is + // first invoked, the call is ignored. + std::function<void()> bindOnce(std::function<void()>); // Set/Get the current Scheduler for this thread static Scheduler* GetCurrent(); |