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

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, 6 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 | « 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/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/read_write_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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 // does not retain |pending_task->task| beyond this function call. 69 // does not retain |pending_task->task| beyond this function call.
69 bool PostPendingTask(PendingTask* pending_task); 70 bool PostPendingTask(PendingTask* pending_task);
70 71
71 // Wakes up the message loop and schedules work. 72 // Wakes up the message loop and schedules work.
72 void ScheduleWork(); 73 void ScheduleWork();
73 74
74 // Number of tasks that require high resolution timing. This value is kept 75 // Number of tasks that require high resolution timing. This value is kept
75 // so that ReloadWorkQueue() completes in constant time. 76 // so that ReloadWorkQueue() completes in constant time.
76 int high_res_task_count_; 77 int high_res_task_count_;
77 78
78 // The lock that protects access to the members of this class. 79 // The lock that protects access to the members of this class, except
80 // |message_loop_|.
79 base::Lock incoming_queue_lock_; 81 base::Lock incoming_queue_lock_;
80 82
83 // Lock that protects |message_loop_| to prevent it from being deleted while a
84 // task is being posted.
85 base::subtle::ReadWriteLock message_loop_lock_;
86
81 // An incoming queue of tasks that are acquired under a mutex for processing 87 // An incoming queue of tasks that are acquired under a mutex for processing
82 // on this instance's thread. These tasks have not yet been been pushed to 88 // on this instance's thread. These tasks have not yet been been pushed to
83 // |message_loop_|. 89 // |message_loop_|.
84 TaskQueue incoming_queue_; 90 TaskQueue incoming_queue_;
85 91
86 // Points to the message loop that owns |this|. 92 // Points to the message loop that owns |this|.
87 MessageLoop* message_loop_; 93 MessageLoop* message_loop_;
88 94
89 // The next sequence number to use for delayed tasks. 95 // The next sequence number to use for delayed tasks.
90 int next_sequence_num_; 96 int next_sequence_num_;
91 97
92 // True if our message loop has already been scheduled and does not need to be 98 // True if our message loop has already been scheduled and does not need to be
93 // scheduled again until an empty reload occurs. 99 // scheduled again until an empty reload occurs.
94 bool message_loop_scheduled_; 100 bool message_loop_scheduled_;
95 101
96 // True if we always need to call ScheduleWork when receiving a new task, even 102 // True if we always need to call ScheduleWork when receiving a new task, even
97 // if the incoming queue was not empty. 103 // if the incoming queue was not empty.
98 const bool always_schedule_work_; 104 const bool always_schedule_work_;
99 105
100 // False until StartScheduling() is called. 106 // False until StartScheduling() is called.
101 bool is_ready_for_scheduling_; 107 bool is_ready_for_scheduling_;
102 108
103 DISALLOW_COPY_AND_ASSIGN(IncomingTaskQueue); 109 DISALLOW_COPY_AND_ASSIGN(IncomingTaskQueue);
104 }; 110 };
105 111
106 } // namespace internal 112 } // namespace internal
107 } // namespace base 113 } // namespace base
108 114
109 #endif // BASE_MESSAGE_LOOP_INCOMING_TASK_QUEUE_H_ 115 #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