diff options
Diffstat (limited to 'include/mbgl')
-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; |