updated the documenation for message loops a bit (flutter/engine#26257)
This commit is contained in:
@@ -13,13 +13,23 @@ namespace fml {
|
||||
class TaskRunner;
|
||||
class MessageLoopImpl;
|
||||
|
||||
/// An event loop associated with a thread.
|
||||
///
|
||||
/// This class is the generic front-end to the MessageLoop, differences in
|
||||
/// implementation based on the running platform are in the subclasses of
|
||||
/// flutter::MessageLoopImpl (ex flutter::MessageLoopAndroid).
|
||||
///
|
||||
/// For scheduling events on the message loop see flutter::TaskRunner.
|
||||
///
|
||||
/// \see fml::TaskRunner
|
||||
/// \see fml::MessageLoopImpl
|
||||
/// \see fml::MessageLoopTaskQueues
|
||||
/// \see fml::Wakeable
|
||||
class MessageLoop {
|
||||
public:
|
||||
FML_EMBEDDER_ONLY
|
||||
static MessageLoop& GetCurrent();
|
||||
|
||||
bool IsValid() const;
|
||||
|
||||
void Run();
|
||||
|
||||
void Terminate();
|
||||
@@ -36,10 +46,15 @@ class MessageLoop {
|
||||
|
||||
static void EnsureInitializedForCurrentThread();
|
||||
|
||||
/// Returns true if \p EnsureInitializedForCurrentThread has been called on
|
||||
/// this thread already.
|
||||
static bool IsInitializedForCurrentThread();
|
||||
|
||||
~MessageLoop();
|
||||
|
||||
/// Gets the unique identifier for the TaskQueue associated with the current
|
||||
/// thread.
|
||||
/// \see fml::MessageLoopTaskQueues
|
||||
static TaskQueueId GetCurrentTaskQueueId();
|
||||
|
||||
private:
|
||||
|
||||
@@ -23,6 +23,11 @@
|
||||
|
||||
namespace fml {
|
||||
|
||||
/// An abstract class that represents the differences in implementation of a \p
|
||||
/// fml::MessageLoop depending on the platform.
|
||||
/// \see fml::MessageLoop
|
||||
/// \see fml::MessageLoopAndroid
|
||||
/// \see fml::MessageLoopDarwin
|
||||
class MessageLoopImpl : public Wakeable,
|
||||
public fml::RefCountedThreadSafe<MessageLoopImpl> {
|
||||
public:
|
||||
|
||||
@@ -22,8 +22,11 @@ namespace fml {
|
||||
|
||||
static const TaskQueueId _kUnmerged = TaskQueueId(TaskQueueId::kUnmerged);
|
||||
|
||||
// This is keyed by the |TaskQueueId| and contains all the queue
|
||||
// components that make up a single TaskQueue.
|
||||
/// A collection of tasks and observers associated with one TaskQueue.
|
||||
///
|
||||
/// Often a TaskQueue has a one-to-one relationship with a fml::MessageLoop,
|
||||
/// this isn't the case when TaskQueues are merged via
|
||||
/// \p fml::MessageLoopTaskQueues::Merge.
|
||||
class TaskQueueEntry {
|
||||
public:
|
||||
using TaskObservers = std::map<intptr_t, fml::closure>;
|
||||
@@ -51,9 +54,12 @@ enum class FlushType {
|
||||
kAll,
|
||||
};
|
||||
|
||||
// This class keeps track of all the tasks and observers that
|
||||
// need to be run on it's MessageLoopImpl. This also wakes up the
|
||||
// loop at the required times.
|
||||
/// A singleton container for all tasks and observers associated with all
|
||||
/// fml::MessageLoops.
|
||||
///
|
||||
/// This also wakes up the loop at the required times.
|
||||
/// \see fml::MessageLoop
|
||||
/// \see fml::Wakeable
|
||||
class MessageLoopTaskQueues
|
||||
: public fml::RefCountedThreadSafe<MessageLoopTaskQueues> {
|
||||
public:
|
||||
@@ -115,7 +121,7 @@ class MessageLoopTaskQueues
|
||||
// Will return false if the owner has not been merged before.
|
||||
bool Unmerge(TaskQueueId owner);
|
||||
|
||||
// Returns true if owner owns the subsumed task queue.
|
||||
/// Returns \p true if \p owner owns the \p subsumed task queue.
|
||||
bool Owns(TaskQueueId owner, TaskQueueId subsumed) const;
|
||||
|
||||
// Returns the subsumed task queue if any or |TaskQueueId::kUnmerged|
|
||||
|
||||
@@ -21,6 +21,10 @@ struct UniqueLooperTraits {
|
||||
static void Free(ALooper* value) { ::ALooper_release(value); }
|
||||
};
|
||||
|
||||
/// Android implementation of \p MessageLoopImpl.
|
||||
///
|
||||
/// This implemenation wraps usage of Android's \p looper.
|
||||
/// \see https://developer.android.com/ndk/reference/group/looper
|
||||
class MessageLoopAndroid : public MessageLoopImpl {
|
||||
private:
|
||||
fml::UniqueObject<ALooper*, UniqueLooperTraits> looper_;
|
||||
|
||||
@@ -16,11 +16,21 @@ namespace fml {
|
||||
|
||||
class MessageLoopImpl;
|
||||
|
||||
/// An interface over the ability to schedule tasks on a \p TaskRunner.
|
||||
class BasicTaskRunner {
|
||||
public:
|
||||
/// Schedules \p task to be executed on the TaskRunner's associated event
|
||||
/// loop.
|
||||
virtual void PostTask(const fml::closure& task) = 0;
|
||||
};
|
||||
|
||||
/// The object for scheduling tasks on a \p fml::MessageLoop.
|
||||
///
|
||||
/// Typically there is one \p TaskRunner associated with each thread. When one
|
||||
/// wants to execute an operation on that thread they post a task to the
|
||||
/// TaskRunner.
|
||||
///
|
||||
/// \see fml::MessageLoop
|
||||
class TaskRunner : public fml::RefCountedThreadSafe<TaskRunner>,
|
||||
public BasicTaskRunner {
|
||||
public:
|
||||
@@ -31,12 +41,24 @@ class TaskRunner : public fml::RefCountedThreadSafe<TaskRunner>,
|
||||
virtual void PostTaskForTime(const fml::closure& task,
|
||||
fml::TimePoint target_time);
|
||||
|
||||
/// Schedules a task to be run on the MessageLoop after the time \p delay has
|
||||
/// passed.
|
||||
/// \note There is latency between when the task is schedule and actually
|
||||
/// executed so that the actual execution time is: now + delay +
|
||||
/// message_loop_latency, where message_loop_latency is undefined and could be
|
||||
/// tens of milliseconds.
|
||||
virtual void PostDelayedTask(const fml::closure& task, fml::TimeDelta delay);
|
||||
|
||||
/// Returns \p true when the current executing thread's TaskRunner matches
|
||||
/// this instance.
|
||||
virtual bool RunsTasksOnCurrentThread();
|
||||
|
||||
/// Returns the unique identifier associated with the TaskRunner.
|
||||
/// \see fml::MessageLoopTaskQueues
|
||||
virtual TaskQueueId GetTaskQueueId();
|
||||
|
||||
/// Executes the \p task directly if the TaskRunner \p runner is the
|
||||
/// TaskRunner associated with the current executing thread.
|
||||
static void RunNowOrPostTask(fml::RefPtr<fml::TaskRunner> runner,
|
||||
const fml::closure& task);
|
||||
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
|
||||
namespace fml {
|
||||
|
||||
/// Interface over the ability to \p WakeUp a \p fml::MessageLoopImpl.
|
||||
/// \see fml::MessageLoopTaskQueues
|
||||
class Wakeable {
|
||||
public:
|
||||
virtual ~Wakeable() {}
|
||||
|
||||
Reference in New Issue
Block a user