• Home
Name Date Size #Lines LOC

..--

test/04-Jul-2025-721490

DIR_METADATAD04-Jul-2025101 76

README.mdD04-Jul-20253.8 KiB6961

associated_thread_id.ccD04-Jul-20252.9 KiB9066

associated_thread_id.hD04-Jul-20254 KiB11252

atomic_flag_set.ccD04-Jul-20256.7 KiB210150

atomic_flag_set.hD04-Jul-20254.8 KiB14070

atomic_flag_set_unittest.ccD04-Jul-202511.6 KiB325255

delayed_task_handle_delegate.ccD04-Jul-20252 KiB7049

delayed_task_handle_delegate.hD04-Jul-20252.1 KiB6637

enqueue_order.hD04-Jul-20251.6 KiB6235

enqueue_order_generator.ccD04-Jul-2025504 1910

enqueue_order_generator.hD04-Jul-20251.2 KiB4326

fence.ccD04-Jul-20251.2 KiB4629

fence.hD04-Jul-20252.1 KiB6834

lazily_deallocated_deque.hD04-Jul-202510.8 KiB390266

lazily_deallocated_deque_unittest.ccD04-Jul-202511 KiB510371

sequence_manager.ccD04-Jul-20256.4 KiB193152

sequence_manager.hD04-Jul-202515 KiB385187

sequence_manager_impl.ccD04-Jul-202546.3 KiB1,262956

sequence_manager_impl.hD04-Jul-202520.8 KiB524309

sequence_manager_impl_unittest.ccD04-Jul-2025216.3 KiB6,0834,576

sequence_manager_perftest.ccD04-Jul-202523.1 KiB728564

sequenced_task_source.ccD04-Jul-2025842 2818

sequenced_task_source.hD04-Jul-20254 KiB10855

task_order.ccD04-Jul-20252.8 KiB9057

task_order.hD04-Jul-20253.4 KiB9243

task_order_unittest.ccD04-Jul-20254.2 KiB131102

task_queue.ccD04-Jul-20252.9 KiB10680

task_queue.hD04-Jul-202517.7 KiB447206

task_queue_impl.ccD04-Jul-202563.3 KiB1,7061,279

task_queue_impl.hD04-Jul-202525.2 KiB632371

task_queue_selector.ccD04-Jul-202510.1 KiB288227

task_queue_selector.hD04-Jul-20259.5 KiB267162

task_queue_selector_unittest.ccD04-Jul-202525.8 KiB687550

task_queue_unittest.ccD04-Jul-20256.6 KiB186109

task_time_observer.ccD04-Jul-2025352 146

task_time_observer.hD04-Jul-20251 KiB3419

tasks.ccD04-Jul-20254.7 KiB151122

tasks.hD04-Jul-20256.5 KiB181110

thread_controller.ccD04-Jul-202528.1 KiB729505

thread_controller.hD04-Jul-202520.1 KiB489227

thread_controller_impl.ccD04-Jul-202513.6 KiB377266

thread_controller_impl.hD04-Jul-20254.9 KiB13396

thread_controller_power_monitor.ccD04-Jul-20253 KiB9761

thread_controller_power_monitor.hD04-Jul-20251.9 KiB5729

thread_controller_power_monitor_unittest.ccD04-Jul-20252.1 KiB6647

thread_controller_with_message_pump_impl.ccD04-Jul-202528.8 KiB757506

thread_controller_with_message_pump_impl.hD04-Jul-20258.4 KiB225144

thread_controller_with_message_pump_impl_unittest.ccD04-Jul-202589.3 KiB2,2941,620

time_domain.ccD04-Jul-2025792 3321

time_domain.hD04-Jul-20252.2 KiB7138

wake_up_queue.ccD04-Jul-20257.1 KiB192130

wake_up_queue.hD04-Jul-20255.4 KiB15993

wake_up_queue_unittest.ccD04-Jul-202520.3 KiB523400

work_deduplicator.ccD04-Jul-20253 KiB7955

work_deduplicator.hD04-Jul-20255.8 KiB14646

work_deduplicator_unittest.ccD04-Jul-20258.3 KiB220169

work_queue.ccD04-Jul-202511.1 KiB345240

work_queue.hD04-Jul-20256.8 KiB18978

work_queue_sets.ccD04-Jul-20258.5 KiB233196

work_queue_sets.hD04-Jul-20254.8 KiB16295

work_queue_sets_unittest.ccD04-Jul-202518.9 KiB525434

work_queue_unittest.ccD04-Jul-202522.9 KiB651514

work_tracker.ccD04-Jul-20254.7 KiB14394

work_tracker.hD04-Jul-20255.1 KiB13554

work_tracker_unittest.ccD04-Jul-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