OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef BASE_MESSAGE_LOOP_INCOMING_TASK_QUEUE_H_ | 5 #ifndef BASE_MESSAGE_LOOP_INCOMING_TASK_QUEUE_H_ |
6 #define BASE_MESSAGE_LOOP_INCOMING_TASK_QUEUE_H_ | 6 #define BASE_MESSAGE_LOOP_INCOMING_TASK_QUEUE_H_ |
7 | 7 |
8 #include "base/base_export.h" | 8 #include "base/base_export.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/pending_task.h" | 10 #include "base/pending_task.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
46 bool IsIdleForTesting(); | 46 bool IsIdleForTesting(); |
47 | 47 |
48 // Loads tasks from the |incoming_queue_| into |*work_queue|. Must be called | 48 // Loads tasks from the |incoming_queue_| into |*work_queue|. Must be called |
49 // from the thread that is running the loop. Returns the number of tasks that | 49 // from the thread that is running the loop. Returns the number of tasks that |
50 // require high resolution timers. | 50 // require high resolution timers. |
51 int ReloadWorkQueue(TaskQueue* work_queue); | 51 int ReloadWorkQueue(TaskQueue* work_queue); |
52 | 52 |
53 // Disconnects |this| from the parent message loop. | 53 // Disconnects |this| from the parent message loop. |
54 void WillDestroyCurrentMessageLoop(); | 54 void WillDestroyCurrentMessageLoop(); |
55 | 55 |
56 // This should be called when it's ready for scheduling work. | |
Nico
2015/04/27 22:49:34
s/it/the message loop/
kinuko
2015/04/28 15:43:25
Done.
| |
57 void StartScheduling(); | |
58 | |
56 private: | 59 private: |
57 friend class RefCountedThreadSafe<IncomingTaskQueue>; | 60 friend class RefCountedThreadSafe<IncomingTaskQueue>; |
58 virtual ~IncomingTaskQueue(); | 61 virtual ~IncomingTaskQueue(); |
59 | 62 |
60 // Calculates the time at which a PendingTask should run. | 63 // Calculates the time at which a PendingTask should run. |
61 TimeTicks CalculateDelayedRuntime(TimeDelta delay); | 64 TimeTicks CalculateDelayedRuntime(TimeDelta delay); |
62 | 65 |
63 // Adds a task to |incoming_queue_|. The caller retains ownership of | 66 // Adds a task to |incoming_queue_|. The caller retains ownership of |
64 // |pending_task|, but this function will reset the value of | 67 // |pending_task|, but this function will reset the value of |
65 // |pending_task->task|. This is needed to ensure that the posting call stack | 68 // |pending_task->task|. This is needed to ensure that the posting call stack |
66 // does not retain |pending_task->task| beyond this function call. | 69 // does not retain |pending_task->task| beyond this function call. |
67 bool PostPendingTask(PendingTask* pending_task); | 70 bool PostPendingTask(PendingTask* pending_task); |
68 | 71 |
72 // Wakes up the message loop and schedules work. | |
73 void ScheduleWork(); | |
74 | |
69 // Number of tasks that require high resolution timing. This value is kept | 75 // Number of tasks that require high resolution timing. This value is kept |
70 // so that ReloadWorkQueue() completes in constant time. | 76 // so that ReloadWorkQueue() completes in constant time. |
71 int high_res_task_count_; | 77 int high_res_task_count_; |
72 | 78 |
73 // The lock that protects access to the members of this class. | 79 // The lock that protects access to the members of this class. |
74 base::Lock incoming_queue_lock_; | 80 base::Lock incoming_queue_lock_; |
75 | 81 |
76 // An incoming queue of tasks that are acquired under a mutex for processing | 82 // An incoming queue of tasks that are acquired under a mutex for processing |
77 // on this instance's thread. These tasks have not yet been been pushed to | 83 // on this instance's thread. These tasks have not yet been been pushed to |
78 // |message_loop_|. | 84 // |message_loop_|. |
79 TaskQueue incoming_queue_; | 85 TaskQueue incoming_queue_; |
80 | 86 |
81 // Points to the message loop that owns |this|. | 87 // Points to the message loop that owns |this|. |
82 MessageLoop* message_loop_; | 88 MessageLoop* message_loop_; |
83 | 89 |
84 // The next sequence number to use for delayed tasks. | 90 // The next sequence number to use for delayed tasks. |
85 int next_sequence_num_; | 91 int next_sequence_num_; |
86 | 92 |
87 // True if our message loop has already been scheduled and does not need to be | 93 // True if our message loop has already been scheduled and does not need to be |
88 // scheduled again until an empty reload occurs. | 94 // scheduled again until an empty reload occurs. |
89 bool message_loop_scheduled_; | 95 bool message_loop_scheduled_; |
90 | 96 |
91 // True if we always need to call ScheduleWork when receiving a new task, even | 97 // True if we always need to call ScheduleWork when receiving a new task, even |
92 // if the incoming queue was not empty. | 98 // if the incoming queue was not empty. |
93 const bool always_schedule_work_; | 99 const bool always_schedule_work_; |
94 | 100 |
101 // False until StartScheduling() is called. | |
102 bool is_ready_for_scheduling_; | |
103 | |
95 DISALLOW_COPY_AND_ASSIGN(IncomingTaskQueue); | 104 DISALLOW_COPY_AND_ASSIGN(IncomingTaskQueue); |
96 }; | 105 }; |
97 | 106 |
98 } // namespace internal | 107 } // namespace internal |
99 } // namespace base | 108 } // namespace base |
100 | 109 |
101 #endif // BASE_MESSAGE_LOOP_INCOMING_TASK_QUEUE_H_ | 110 #endif // BASE_MESSAGE_LOOP_INCOMING_TASK_QUEUE_H_ |
OLD | NEW |