|
Reland (3rd try): Lazily initialize MessageLoop for faster thread startup
Original review: https://codereview.chromium.org/1011683002/
2nd try: https://codereview.chromium.org/1129953004/
2nd try reverted due to race reports on Linux:
https://crbug.com/489263 Data races on valid_thread_id_ after r330329
This fixes:
- Race in MessageLoopProxyImpl by introducing lock
- Race in BrowserMainLoop/BrowserThreadImpl, where BrowserThread::CurrentlyOn()
called on one of BrowserThreads tries to touch other thread's message_loop()
via global thread table.
Reg: the latter race, the code flow that causes this race is like following:
// On the main thread, we create all known browser threads:
for (...) {
{
AutoLock lock(g_lock);
g_threads[id] = new BrowserProcessSubThread();
}
// [A] This initializes the thread's message_loop, which causes a race
// against [B] in the new code because new threads can start running
// immediately.
thread->StartWithOptions();
}
// On the new thread's main function, it calls CurrentlyOn() which does:
{
// [B] This touches other thread's Thread::message_loop.
AutoLock lock(g_lock);
return g_threads[other_thread_id] &&
g_threads[other_thread_id]->message_loop() == MessageLoop::current();
}
This was safe before because both message_loop initialization and the first
call to CurrentlyOn() on the new thread was done synchronously in
StartWithOptions() while the main thread was blocked. In the new code
new threads can start accessing message_loop() asynchronously while
the main thread's for loop is running.
PS1 is the original patch (2nd try) that got reverted.
BUG= 465458, 489263
Committed: https://crrev.com/7f68f8735355c1c73557c3cfb294b441901fc31d
Cr-Commit-Position: refs/heads/master@{#331235}
Total comments: 1
|
Unified diffs |
Side-by-side diffs |
Delta from patch set |
Stats (+300 lines, -181 lines) |
Patch |
 |
M |
base/message_loop/incoming_task_queue.h
|
View
|
|
3 chunks |
+10 lines, -0 lines |
0 comments
|
Download
|
 |
M |
base/message_loop/incoming_task_queue.cc
|
View
|
|
3 chunks |
+26 lines, -10 lines |
0 comments
|
Download
|
 |
M |
base/message_loop/message_loop.h
|
View
|
|
5 chunks |
+36 lines, -7 lines |
0 comments
|
Download
|
 |
M |
base/message_loop/message_loop.cc
|
View
|
|
4 chunks |
+47 lines, -33 lines |
0 comments
|
Download
|
 |
M |
base/message_loop/message_loop_proxy_impl.h
|
View
|
1
|
3 chunks |
+7 lines, -1 line |
0 comments
|
Download
|
 |
M |
base/message_loop/message_loop_proxy_impl.cc
|
View
|
1
|
2 chunks |
+8 lines, -1 line |
0 comments
|
Download
|
 |
M |
base/message_loop/message_pump_perftest.cc
|
View
|
|
3 chunks |
+0 lines, -5 lines |
0 comments
|
Download
|
 |
M |
base/threading/platform_thread.h
|
View
|
|
1 chunk |
+4 lines, -0 lines |
0 comments
|
Download
|
 |
M |
base/threading/platform_thread_win.cc
|
View
|
|
1 chunk |
+3 lines, -2 lines |
0 comments
|
Download
|
 |
M |
base/threading/thread.h
|
View
|
|
6 chunks |
+25 lines, -12 lines |
0 comments
|
Download
|
 |
M |
base/threading/thread.cc
|
View
|
|
7 chunks |
+93 lines, -81 lines |
0 comments
|
Download
|
 |
M |
base/threading/thread_id_name_manager_unittest.cc
|
View
|
|
3 chunks |
+6 lines, -6 lines |
0 comments
|
Download
|
 |
M |
base/threading/thread_unittest.cc
|
View
|
|
1 chunk |
+3 lines, -2 lines |
0 comments
|
Download
|
 |
M |
chrome/browser/io_thread.h
|
View
|
1
2
3
|
1 chunk |
+0 lines, -1 line |
0 comments
|
Download
|
 |
M |
chrome/browser/io_thread.cc
|
View
|
1
2
3
|
1 chunk |
+0 lines, -5 lines |
0 comments
|
Download
|
 |
M |
chrome/browser/metrics/thread_watcher_android_unittest.cc
|
View
|
1
2
3
|
1 chunk |
+1 line, -1 line |
0 comments
|
Download
|
 |
M |
chrome/browser/metrics/thread_watcher_unittest.cc
|
View
|
1
2
3
|
2 chunks |
+4 lines, -4 lines |
0 comments
|
Download
|
 |
M |
chrome/browser/sync/glue/sync_backend_registrar_unittest.cc
|
View
|
|
1 chunk |
+3 lines, -0 lines |
0 comments
|
Download
|
 |
M |
content/browser/browser_thread_impl.h
|
View
|
1
2
|
1 chunk |
+2 lines, -0 lines |
0 comments
|
Download
|
 |
M |
content/browser/browser_thread_impl.cc
|
View
|
1
2
|
2 chunks |
+10 lines, -7 lines |
0 comments
|
Download
|
 |
M |
content/public/browser/browser_thread_delegate.h
|
View
|
|
1 chunk |
+0 lines, -3 lines |
0 comments
|
Download
|
 |
M |
content/public/test/test_browser_thread.h
|
View
|
|
1 chunk |
+4 lines, -0 lines |
0 comments
|
Download
|
 |
M |
content/public/test/test_browser_thread.cc
|
View
|
|
1 chunk |
+4 lines, -0 lines |
0 comments
|
Download
|
 |
M |
net/android/network_change_notifier_android.cc
|
View
|
|
1 chunk |
+3 lines, -0 lines |
0 comments
|
Download
|
 |
M |
net/test/embedded_test_server/embedded_test_server.cc
|
View
|
|
1 chunk |
+1 line, -0 lines |
0 comments
|
Download
|
Total messages: 24 (15 generated)
|