diff options
Diffstat (limited to 'include/mbgl/actor/mailbox.hpp')
-rw-r--r-- | include/mbgl/actor/mailbox.hpp | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/include/mbgl/actor/mailbox.hpp b/include/mbgl/actor/mailbox.hpp index 1603ea4924..862ee750a4 100644 --- a/include/mbgl/actor/mailbox.hpp +++ b/include/mbgl/actor/mailbox.hpp @@ -1,5 +1,7 @@ #pragma once +#include <mbgl/util/optional.hpp> + #include <memory> #include <mutex> #include <queue> @@ -11,6 +13,13 @@ class Message; class Mailbox : public std::enable_shared_from_this<Mailbox> { public: + + // Create a "holding" mailbox, messages to which will remain queued, + // unconsumed, until the mailbox is associated with a Scheduler using + // start(). This allows a Mailbox object to be created on one thread and + // later transferred to a different target thread that may not yet exist. + Mailbox(); + Mailbox(Scheduler&); void push(std::unique_ptr<Message>); @@ -18,14 +27,15 @@ public: void close(); void receive(); - // Replace this mailbox's scheduler. Effectively allows a mailbox to be - // created on one thread and moved to another one. - void setScheduler(Scheduler* scheduler_); + // Attach the given scheduler to this mailbox and begin processing messages + // sent to it. The mailbox must be a "holding" mailbox, as created by the + // default constructor Mailbox(). + void start(Scheduler* scheduler_); static void maybeReceive(std::weak_ptr<Mailbox>); private: - Scheduler* scheduler; + optional<Scheduler*> scheduler; std::recursive_mutex receivingMutex; std::mutex pushingMutex; |