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 the message loop becomes ready for | |
57 // scheduling work. | |
58 void StartScheduling(); | |
59 | |
60 private: | 56 private: |
61 friend class RefCountedThreadSafe<IncomingTaskQueue>; | 57 friend class RefCountedThreadSafe<IncomingTaskQueue>; |
62 virtual ~IncomingTaskQueue(); | 58 virtual ~IncomingTaskQueue(); |
63 | 59 |
64 // Calculates the time at which a PendingTask should run. | 60 // Calculates the time at which a PendingTask should run. |
65 TimeTicks CalculateDelayedRuntime(TimeDelta delay); | 61 TimeTicks CalculateDelayedRuntime(TimeDelta delay); |
66 | 62 |
67 // Adds a task to |incoming_queue_|. The caller retains ownership of | 63 // Adds a task to |incoming_queue_|. The caller retains ownership of |
68 // |pending_task|, but this function will reset the value of | 64 // |pending_task|, but this function will reset the value of |
69 // |pending_task->task|. This is needed to ensure that the posting call stack | 65 // |pending_task->task|. This is needed to ensure that the posting call stack |
70 // does not retain |pending_task->task| beyond this function call. | 66 // does not retain |pending_task->task| beyond this function call. |
71 bool PostPendingTask(PendingTask* pending_task); | 67 bool PostPendingTask(PendingTask* pending_task); |
72 | 68 |
73 // Wakes up the message loop and schedules work. | |
74 void ScheduleWork(); | |
75 | |
76 // Number of tasks that require high resolution timing. This value is kept | 69 // Number of tasks that require high resolution timing. This value is kept |
77 // so that ReloadWorkQueue() completes in constant time. | 70 // so that ReloadWorkQueue() completes in constant time. |
78 int high_res_task_count_; | 71 int high_res_task_count_; |
79 | 72 |
80 // The lock that protects access to the members of this class. | 73 // The lock that protects access to the members of this class. |
81 base::Lock incoming_queue_lock_; | 74 base::Lock incoming_queue_lock_; |
82 | 75 |
83 // An incoming queue of tasks that are acquired under a mutex for processing | 76 // An incoming queue of tasks that are acquired under a mutex for processing |
84 // on this instance's thread. These tasks have not yet been been pushed to | 77 // on this instance's thread. These tasks have not yet been been pushed to |
85 // |message_loop_|. | 78 // |message_loop_|. |
86 TaskQueue incoming_queue_; | 79 TaskQueue incoming_queue_; |
87 | 80 |
88 // Points to the message loop that owns |this|. | 81 // Points to the message loop that owns |this|. |
89 MessageLoop* message_loop_; | 82 MessageLoop* message_loop_; |
90 | 83 |
91 // The next sequence number to use for delayed tasks. | 84 // The next sequence number to use for delayed tasks. |
92 int next_sequence_num_; | 85 int next_sequence_num_; |
93 | 86 |
94 // True if our message loop has already been scheduled and does not need to be | 87 // True if our message loop has already been scheduled and does not need to be |
95 // scheduled again until an empty reload occurs. | 88 // scheduled again until an empty reload occurs. |
96 bool message_loop_scheduled_; | 89 bool message_loop_scheduled_; |
97 | 90 |
98 // True if we always need to call ScheduleWork when receiving a new task, even | 91 // True if we always need to call ScheduleWork when receiving a new task, even |
99 // if the incoming queue was not empty. | 92 // if the incoming queue was not empty. |
100 const bool always_schedule_work_; | 93 const bool always_schedule_work_; |
101 | 94 |
102 // False until StartScheduling() is called. | |
103 bool is_ready_for_scheduling_; | |
104 | |
105 DISALLOW_COPY_AND_ASSIGN(IncomingTaskQueue); | 95 DISALLOW_COPY_AND_ASSIGN(IncomingTaskQueue); |
106 }; | 96 }; |
107 | 97 |
108 } // namespace internal | 98 } // namespace internal |
109 } // namespace base | 99 } // namespace base |
110 | 100 |
111 #endif // BASE_MESSAGE_LOOP_INCOMING_TASK_QUEUE_H_ | 101 #endif // BASE_MESSAGE_LOOP_INCOMING_TASK_QUEUE_H_ |
OLD | NEW |