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