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

Side by Side Diff: content/browser/browser_thread_impl.cc

Issue 1011683002: Lazily initialize MessageLoop for faster thread startup (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #include "content/browser/browser_thread_impl.h" 5 #include "content/browser/browser_thread_impl.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/atomicops.h" 9 #include "base/atomicops.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 152
153 void BrowserThreadImpl::Init() { 153 void BrowserThreadImpl::Init() {
154 BrowserThreadGlobals& globals = g_globals.Get(); 154 BrowserThreadGlobals& globals = g_globals.Get();
155 155
156 using base::subtle::AtomicWord; 156 using base::subtle::AtomicWord;
157 AtomicWord* storage = 157 AtomicWord* storage =
158 reinterpret_cast<AtomicWord*>(&globals.thread_delegates[identifier_]); 158 reinterpret_cast<AtomicWord*>(&globals.thread_delegates[identifier_]);
159 AtomicWord stored_pointer = base::subtle::NoBarrier_Load(storage); 159 AtomicWord stored_pointer = base::subtle::NoBarrier_Load(storage);
160 BrowserThreadDelegate* delegate = 160 BrowserThreadDelegate* delegate =
161 reinterpret_cast<BrowserThreadDelegate*>(stored_pointer); 161 reinterpret_cast<BrowserThreadDelegate*>(stored_pointer);
162 if (delegate) { 162 if (delegate)
163 delegate->Init(); 163 delegate->Init();
164 message_loop()->PostTask(FROM_HERE,
165 base::Bind(&BrowserThreadDelegate::InitAsync,
166 // Delegate is expected to exist for the
167 // duration of the thread's lifetime
168 base::Unretained(delegate)));
169 }
170 } 164 }
171 165
172 // We disable optimizations for this block of functions so the compiler doesn't 166 // We disable optimizations for this block of functions so the compiler doesn't
173 // merge them all together. 167 // merge them all together.
174 MSVC_DISABLE_OPTIMIZE() 168 MSVC_DISABLE_OPTIMIZE()
175 MSVC_PUSH_DISABLE_WARNING(4748) 169 MSVC_PUSH_DISABLE_WARNING(4748)
176 170
177 NOINLINE void BrowserThreadImpl::UIThreadRun(base::MessageLoop* message_loop) { 171 NOINLINE void BrowserThreadImpl::UIThreadRun(base::MessageLoop* message_loop) {
178 volatile int line_number = __LINE__; 172 volatile int line_number = __LINE__;
179 Thread::Run(message_loop); 173 Thread::Run(message_loop);
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after
540 AtomicWord* storage = reinterpret_cast<AtomicWord*>( 534 AtomicWord* storage = reinterpret_cast<AtomicWord*>(
541 &globals.thread_delegates[identifier]); 535 &globals.thread_delegates[identifier]);
542 AtomicWord old_pointer = base::subtle::NoBarrier_AtomicExchange( 536 AtomicWord old_pointer = base::subtle::NoBarrier_AtomicExchange(
543 storage, reinterpret_cast<AtomicWord>(delegate)); 537 storage, reinterpret_cast<AtomicWord>(delegate));
544 538
545 // This catches registration when previously registered. 539 // This catches registration when previously registered.
546 DCHECK(!delegate || !old_pointer); 540 DCHECK(!delegate || !old_pointer);
547 } 541 }
548 542
549 } // namespace content 543 } // namespace content
OLDNEW
« no previous file with comments | « chrome/browser/sync/glue/sync_backend_registrar_unittest.cc ('k') | content/public/browser/browser_thread_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698