class MessageLoop
Defined at line 56 of file ../../src/developer/debug/shared/message_loop.h
Message loop implementation.
Unlike the one in FXL, this will run on the host in addition to a Zircon target. On Zircon it
is backed by the async-loop library, on the host (Linux
&
Mac) it is backed by a poll()
implementation (see message_loop_poll.h).
This message loop supports several types of tasks:
- Bare lambdas.
- Delayed lambdas (timers).
- fpromise::pending_task objects (normally generated by fpromise::promise).
- Async I/O events on file handles.
The Fuchsia-specific subclass can also watch for Zircon async events (see message_loop_fuchsia.h
for more).
Protected Members
mutex mutex_
Public Methods
void MessageLoop ()
There can be only one active MessageLoop in scope per thread at a time.
A message loop is active between Init() and Cleanup(). During this period, Current() will
return the message loop.
Init() / Cleanup() is a separate phase so a message loop can be created and managed on one
thread and sent to another thread to actually run (to help with cross-thread task posting).
Defined at line 55 of file ../../src/developer/debug/shared/message_loop.cc
void ~MessageLoop ()
Defined at line 57 of file ../../src/developer/debug/shared/message_loop.cc
bool Init (std::string * error_message)
Init() and Cleanup() must be called on the same thread as Run().
Init() returns true on success. On false the error message will be put into the output param.
Defined at line 61 of file ../../src/developer/debug/shared/message_loop.cc
void Cleanup ()
Defined at line 67 of file ../../src/developer/debug/shared/message_loop.cc
void QuitNow ()
Exits the message loop immediately, not running pending functions. This must be called only on
the MessageLoop thread.
Defined at line 330 of file ../../src/developer/debug/shared/message_loop.cc
MessageLoop * Current ()
Returns the current message loop or null if there isn't one.
Defined at line 81 of file ../../src/developer/debug/shared/message_loop.cc
void Run ()
Runs the message loop.
Defined at line 83 of file ../../src/developer/debug/shared/message_loop.cc
void RunUntilNoTasks ()
Run until no more tasks are posted. This is not really meant for normal functioning of the
debugger. Rather this is geared towards test environments that control what gets inserted into
the message loop. This Useful for tests in which tasks post additional tasks.
NOTE: OS events (file handles, sockets, signals) are not considered as non-idle tasks.
Basically they're ignored when checking for "idleness".
Defined at line 88 of file ../../src/developer/debug/shared/message_loop.cc
void PostTask (FileLineFunction file_line, fit::function<void ()> fn)
Posts the given work to the message loop. It will be added to the end of the work queue.
Defined at line 100 of file ../../src/developer/debug/shared/message_loop.cc
void PostTask (FileLineFunction file_line, fpromise::pending_task task)
Defined at line 104 of file ../../src/developer/debug/shared/message_loop.cc
void RunTask (FileLineFunction file_line, fpromise::pending_task task)
Runs the given task immediately. If it reports a pending completion it will complete
asynchronously, otherwise it will complete synchronously. This can be used to start executing
a promise without putting it at the back of the message loop.
If the task complete asynchronously, it will be added to the queue when it signals a pending
completion.
Defined at line 108 of file ../../src/developer/debug/shared/message_loop.cc
void PostTimer (FileLineFunction file_line, uint64_t delta_ms, fit::function<void ()> fn)
Set a task to run after a certain number of milliseconds have elapsed. Granularity is hard to
guarantee but the timer shouldn't fire earlier than expected.
Defined at line 115 of file ../../src/developer/debug/shared/message_loop.cc
WatchHandle WatchFD (WatchMode mode, int fd, FDWatcher watcher)
void schedule_task (fpromise::pending_task task)
fpromise::executor implementation.
Defined at line 132 of file ../../src/developer/debug/shared/message_loop.cc
fpromise::suspended_task::ticket duplicate_ticket (fpromise::suspended_task::ticket ticket)
fpromise::resolver implementation.
Defined at line 136 of file ../../src/developer/debug/shared/message_loop.cc
void resolve_ticket (fpromise::suspended_task::ticket ticket, bool resume_task)
Defined at line 148 of file ../../src/developer/debug/shared/message_loop.cc
Protected Methods
void RunImpl ()
uint64_t GetMonotonicNowNS ()
Get the value of a monotonic clock in nanoseconds.
void StopWatching (int id)
Used by WatchHandle to unregister a watch. Can be called from any thread without the lock held.
void SetHasTasks ()
Indicates there are tasks to process. Can be called from any thread and will be called without
the lock held.
bool should_quit ()
The platform implementation should check should_quit() after every task execution and exit if
true.
Defined at line 161 of file ../../src/developer/debug/shared/message_loop.h
bool ProcessPendingTask ()
Processes one pending task, returning true if there was work to do, or false if there was
nothing. The mutex_ must be held during the call. It will be unlocked during task processing,
so the platform implementation that calls it must not assume state did not change across the
call.
Defined at line 332 of file ../../src/developer/debug/shared/message_loop.cc
uint64_t DelayNS ()
How much time we should wait before waking up again to process timers.
Defined at line 210 of file ../../src/developer/debug/shared/message_loop.cc
Enumerations
enum WatchMode
| Name | Value |
|---|---|
| kRead | 0 |
| kWrite | 1 |
| kReadWrite | 2 |
Defined at line 58 of file ../../src/developer/debug/shared/message_loop.h
Records
Friends
class WatchHandle
class MessageLoopContext