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

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

Issue 1991623002: Avoid holding |incoming_queue_lock_| while waking up the message loop. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@base-rw-lock
Patch Set: Rebase Created 4 years, 7 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
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/macros.h" 9 #include "base/macros.h"
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
11 #include "base/pending_task.h" 11 #include "base/pending_task.h"
12 #include "base/synchronization/lock.h" 12 #include "base/synchronization/lock.h"
13 #include "base/synchronization/rw_lock.h"
13 #include "base/time/time.h" 14 #include "base/time/time.h"
14 15
15 namespace base { 16 namespace base {
16 17
17 class MessageLoop; 18 class MessageLoop;
18 class WaitableEvent; 19 class WaitableEvent;
19 20
20 namespace internal { 21 namespace internal {
21 22
22 // Implements a queue of tasks posted to the message loop running on the current 23 // Implements a queue of tasks posted to the message loop running on the current
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 void WillDestroyCurrentMessageLoop(); 56 void WillDestroyCurrentMessageLoop();
56 57
57 // This should be called when the message loop becomes ready for 58 // This should be called when the message loop becomes ready for
58 // scheduling work. 59 // scheduling work.
59 void StartScheduling(); 60 void StartScheduling();
60 61
61 private: 62 private:
62 friend class RefCountedThreadSafe<IncomingTaskQueue>; 63 friend class RefCountedThreadSafe<IncomingTaskQueue>;
63 virtual ~IncomingTaskQueue(); 64 virtual ~IncomingTaskQueue();
64 65
65 // Calculates the time at which a PendingTask should run.
66 TimeTicks CalculateDelayedRuntime(TimeDelta delay);
67
68 // Adds a task to |incoming_queue_|. The caller retains ownership of 66 // Adds a task to |incoming_queue_|. The caller retains ownership of
69 // |pending_task|, but this function will reset the value of 67 // |pending_task|, but this function will reset the value of
70 // |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
71 // does not retain |pending_task->task| beyond this function call. 69 // does not retain |pending_task->task| beyond this function call.
72 bool PostPendingTask(PendingTask* pending_task); 70 bool PostPendingTask(PendingTask* pending_task);
73 71
74 // Wakes up the message loop and schedules work.
75 void ScheduleWork();
76
77 // Number of tasks that require high resolution timing. This value is kept 72 // Number of tasks that require high resolution timing. This value is kept
78 // so that ReloadWorkQueue() completes in constant time. 73 // so that ReloadWorkQueue() completes in constant time.
79 int high_res_task_count_; 74 int high_res_task_count_;
80 75
81 // The lock that protects access to the members of this class. 76 // The lock that protects access to the members of this class, except
77 // |message_loop_|.
82 base::Lock incoming_queue_lock_; 78 base::Lock incoming_queue_lock_;
83 79
80 // Lock that protects |message_loop_| to prevent it from being deleted while a
81 // task a being posted.
danakj 2016/05/19 21:27:43 is being
Anand Mistry (off Chromium) 2016/05/20 04:45:38 Done.
82 base::RWLock message_loop_lock_;
83
84 // An incoming queue of tasks that are acquired under a mutex for processing 84 // An incoming queue of tasks that are acquired under a mutex for processing
85 // on this instance's thread. These tasks have not yet been been pushed to 85 // on this instance's thread. These tasks have not yet been been pushed to
86 // |message_loop_|. 86 // |message_loop_|.
87 TaskQueue incoming_queue_; 87 TaskQueue incoming_queue_;
88 88
89 // Points to the message loop that owns |this|. 89 // Points to the message loop that owns |this|.
90 MessageLoop* message_loop_; 90 MessageLoop* message_loop_;
91 91
92 // The next sequence number to use for delayed tasks. 92 // The next sequence number to use for delayed tasks.
93 int next_sequence_num_; 93 int next_sequence_num_;
94 94
95 // True if our message loop has already been scheduled and does not need to be 95 // True if our message loop has already been scheduled and does not need to be
96 // scheduled again until an empty reload occurs. 96 // scheduled again until an empty reload occurs.
97 bool message_loop_scheduled_; 97 bool message_loop_scheduled_;
98 98
99 // True if we always need to call ScheduleWork when receiving a new task, even 99 // True if we always need to call ScheduleWork when receiving a new task, even
100 // if the incoming queue was not empty. 100 // if the incoming queue was not empty.
101 const bool always_schedule_work_; 101 const bool always_schedule_work_;
102 102
103 // False until StartScheduling() is called. 103 // False until StartScheduling() is called.
104 bool is_ready_for_scheduling_; 104 bool is_ready_for_scheduling_;
105 105
106 DISALLOW_COPY_AND_ASSIGN(IncomingTaskQueue); 106 DISALLOW_COPY_AND_ASSIGN(IncomingTaskQueue);
107 }; 107 };
108 108
109 } // namespace internal 109 } // namespace internal
110 } // namespace base 110 } // namespace base
111 111
112 #endif // BASE_MESSAGE_LOOP_INCOMING_TASK_QUEUE_H_ 112 #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') | base/message_loop/incoming_task_queue.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698