• Home
Name Date Size #Lines LOC

..--

test/06-Sep-2024-723491

DIR_METADATAD06-Sep-202454 43

README.mdD06-Sep-20243.8 KiB6961

associated_thread_id.ccD06-Sep-20241.1 KiB3623

associated_thread_id.hD06-Sep-20243.1 KiB9245

atomic_flag_set.ccD06-Sep-20246.6 KiB214155

atomic_flag_set.hD06-Sep-20244.9 KiB14373

atomic_flag_set_unittest.ccD06-Sep-202411.6 KiB326256

delayed_task_handle_delegate.ccD06-Sep-20242 KiB7049

delayed_task_handle_delegate.hD06-Sep-20242 KiB6537

enqueue_order.hD06-Sep-20241.6 KiB6235

enqueue_order_generator.ccD06-Sep-2024504 1910

enqueue_order_generator.hD06-Sep-20241.2 KiB4326

fence.ccD06-Sep-20241.2 KiB4629

fence.hD06-Sep-20242 KiB6733

lazily_deallocated_deque.hD06-Sep-202410.3 KiB385264

lazily_deallocated_deque_unittest.ccD06-Sep-202411 KiB510371

sequence_manager.ccD06-Sep-20246.4 KiB193152

sequence_manager.hD06-Sep-202414.9 KiB382184

sequence_manager_impl.ccD06-Sep-202445.4 KiB1,221925

sequence_manager_impl.hD06-Sep-202420 KiB500295

sequence_manager_impl_unittest.ccD06-Sep-2024192.4 KiB5,4624,106

sequence_manager_perftest.ccD06-Sep-202423.2 KiB728565

sequenced_task_source.ccD06-Sep-2024842 2818

sequenced_task_source.hD06-Sep-20243.4 KiB9452

task_order.ccD06-Sep-20242.8 KiB9057

task_order.hD06-Sep-20243.4 KiB9243

task_order_unittest.ccD06-Sep-20244.2 KiB130102

task_queue.ccD06-Sep-20242.9 KiB10680

task_queue.hD06-Sep-202417.7 KiB447206

task_queue_impl.ccD06-Sep-202459.7 KiB1,6101,205

task_queue_impl.hD06-Sep-202424.6 KiB621363

task_queue_selector.ccD06-Sep-202410.3 KiB293229

task_queue_selector.hD06-Sep-20249.5 KiB266162

task_queue_selector_unittest.ccD06-Sep-202424.2 KiB647515

task_queue_unittest.ccD06-Sep-20246.7 KiB187110

task_time_observer.hD06-Sep-2024977 3217

tasks.ccD06-Sep-20244.7 KiB152123

tasks.hD06-Sep-20246.5 KiB180110

thread_controller.ccD06-Sep-202419.7 KiB534357

thread_controller.hD06-Sep-202418.3 KiB451203

thread_controller_impl.ccD06-Sep-202413.6 KiB378267

thread_controller_impl.hD06-Sep-20244.9 KiB13495

thread_controller_power_monitor.ccD06-Sep-20243 KiB9560

thread_controller_power_monitor.hD06-Sep-20242 KiB5829

thread_controller_power_monitor_unittest.ccD06-Sep-20242.1 KiB6647

thread_controller_with_message_pump_impl.ccD06-Sep-202428.2 KiB742503

thread_controller_with_message_pump_impl.hD06-Sep-20248.3 KiB223142

thread_controller_with_message_pump_impl_unittest.ccD06-Sep-202481.9 KiB2,0901,464

time_domain.ccD06-Sep-2024827 3221

time_domain.hD06-Sep-20242.2 KiB7038

wake_up_queue.ccD06-Sep-20247.1 KiB192131

wake_up_queue.hD06-Sep-20245.2 KiB15592

wake_up_queue_unittest.ccD06-Sep-202420.3 KiB523400

work_deduplicator.ccD06-Sep-20243 KiB7955

work_deduplicator.hD06-Sep-20245.8 KiB14646

work_deduplicator_unittest.ccD06-Sep-20248.3 KiB220169

work_queue.ccD06-Sep-202410.4 KiB331230

work_queue.hD06-Sep-20246.7 KiB18778

work_queue_sets.ccD06-Sep-20248.3 KiB228195

work_queue_sets.hD06-Sep-20244.6 KiB15691

work_queue_sets_unittest.ccD06-Sep-202418.8 KiB520431

work_queue_unittest.ccD06-Sep-202422.9 KiB650514

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