[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.
This commit is contained in:
committed by
Konstantin Käfer
parent
54cbdc4812
commit
099a1cb9f1
33
include/mbgl/actor/mailbox.hpp
Normal file
33
include/mbgl/actor/mailbox.hpp
Normal file
@@ -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
|
||||
38
include/mbgl/actor/scheduler.hpp
Normal file
38
include/mbgl/actor/scheduler.hpp
Normal file
@@ -0,0 +1,38 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
|
||||
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<Mailbox>(*util::RunLoop::Get());
|
||||
Actor<Worker> worker(threadPool, ActorRef<Foo>(*this, mailbox));
|
||||
*/
|
||||
|
||||
class Scheduler {
|
||||
public:
|
||||
virtual ~Scheduler() = default;
|
||||
virtual void schedule(std::weak_ptr<Mailbox>) = 0;
|
||||
};
|
||||
|
||||
} // namespace mbgl
|
||||
Reference in New Issue
Block a user