Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: base/message_loop/incoming_task_queue.h

Issue 1647803004: Move base to DEPS (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/memory/weak_ptr_unittest.nc ('k') | base/message_loop/incoming_task_queue.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef BASE_MESSAGE_LOOP_INCOMING_TASK_QUEUE_H_
6 #define BASE_MESSAGE_LOOP_INCOMING_TASK_QUEUE_H_
7
8 #include "base/base_export.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/pending_task.h"
11 #include "base/synchronization/lock.h"
12 #include "base/time/time.h"
13
14 namespace base {
15
16 class MessageLoop;
17 class WaitableEvent;
18
19 namespace internal {
20
21 // Implements a queue of tasks posted to the message loop running on the current
22 // thread. This class takes care of synchronizing posting tasks from different
23 // threads and together with MessageLoop ensures clean shutdown.
24 class BASE_EXPORT IncomingTaskQueue
25 : public RefCountedThreadSafe<IncomingTaskQueue> {
26 public:
27 explicit IncomingTaskQueue(MessageLoop* message_loop);
28
29 // Appends a task to the incoming queue. Posting of all tasks is routed though
30 // AddToIncomingQueue() or TryAddToIncomingQueue() to make sure that posting
31 // task is properly synchronized between different threads.
32 //
33 // Returns true if the task was successfully added to the queue, otherwise
34 // returns false. In all cases, the ownership of |task| is transferred to the
35 // called method.
36 bool AddToIncomingQueue(const tracked_objects::Location& from_here,
37 const Closure& task,
38 TimeDelta delay,
39 bool nestable);
40
41 // Returns true if the queue contains tasks that require higher than default
42 // timer resolution. Currently only needed for Windows.
43 bool HasHighResolutionTasks();
44
45 // Returns true if the message loop is "idle". Provided for testing.
46 bool IsIdleForTesting();
47
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
50 // require high resolution timers.
51 int ReloadWorkQueue(TaskQueue* work_queue);
52
53 // Disconnects |this| from the parent message loop.
54 void WillDestroyCurrentMessageLoop();
55
56 // This should be called when the message loop becomes ready for
57 // scheduling work.
58 void StartScheduling();
59
60 private:
61 friend class RefCountedThreadSafe<IncomingTaskQueue>;
62 virtual ~IncomingTaskQueue();
63
64 // Calculates the time at which a PendingTask should run.
65 TimeTicks CalculateDelayedRuntime(TimeDelta delay);
66
67 // Adds a task to |incoming_queue_|. The caller retains ownership of
68 // |pending_task|, but this function will reset the value of
69 // |pending_task->task|. This is needed to ensure that the posting call stack
70 // does not retain |pending_task->task| beyond this function call.
71 bool PostPendingTask(PendingTask* pending_task);
72
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
77 // so that ReloadWorkQueue() completes in constant time.
78 int high_res_task_count_;
79
80 // The lock that protects access to the members of this class.
81 base::Lock incoming_queue_lock_;
82
83 // 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
85 // |message_loop_|.
86 TaskQueue incoming_queue_;
87
88 // Points to the message loop that owns |this|.
89 MessageLoop* message_loop_;
90
91 // The next sequence number to use for delayed tasks.
92 int next_sequence_num_;
93
94 // True if our message loop has already been scheduled and does not need to be
95 // scheduled again until an empty reload occurs.
96 bool message_loop_scheduled_;
97
98 // True if we always need to call ScheduleWork when receiving a new task, even
99 // if the incoming queue was not empty.
100 const bool always_schedule_work_;
101
102 // False until StartScheduling() is called.
103 bool is_ready_for_scheduling_;
104
105 DISALLOW_COPY_AND_ASSIGN(IncomingTaskQueue);
106 };
107
108 } // namespace internal
109 } // namespace base
110
111 #endif // BASE_MESSAGE_LOOP_INCOMING_TASK_QUEUE_H_
OLDNEW
« no previous file with comments | « base/memory/weak_ptr_unittest.nc ('k') | base/message_loop/incoming_task_queue.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698