diff options
author | Mikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com> | 2019-10-04 12:30:41 +0300 |
---|---|---|
committer | Mikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com> | 2019-10-04 17:42:21 +0300 |
commit | bef635765a1bbec14d7732856c38c037ea8add6a (patch) | |
tree | 47443222a5982031b4c9ecd531bea14edc61a8c8 /include | |
parent | 198e3453394ccb2b1f7db72d1858cfd18e302a1e (diff) | |
download | qtlocation-mapboxgl-bef635765a1bbec14d7732856c38c037ea8add6a.tar.gz |
[core] Decouple Scheduler interface from actor model
So that it is possible to schedule normal `std::function` and use `mapbox::base::WeakPtr`.
Diffstat (limited to 'include')
-rw-r--r-- | include/mbgl/actor/mailbox.hpp | 2 | ||||
-rw-r--r-- | include/mbgl/actor/scheduler.hpp | 10 | ||||
-rw-r--r-- | include/mbgl/util/run_loop.hpp | 8 |
3 files changed, 8 insertions, 12 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..ca34901cfd 100644 --- a/include/mbgl/actor/scheduler.hpp +++ b/include/mbgl/actor/scheduler.hpp @@ -1,5 +1,6 @@ #pragma once +#include <functional> #include <memory> namespace mbgl { @@ -31,12 +32,9 @@ 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; // Set/Get the current Scheduler for this thread static Scheduler* GetCurrent(); diff --git a/include/mbgl/util/run_loop.hpp b/include/mbgl/util/run_loop.hpp index 381e3ae213..961573fd87 100644 --- a/include/mbgl/util/run_loop.hpp +++ b/include/mbgl/util/run_loop.hpp @@ -72,12 +72,8 @@ public: push(Priority::Default, task); return std::make_unique<WorkRequest>(task); } - - void schedule(std::weak_ptr<Mailbox> mailbox) override { - invoke([mailbox] () { - Mailbox::maybeReceive(mailbox); - }); - } + + void schedule(std::function<void()> fn) override { invoke(std::move(fn)); } class Impl; |