From 099a1cb9f10d5b615b115583be147656f2c2cd43 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Tue, 21 Feb 2017 13:57:20 -0800 Subject: [core] Move actor/{mailbox,scheduler}.hpp to public include directory Map constructor takes Scheduler&, and consumers are expected to define an implementation. Therefore the interface must be public. --- cmake/core-files.cmake | 4 ++-- include/mbgl/actor/mailbox.hpp | 33 +++++++++++++++++++++++++++++++++ include/mbgl/actor/scheduler.hpp | 38 ++++++++++++++++++++++++++++++++++++++ src/mbgl/actor/mailbox.hpp | 33 --------------------------------- src/mbgl/actor/scheduler.hpp | 38 -------------------------------------- 5 files changed, 73 insertions(+), 73 deletions(-) create mode 100644 include/mbgl/actor/mailbox.hpp create mode 100644 include/mbgl/actor/scheduler.hpp delete mode 100644 src/mbgl/actor/mailbox.hpp delete mode 100644 src/mbgl/actor/scheduler.hpp diff --git a/cmake/core-files.cmake b/cmake/core-files.cmake index 1a1f400163..21a88f0264 100644 --- a/cmake/core-files.cmake +++ b/cmake/core-files.cmake @@ -2,12 +2,12 @@ set(MBGL_CORE_FILES # actor + include/mbgl/actor/mailbox.hpp + include/mbgl/actor/scheduler.hpp src/mbgl/actor/actor.hpp src/mbgl/actor/actor_ref.hpp src/mbgl/actor/mailbox.cpp - src/mbgl/actor/mailbox.hpp src/mbgl/actor/message.hpp - src/mbgl/actor/scheduler.hpp # algorithm src/mbgl/algorithm/covered_by_children.hpp 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 +#include +#include + +namespace mbgl { + +class Scheduler; +class Message; + +class Mailbox : public std::enable_shared_from_this { +public: + Mailbox(Scheduler&); + + void push(std::unique_ptr); + + void close(); + void receive(); + + static void maybeReceive(std::weak_ptr); + +private: + Scheduler& scheduler; + + std::mutex closingMutex; + bool closing { false }; + + std::mutex queueMutex; + std::queue> queue; +}; + +} // namespace mbgl diff --git a/include/mbgl/actor/scheduler.hpp b/include/mbgl/actor/scheduler.hpp new file mode 100644 index 0000000000..83689c3348 --- /dev/null +++ b/include/mbgl/actor/scheduler.hpp @@ -0,0 +1,38 @@ +#pragma once + +#include + +namespace mbgl { + +class Mailbox; + +/* + A `Scheduler` is responsible for coordinating the processing of messages by + one or more actors via their mailboxes. It's an abstract interface. Currently, + the following concrete implementations exist: + + * `ThreadPool` can coordinate an unlimited number of actors over any number of + threads via a pool, preserving the following behaviors: + + - Messages from each individual mailbox are processed in order + - Only a single message from a mailbox is processed at a time; there is no + concurrency within a mailbox + + Subject to these constraints, processing can happen on whatever thread in the + pool is available. + + * `RunLoop` is a `Scheduler` that is typically used to create a mailbox and + `ActorRef` for an object that lives on the main thread and is not itself wrapped + as an `Actor`: + + auto mailbox = std::make_shared(*util::RunLoop::Get()); + Actor worker(threadPool, ActorRef(*this, mailbox)); +*/ + +class Scheduler { +public: + virtual ~Scheduler() = default; + virtual void schedule(std::weak_ptr) = 0; +}; + +} // namespace mbgl diff --git a/src/mbgl/actor/mailbox.hpp b/src/mbgl/actor/mailbox.hpp deleted file mode 100644 index cff0de243a..0000000000 --- a/src/mbgl/actor/mailbox.hpp +++ /dev/null @@ -1,33 +0,0 @@ -#pragma once - -#include -#include -#include - -namespace mbgl { - -class Scheduler; -class Message; - -class Mailbox : public std::enable_shared_from_this { -public: - Mailbox(Scheduler&); - - void push(std::unique_ptr); - - void close(); - void receive(); - - static void maybeReceive(std::weak_ptr); - -private: - Scheduler& scheduler; - - std::mutex closingMutex; - bool closing { false }; - - std::mutex queueMutex; - std::queue> queue; -}; - -} // namespace mbgl diff --git a/src/mbgl/actor/scheduler.hpp b/src/mbgl/actor/scheduler.hpp deleted file mode 100644 index 83689c3348..0000000000 --- a/src/mbgl/actor/scheduler.hpp +++ /dev/null @@ -1,38 +0,0 @@ -#pragma once - -#include - -namespace mbgl { - -class Mailbox; - -/* - A `Scheduler` is responsible for coordinating the processing of messages by - one or more actors via their mailboxes. It's an abstract interface. Currently, - the following concrete implementations exist: - - * `ThreadPool` can coordinate an unlimited number of actors over any number of - threads via a pool, preserving the following behaviors: - - - Messages from each individual mailbox are processed in order - - Only a single message from a mailbox is processed at a time; there is no - concurrency within a mailbox - - Subject to these constraints, processing can happen on whatever thread in the - pool is available. - - * `RunLoop` is a `Scheduler` that is typically used to create a mailbox and - `ActorRef` for an object that lives on the main thread and is not itself wrapped - as an `Actor`: - - auto mailbox = std::make_shared(*util::RunLoop::Get()); - Actor worker(threadPool, ActorRef(*this, mailbox)); -*/ - -class Scheduler { -public: - virtual ~Scheduler() = default; - virtual void schedule(std::weak_ptr) = 0; -}; - -} // namespace mbgl -- cgit v1.2.1