• Home
Name Date Size #Lines LOC

..--

test/03-May-2024-726493

DIR_METADATAD03-May-202454 43

README.mdD03-May-20243.8 KiB6961

associated_thread_id.ccD03-May-20241.1 KiB3623

associated_thread_id.hD03-May-20243.1 KiB9245

atomic_flag_set.ccD03-May-20246.7 KiB214155

atomic_flag_set.hD03-May-20244.9 KiB14373

atomic_flag_set_unittest.ccD03-May-202411.6 KiB326256

delayed_task_handle_delegate.ccD03-May-20242 KiB7049

delayed_task_handle_delegate.hD03-May-20242 KiB6537

enqueue_order.hD03-May-20241.6 KiB6235

enqueue_order_generator.ccD03-May-2024504 1910

enqueue_order_generator.hD03-May-20241.2 KiB4326

fence.ccD03-May-20241.2 KiB4629

fence.hD03-May-20242 KiB6733

hierarchical_timing_wheel.ccD03-May-20242.6 KiB8458

hierarchical_timing_wheel.hD03-May-202415.9 KiB434246

hierarchical_timing_wheel_unittest.ccD03-May-202411.4 KiB303200

lazily_deallocated_deque.hD03-May-202410.4 KiB389266

lazily_deallocated_deque_unittest.ccD03-May-202411 KiB510371

sequence_manager.ccD03-May-20246.4 KiB193152

sequence_manager.hD03-May-202415.4 KiB398194

sequence_manager_impl.ccD03-May-202447 KiB1,263961

sequence_manager_impl.hD03-May-202420.9 KiB519303

sequence_manager_impl_unittest.ccD03-May-2024198.4 KiB5,6054,195

sequence_manager_perftest.ccD03-May-202423.2 KiB728565

sequenced_task_source.ccD03-May-2024842 2818

sequenced_task_source.hD03-May-20243.6 KiB9953

task_order.ccD03-May-20242.8 KiB9057

task_order.hD03-May-20243.4 KiB9243

task_order_unittest.ccD03-May-20244.2 KiB130102

task_queue.ccD03-May-20249.9 KiB325256

task_queue.hD03-May-202418.6 KiB477222

task_queue_impl.ccD03-May-202460.4 KiB1,6151,193

task_queue_impl.hD03-May-202425.1 KiB633350

task_queue_selector.ccD03-May-202410.4 KiB294230

task_queue_selector.hD03-May-20249.5 KiB266162

task_queue_selector_unittest.ccD03-May-202424.2 KiB647515

task_queue_unittest.ccD03-May-20247.5 KiB211128

task_time_observer.hD03-May-2024977 3217

tasks.ccD03-May-20244.7 KiB152123

tasks.hD03-May-20246.5 KiB180110

thread_controller.ccD03-May-202418.4 KiB498334

thread_controller.hD03-May-202418.3 KiB449202

thread_controller_impl.ccD03-May-202413.8 KiB385273

thread_controller_impl.hD03-May-20245 KiB13596

thread_controller_power_monitor.ccD03-May-20243 KiB9560

thread_controller_power_monitor.hD03-May-20242 KiB5829

thread_controller_power_monitor_unittest.ccD03-May-20242.1 KiB6647

thread_controller_with_message_pump_impl.ccD03-May-202428.6 KiB753513

thread_controller_with_message_pump_impl.hD03-May-20248.4 KiB225142

thread_controller_with_message_pump_impl_unittest.ccD03-May-202481.9 KiB2,0911,464

time_domain.ccD03-May-2024827 3221

time_domain.hD03-May-20242.4 KiB7238

timing_wheel.ccD03-May-20241.5 KiB4930

timing_wheel.hD03-May-20249.5 KiB260150

timing_wheel_unittest.ccD03-May-202411.3 KiB299200

wake_up_queue.ccD03-May-20247.1 KiB192131

wake_up_queue.hD03-May-20245.2 KiB15592

wake_up_queue_unittest.ccD03-May-202420.3 KiB523400

work_deduplicator.ccD03-May-20243 KiB7955

work_deduplicator.hD03-May-20245.8 KiB14646

work_deduplicator_unittest.ccD03-May-20248.3 KiB220169

work_queue.ccD03-May-202410.4 KiB331230

work_queue.hD03-May-20246.7 KiB18778

work_queue_sets.ccD03-May-20248.3 KiB228195

work_queue_sets.hD03-May-20244.6 KiB15691

work_queue_sets_unittest.ccD03-May-202418.8 KiB520431

work_queue_unittest.ccD03-May-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