summaryrefslogtreecommitdiff
path: root/include/mbgl/actor/mailbox.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'include/mbgl/actor/mailbox.hpp')
-rw-r--r--include/mbgl/actor/mailbox.hpp33
1 files changed, 33 insertions, 0 deletions
diff --git a/include/mbgl/actor/mailbox.hpp b/include/mbgl/actor/mailbox.hpp
new file mode 100644
index 0000000000..cff0de243a
--- /dev/null
+++ b/include/mbgl/actor/mailbox.hpp
@@ -0,0 +1,33 @@
+#pragma once
+
+#include <memory>
+#include <mutex>
+#include <queue>
+
+namespace mbgl {
+
+class Scheduler;
+class Message;
+
+class Mailbox : public std::enable_shared_from_this<Mailbox> {
+public:
+ Mailbox(Scheduler&);
+
+ void push(std::unique_ptr<Message>);
+
+ void close();
+ void receive();
+
+ static void maybeReceive(std::weak_ptr<Mailbox>);
+
+private:
+ Scheduler& scheduler;
+
+ std::mutex closingMutex;
+ bool closing { false };
+
+ std::mutex queueMutex;
+ std::queue<std::unique_ptr<Message>> queue;
+};
+
+} // namespace mbgl