| OLD | NEW |
| 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 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 | 151 |
| 152 void BrowserThreadImpl::Init() { | 152 void BrowserThreadImpl::Init() { |
| 153 BrowserThreadGlobals& globals = g_globals.Get(); | 153 BrowserThreadGlobals& globals = g_globals.Get(); |
| 154 | 154 |
| 155 using base::subtle::AtomicWord; | 155 using base::subtle::AtomicWord; |
| 156 AtomicWord* storage = | 156 AtomicWord* storage = |
| 157 reinterpret_cast<AtomicWord*>(&globals.thread_delegates[identifier_]); | 157 reinterpret_cast<AtomicWord*>(&globals.thread_delegates[identifier_]); |
| 158 AtomicWord stored_pointer = base::subtle::NoBarrier_Load(storage); | 158 AtomicWord stored_pointer = base::subtle::NoBarrier_Load(storage); |
| 159 BrowserThreadDelegate* delegate = | 159 BrowserThreadDelegate* delegate = |
| 160 reinterpret_cast<BrowserThreadDelegate*>(stored_pointer); | 160 reinterpret_cast<BrowserThreadDelegate*>(stored_pointer); |
| 161 if (delegate) { | 161 if (delegate) |
| 162 delegate->Init(); | 162 delegate->Init(); |
| 163 message_loop()->PostTask(FROM_HERE, | |
| 164 base::Bind(&BrowserThreadDelegate::InitAsync, | |
| 165 // Delegate is expected to exist for the | |
| 166 // duration of the thread's lifetime | |
| 167 base::Unretained(delegate))); | |
| 168 } | |
| 169 } | 163 } |
| 170 | 164 |
| 171 // We disable optimizations for this block of functions so the compiler doesn't | 165 // We disable optimizations for this block of functions so the compiler doesn't |
| 172 // merge them all together. | 166 // merge them all together. |
| 173 MSVC_DISABLE_OPTIMIZE() | 167 MSVC_DISABLE_OPTIMIZE() |
| 174 MSVC_PUSH_DISABLE_WARNING(4748) | 168 MSVC_PUSH_DISABLE_WARNING(4748) |
| 175 | 169 |
| 176 NOINLINE void BrowserThreadImpl::UIThreadRun(base::MessageLoop* message_loop) { | 170 NOINLINE void BrowserThreadImpl::UIThreadRun(base::MessageLoop* message_loop) { |
| 177 volatile int line_number = __LINE__; | 171 volatile int line_number = __LINE__; |
| 178 Thread::Run(message_loop); | 172 Thread::Run(message_loop); |
| (...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 530 AtomicWord* storage = reinterpret_cast<AtomicWord*>( | 524 AtomicWord* storage = reinterpret_cast<AtomicWord*>( |
| 531 &globals.thread_delegates[identifier]); | 525 &globals.thread_delegates[identifier]); |
| 532 AtomicWord old_pointer = base::subtle::NoBarrier_AtomicExchange( | 526 AtomicWord old_pointer = base::subtle::NoBarrier_AtomicExchange( |
| 533 storage, reinterpret_cast<AtomicWord>(delegate)); | 527 storage, reinterpret_cast<AtomicWord>(delegate)); |
| 534 | 528 |
| 535 // This catches registration when previously registered. | 529 // This catches registration when previously registered. |
| 536 DCHECK(!delegate || !old_pointer); | 530 DCHECK(!delegate || !old_pointer); |
| 537 } | 531 } |
| 538 | 532 |
| 539 } // namespace content | 533 } // namespace content |
| OLD | NEW |