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

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

Issue 395913006: High resolution timer fix for Windows (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: real fixes for review Created 6 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | 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
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 20 matching lines...) Expand all
31 // task is properly synchronized between different threads. 31 // task is properly synchronized between different threads.
32 // 32 //
33 // Returns true if the task was successfully added to the queue, otherwise 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 34 // returns false. In all cases, the ownership of |task| is transferred to the
35 // called method. 35 // called method.
36 bool AddToIncomingQueue(const tracked_objects::Location& from_here, 36 bool AddToIncomingQueue(const tracked_objects::Location& from_here,
37 const Closure& task, 37 const Closure& task,
38 TimeDelta delay, 38 TimeDelta delay,
39 bool nestable); 39 bool nestable);
40 40
41 // Returns true if the message loop has high resolution timers enabled. 41 // Returns true if the queue contains tasks that require higher than default
42 // Provided for testing. 42 // timer resolution. Currently only needed for Windows.
43 bool IsHighResolutionTimerEnabledForTesting(); 43 bool HasHighResolutionTasks();
44 44
45 // Returns true if the message loop is "idle". Provided for testing. 45 // Returns true if the message loop is "idle". Provided for testing.
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. 49 // from the thread that is running the loop. Returns the number of tasks that
50 void ReloadWorkQueue(TaskQueue* work_queue); 50 // require high resolution timers.
51 int ReloadWorkQueue(TaskQueue* work_queue);
51 52
52 // Disconnects |this| from the parent message loop. 53 // Disconnects |this| from the parent message loop.
53 void WillDestroyCurrentMessageLoop(); 54 void WillDestroyCurrentMessageLoop();
54 55
55 private: 56 private:
56 friend class RefCountedThreadSafe<IncomingTaskQueue>; 57 friend class RefCountedThreadSafe<IncomingTaskQueue>;
57 virtual ~IncomingTaskQueue(); 58 virtual ~IncomingTaskQueue();
58 59
59 // Calculates the time at which a PendingTask should run. 60 // Calculates the time at which a PendingTask should run.
60 TimeTicks CalculateDelayedRuntime(TimeDelta delay); 61 TimeTicks CalculateDelayedRuntime(TimeDelta delay);
61 62
62 // Adds a task to |incoming_queue_|. The caller retains ownership of 63 // Adds a task to |incoming_queue_|. The caller retains ownership of
63 // |pending_task|, but this function will reset the value of 64 // |pending_task|, but this function will reset the value of
64 // |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
65 // does not retain |pending_task->task| beyond this function call. 66 // does not retain |pending_task->task| beyond this function call.
66 bool PostPendingTask(PendingTask* pending_task); 67 bool PostPendingTask(PendingTask* pending_task);
67 68
68 #if defined(OS_WIN) 69 // Number of tasks that require high resolution timing. This value is kept
69 TimeTicks high_resolution_timer_expiration_; 70 // so that ReloadWorkQueue() completes in constant time.
70 #endif 71 int high_res_task_count_;
71 72
72 // The lock that protects access to |incoming_queue_|, |message_loop_| and 73 // The lock that protects access to the members of this class.
darin (slow to review) 2014/07/19 04:06:57 micro-nit: How about listing the lock as the first
73 // |next_sequence_num_|.
74 base::Lock incoming_queue_lock_; 74 base::Lock incoming_queue_lock_;
75 75
76 // 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
77 // 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
78 // |message_loop_|. 78 // |message_loop_|.
79 TaskQueue incoming_queue_; 79 TaskQueue incoming_queue_;
80 80
81 // Points to the message loop that owns |this|. 81 // Points to the message loop that owns |this|.
82 MessageLoop* message_loop_; 82 MessageLoop* message_loop_;
83 83
84 // The next sequence number to use for delayed tasks. 84 // The next sequence number to use for delayed tasks.
85 int next_sequence_num_; 85 int next_sequence_num_;
86 86
87 DISALLOW_COPY_AND_ASSIGN(IncomingTaskQueue); 87 DISALLOW_COPY_AND_ASSIGN(IncomingTaskQueue);
88 }; 88 };
89 89
90 } // namespace internal 90 } // namespace internal
91 } // namespace base 91 } // namespace base
92 92
93 #endif // BASE_MESSAGE_LOOP_INCOMING_TASK_QUEUE_H_ 93 #endif // BASE_MESSAGE_LOOP_INCOMING_TASK_QUEUE_H_
OLDNEW
« no previous file with comments | « no previous file | base/message_loop/incoming_task_queue.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698