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 /src/mbgl/actor/mailbox.cpp | |
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 'src/mbgl/actor/mailbox.cpp')
-rw-r--r-- | src/mbgl/actor/mailbox.cpp | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/src/mbgl/actor/mailbox.cpp b/src/mbgl/actor/mailbox.cpp index dfe0520790..070e14bdb0 100644 --- a/src/mbgl/actor/mailbox.cpp +++ b/src/mbgl/actor/mailbox.cpp @@ -27,7 +27,7 @@ void Mailbox::open(Scheduler& scheduler_) { } if (!queue.empty()) { - (*scheduler)->schedule(shared_from_this()); + (*scheduler)->schedule(makeClosure(shared_from_this())); } } @@ -57,7 +57,7 @@ void Mailbox::push(std::unique_ptr<Message> message) { bool wasEmpty = queue.empty(); queue.push(std::move(message)); if (wasEmpty && scheduler) { - (*scheduler)->schedule(shared_from_this()); + (*scheduler)->schedule(makeClosure(shared_from_this())); } } @@ -84,14 +84,20 @@ void Mailbox::receive() { (*message)(); if (!wasEmpty) { - (*scheduler)->schedule(shared_from_this()); + (*scheduler)->schedule(makeClosure(shared_from_this())); } } +// static void Mailbox::maybeReceive(std::weak_ptr<Mailbox> mailbox) { if (auto locked = mailbox.lock()) { locked->receive(); } } +// static +std::function<void()> Mailbox::makeClosure(std::weak_ptr<Mailbox> mailbox) { + return [mailbox]() { maybeReceive(mailbox); }; +} + } // namespace mbgl |