MapLibre Native Core
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
mbgl::Scheduler Class Referenceabstract

#include <scheduler.hpp>

Inheritance diagram for mbgl::Scheduler:
mbgl::util::RunLoop

Public Member Functions

virtual ~Scheduler ()=default
 
virtual void schedule (std::function< void()>)=0
 Enqueues a function for execution. More...
 
virtual mapbox::base::WeakPtr< SchedulermakeWeakPtr ()=0
 Makes a weak pointer to this Scheduler. More...
 
std::function< void()> bindOnce (std::function< void()>)
 
template<typename TaskFn , typename ReplyFn >
void scheduleAndReplyValue (const TaskFn &task, const ReplyFn &reply)
 

Static Public Member Functions

static SchedulerGetCurrent ()
 Set/Get the current Scheduler for this thread. More...
 
static void SetCurrent (Scheduler *)
 
static std::shared_ptr< SchedulerGetBackground ()
 
static std::shared_ptr< SchedulerGetSequenced ()
 

Protected Member Functions

template<typename TaskFn , typename ReplyFn >
void scheduleAndReplyValue (const TaskFn &task, const ReplyFn &reply, mapbox::base::WeakPtr< Scheduler > replyScheduler)
 

Detailed Description

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.

Scheduler::GetCurrent() is typically used to create a mailbox and ActorRef for an object that lives on the main thread and is not itself wrapped an Actor. The underlying implementation of this Scheduler should usually be a RunLoop auto mailbox = std::make_shared<Mailbox>(*Scheduler::Get()); Actor<Worker> worker(threadPool, ActorRef<Foo>(*this, mailbox));

Definition at line 35 of file scheduler.hpp.

Constructor & Destructor Documentation

◆ ~Scheduler()

virtual mbgl::Scheduler::~Scheduler ( )
virtualdefault

Member Function Documentation

◆ bindOnce()

std::function<void()> mbgl::Scheduler::bindOnce ( std::function< void()>  )

Returns a closure wrapping the given one.

When the returned closure is invoked for the first time, it schedules the given closure to this scheduler, the consequent calls of the returned closure are ignored.

If this scheduler is already deleted by the time the returnded closure is first invoked, the call is ignored.

◆ GetBackground()

static std::shared_ptr<Scheduler> mbgl::Scheduler::GetBackground ( )
static

Get the scheduler for asynchronous tasks. This method will lazily initialize a shared worker pool when ran from the first time. The scheduled tasks might run in parallel on different threads. TODO : Rename to GetPool()

◆ GetCurrent()

static Scheduler* mbgl::Scheduler::GetCurrent ( )
static

Set/Get the current Scheduler for this thread.

◆ GetSequenced()

static std::shared_ptr<Scheduler> mbgl::Scheduler::GetSequenced ( )
static

Get the sequenced scheduler for asynchronous tasks. Unlike the method above, the returned scheduler (once stored) represents a single thread, thus each newly scheduled task is guarantied to run after the previously scheduled one.

Sequenced scheduler can be used for running tasks on the same thread-unsafe object.

◆ makeWeakPtr()

virtual mapbox::base::WeakPtr<Scheduler> mbgl::Scheduler::makeWeakPtr ( )
pure virtual

Makes a weak pointer to this Scheduler.

Implemented in mbgl::util::RunLoop.

◆ schedule()

virtual void mbgl::Scheduler::schedule ( std::function< void()>  )
pure virtual

Enqueues a function for execution.

Implemented in mbgl::util::RunLoop.

◆ scheduleAndReplyValue() [1/2]

template<typename TaskFn , typename ReplyFn >
void mbgl::Scheduler::scheduleAndReplyValue ( const TaskFn &  task,
const ReplyFn &  reply 
)
inline

Enqueues the given |task| for execution into this scheduler's task queue and then enqueues the |reply| with the captured task result to the current task queue.

The |TaskFn| return type must be compatible with the |ReplyFn| argument type. Note: the task result is copied and passed by value.

Definition at line 61 of file scheduler.hpp.

◆ scheduleAndReplyValue() [2/2]

template<typename TaskFn , typename ReplyFn >
void mbgl::Scheduler::scheduleAndReplyValue ( const TaskFn &  task,
const ReplyFn &  reply,
mapbox::base::WeakPtr< Scheduler replyScheduler 
)
inlineprotected

Definition at line 90 of file scheduler.hpp.

◆ SetCurrent()

static void mbgl::Scheduler::SetCurrent ( Scheduler )
static

The documentation for this class was generated from the following file: