Name Date Size #Lines LOC

..--

test/H25-Apr-2025-726493

DIR_METADATAH A D25-Apr-2025101 76

README.mdH A D25-Apr-20253.8 KiB6961

associated_thread_id.ccH A D25-Apr-20251.2 KiB3724

associated_thread_id.hH A D25-Apr-20253.5 KiB10251

atomic_flag_set.ccH A D25-Apr-20256.6 KiB214155

atomic_flag_set.hH A D25-Apr-20254.9 KiB14373

atomic_flag_set_unittest.ccH A D25-Apr-202511.6 KiB326256

delayed_task_handle_delegate.ccH A D25-Apr-20252 KiB7049

delayed_task_handle_delegate.hH A D25-Apr-20252 KiB6537

enqueue_order.hH A D25-Apr-20251.6 KiB6235

enqueue_order_generator.ccH A D25-Apr-2025504 1910

enqueue_order_generator.hH A D25-Apr-20251.2 KiB4326

fence.ccH A D25-Apr-20251.2 KiB4629

fence.hH A D25-Apr-20252 KiB6733

lazily_deallocated_deque.hH A D25-Apr-202510.3 KiB385264

lazily_deallocated_deque_unittest.ccH A D25-Apr-202511 KiB510371

sequence_manager.ccH A D25-Apr-20256.4 KiB193152

sequence_manager.hH A D25-Apr-202514.9 KiB382184

sequence_manager_impl.ccH A D25-Apr-202546.2 KiB1,257953

sequence_manager_impl.hH A D25-Apr-202520.5 KiB516305

sequence_manager_impl_unittest.ccH A D25-Apr-2025215.3 KiB6,0634,566

sequence_manager_perftest.ccH A D25-Apr-202523.1 KiB729565

sequenced_task_source.ccH A D25-Apr-2025842 2818

sequenced_task_source.hH A D25-Apr-20254 KiB10855

task_order.ccH A D25-Apr-20252.8 KiB9057

task_order.hH A D25-Apr-20253.4 KiB9243

task_order_unittest.ccH A D25-Apr-20254.2 KiB131102

task_queue.ccH A D25-Apr-20252.9 KiB10680

task_queue.hH A D25-Apr-202517.7 KiB447206

task_queue_impl.ccH A D25-Apr-202562.7 KiB1,6941,269

task_queue_impl.hH A D25-Apr-202524.9 KiB627370

task_queue_selector.ccH A D25-Apr-202510.5 KiB297233

task_queue_selector.hH A D25-Apr-20259.5 KiB269163

task_queue_selector_unittest.ccH A D25-Apr-202525.6 KiB682547

task_queue_unittest.ccH A D25-Apr-20256.7 KiB187110

task_time_observer.hH A D25-Apr-2025977 3217

tasks.ccH A D25-Apr-20254.7 KiB152123

tasks.hH A D25-Apr-20256.5 KiB181110

thread_controller.ccH A D25-Apr-202525.5 KiB675460

thread_controller.hH A D25-Apr-202519.1 KiB464208

thread_controller_impl.ccH A D25-Apr-202513.6 KiB377266

thread_controller_impl.hH A D25-Apr-20254.8 KiB13295

thread_controller_power_monitor.ccH A D25-Apr-20253 KiB9560

thread_controller_power_monitor.hH A D25-Apr-20251.9 KiB5729

thread_controller_power_monitor_unittest.ccH A D25-Apr-20252.1 KiB6647

thread_controller_with_message_pump_impl.ccH A D25-Apr-202528.8 KiB759511

thread_controller_with_message_pump_impl.hH A D25-Apr-20258.3 KiB223142

thread_controller_with_message_pump_impl_unittest.ccH A D25-Apr-202582.4 KiB2,0981,468

time_domain.ccH A D25-Apr-2025792 3321

time_domain.hH A D25-Apr-20252.2 KiB7138

wake_up_queue.ccH A D25-Apr-20257.1 KiB192130

wake_up_queue.hH A D25-Apr-20255.2 KiB15692

wake_up_queue_unittest.ccH A D25-Apr-202520.3 KiB523400

work_deduplicator.ccH A D25-Apr-20253 KiB7955

work_deduplicator.hH A D25-Apr-20255.8 KiB14646

work_deduplicator_unittest.ccH A D25-Apr-20258.3 KiB220169

work_queue.ccH A D25-Apr-202510.4 KiB332230

work_queue.hH A D25-Apr-20256.7 KiB18878

work_queue_sets.ccH A D25-Apr-20258.5 KiB233196

work_queue_sets.hH A D25-Apr-20254.8 KiB16295

work_queue_sets_unittest.ccH A D25-Apr-202518.8 KiB520431

work_queue_unittest.ccH A D25-Apr-202522.9 KiB651514

work_tracker.ccH A D25-Apr-20254.7 KiB14394

work_tracker.hH A D25-Apr-20255 KiB13454

work_tracker_unittest.ccH A D25-Apr-20255.5 KiB155103

README.md

1# What is this
2This file documents high level parts of the sequence manager.
3
4The sequence manager provides a set of prioritized FIFO task queues, which
5allows funneling multiple sequences of immediate and delayed tasks on a single
6underlying sequence.
7
8## Work Queue and Task selection
9Both immediate tasks and delayed tasks are posted to a `TaskQueue` via an
10associated `TaskRunner`. `TaskQueue`s use distinct primitive FIFO queues, called
11`WorkQueue`s, to manage immediate tasks and delayed tasks. Tasks eventually end
12up in their assigned `WorkQueue` which is made directly visible to
13`SequenceManager` through `TaskQueueSelector`.
14`SequenceManagerImpl::SelectNextTask()` uses
15`TaskQueueSelector::SelectWorkQueueToService()` to select the next work queue
16based on various policy e.g. priority, from which 1 task is popped at a time.
17
18## Journey of a Task
19Task queues have a mechanism to allow efficient cross-thread posting with the
20use of 2 work queues, `immediate_incoming_queue` which is used when posting, and
21`immediate_work_queue` used to pop tasks from. An immediate task posted from the
22main thread is pushed on `immediate_incoming_queue` in
23`TaskQueueImpl::PostImmediateTaskImpl()`. If the work queue was empty,
24`SequenceManager` is notified and the `TaskQueue` is registered to do
25`ReloadEmptyImmediateWorkQueue()` before SequenceManager selects a task, which
26moves tasks from `immediate_incoming_queue` to `immediate_work_queue` in batch
27for all registered `TaskQueue`s. The tasks then follow the regular work queue
28selection mechanism.
29
30## Journey of a WakeUp
31A `WakeUp` represents a time at which a delayed task wants to run.
32
33Each `TaskQueueImpl` maintains its own next wake-up as
34`main_thread_only().scheduled_wake_up`, associated with the earliest pending
35delayed task. It communicates its wake up to the WakeUpQueue via
36`WakeUpQueue::SetNextWakeUpForQueue()`. The `WakeUpQueue` is responsible for
37determining the single next wake up time for the thread. This is accessed from
38`SequenceManagerImpl` and may determine the next run time if there's no
39immediate work, which ultimately gets passed to the MessagePump, typically via
40`MessagePump::Delegate::NextWorkInfo` (returned by
41`ThreadControllerWithMessagePumpImpl::DoWork()`) or by
42`MessagePump::ScheduleDelayedWork()` (on rare occasions where the next WakeUp is
43scheduled on the main thread from outside a `DoWork()`). When a delayed run time
44associated with a wake-up is reached, `WakeUpQueue` is notified through
45`WakeUpQueue::MoveReadyDelayedTasksToWorkQueues()` and in turn notifies all
46`TaskQueue`s whose wake-up can be resolved. This lets each `TaskQueue`s process
47ripe delayed tasks.
48
49## Journey of a delayed Task
50A delayed Task posted cross-thread generates an immediate Task to run
51`TaskQueueImpl::ScheduleDelayedWorkTask()` which eventually calls
52`TaskQueueImpl::PushOntoDelayedIncomingQueueFromMainThread()`, so that it can be
53enqueued on the main thread. A delayed Task posted from the main thread skips
54this step and calls
55`TaskQueueImpl::PushOntoDelayedIncomingQueueFromMainThread()` directly. The Task
56is then pushed on `main_thread_only().delayed_incoming_queue` and possibly
57updates the next task queue wake-up. Once the delayed run time is reached,
58possibly because the wake-up is resolved, the delayed task is moved to
59`main_thread_only().delayed_work_queue` and follows the regular work queue
60selection mechanism.
61
62## TimeDomain and TickClock
63`SequenceManager` and related classes use a common `TickClock` that can be
64injected by specifying a `TimeDomain`. A `TimeDomain` is a specialisation of
65`TickClock` that gets notified when the `MessagePump` is about to go idle via
66TimeDomain::MaybeFastForwardToWakeUp(), and can use the signal to fast forward
67in time. This is used in `TaskEnvironment` to support `MOCK_TIME`, and in
68devtools to support virtual time.
69