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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
88 using base::subtle::AtomicWord; | 88 using base::subtle::AtomicWord; |
89 AtomicWord* storage = | 89 AtomicWord* storage = |
90 reinterpret_cast<AtomicWord*>(&globals.thread_delegates[identifier_]); | 90 reinterpret_cast<AtomicWord*>(&globals.thread_delegates[identifier_]); |
91 AtomicWord stored_pointer = base::subtle::NoBarrier_Load(storage); | 91 AtomicWord stored_pointer = base::subtle::NoBarrier_Load(storage); |
92 BrowserThreadDelegate* delegate = | 92 BrowserThreadDelegate* delegate = |
93 reinterpret_cast<BrowserThreadDelegate*>(stored_pointer); | 93 reinterpret_cast<BrowserThreadDelegate*>(stored_pointer); |
94 if (delegate) | 94 if (delegate) |
95 delegate->Init(); | 95 delegate->Init(); |
96 } | 96 } |
97 | 97 |
98 // We disable optimizations for this block of functions so the compiler doesn't | |
99 // merge them all together. | |
100 // TODO(rtenneti): What is the equivalent for other compilers? | |
101 #if defined(COMPILER_MSVC) | |
sky
2012/07/23 15:49:17
Use MSVC_PUSH_DISABLE/POP_DISABLE to avoid the ifd
ramant (doing other things)
2012/07/23 17:33:04
Done.
| |
102 #pragma optimize("", off) | |
103 MSVC_PUSH_DISABLE_WARNING(4748) | |
104 #endif | |
105 | |
106 void BrowserThreadImpl::UIThreadRun(MessageLoop* message_loop) { | |
107 volatile int line_number = __LINE__; | |
sky
2012/07/23 15:49:17
Why do you need the line numbers on all these?
ramant (doing other things)
2012/07/23 17:33:04
Compilers could optimize away all *ThreadRun funct
| |
108 Thread::Run(message_loop); | |
109 CHECK_GT(line_number, 0); | |
110 } | |
111 | |
112 void BrowserThreadImpl::DBThreadRun(MessageLoop* message_loop) { | |
113 volatile int line_number = __LINE__; | |
114 Thread::Run(message_loop); | |
115 CHECK_GT(line_number, 0); | |
116 } | |
117 | |
118 void BrowserThreadImpl::WebKitThreadRun(MessageLoop* message_loop) { | |
119 volatile int line_number = __LINE__; | |
120 Thread::Run(message_loop); | |
121 CHECK_GT(line_number, 0); | |
122 } | |
123 | |
124 void BrowserThreadImpl::FileThreadRun(MessageLoop* message_loop) { | |
125 volatile int line_number = __LINE__; | |
126 Thread::Run(message_loop); | |
127 CHECK_GT(line_number, 0); | |
128 } | |
129 | |
130 void BrowserThreadImpl::FileUserBlockingThreadRun(MessageLoop* message_loop) { | |
131 volatile int line_number = __LINE__; | |
132 Thread::Run(message_loop); | |
133 CHECK_GT(line_number, 0); | |
134 } | |
135 | |
136 void BrowserThreadImpl::ProcessLauncherThreadRun(MessageLoop* message_loop) { | |
137 volatile int line_number = __LINE__; | |
138 Thread::Run(message_loop); | |
139 CHECK_GT(line_number, 0); | |
140 } | |
141 | |
142 void BrowserThreadImpl::CacheThreadRun(MessageLoop* message_loop) { | |
143 volatile int line_number = __LINE__; | |
144 Thread::Run(message_loop); | |
145 CHECK_GT(line_number, 0); | |
146 } | |
147 | |
148 void BrowserThreadImpl::IOThreadRun(MessageLoop* message_loop) { | |
149 volatile int line_number = __LINE__; | |
150 Thread::Run(message_loop); | |
151 CHECK_GT(line_number, 0); | |
152 } | |
153 | |
154 #if defined(COMPILER_MSVC) | |
155 MSVC_POP_WARNING() | |
156 #pragma optimize("", on) | |
157 #endif | |
158 | |
159 void BrowserThreadImpl::Run(MessageLoop* message_loop) { | |
160 BrowserThread::ID thread_id; | |
161 if (!GetCurrentThreadIdentifier(&thread_id)) | |
162 return Thread::Run(message_loop); | |
163 | |
164 switch (thread_id) { | |
165 case BrowserThread::UI: | |
166 return UIThreadRun(message_loop); | |
167 case BrowserThread::DB: | |
168 return DBThreadRun(message_loop); | |
169 case BrowserThread::WEBKIT_DEPRECATED: | |
170 return WebKitThreadRun(message_loop); | |
171 case BrowserThread::FILE: | |
172 return FileThreadRun(message_loop); | |
173 case BrowserThread::FILE_USER_BLOCKING: | |
174 return FileUserBlockingThreadRun(message_loop); | |
175 case BrowserThread::PROCESS_LAUNCHER: | |
176 return ProcessLauncherThreadRun(message_loop); | |
177 case BrowserThread::CACHE: | |
178 return CacheThreadRun(message_loop); | |
179 case BrowserThread::IO: | |
180 return IOThreadRun(message_loop); | |
181 case BrowserThread::ID_COUNT: | |
182 CHECK(false); // This shouldn't actually be reached! | |
183 break; | |
184 } | |
185 Thread::Run(message_loop); | |
186 } | |
187 | |
98 void BrowserThreadImpl::CleanUp() { | 188 void BrowserThreadImpl::CleanUp() { |
99 BrowserThreadGlobals& globals = g_globals.Get(); | 189 BrowserThreadGlobals& globals = g_globals.Get(); |
100 | 190 |
101 using base::subtle::AtomicWord; | 191 using base::subtle::AtomicWord; |
102 AtomicWord* storage = | 192 AtomicWord* storage = |
103 reinterpret_cast<AtomicWord*>(&globals.thread_delegates[identifier_]); | 193 reinterpret_cast<AtomicWord*>(&globals.thread_delegates[identifier_]); |
104 AtomicWord stored_pointer = base::subtle::NoBarrier_Load(storage); | 194 AtomicWord stored_pointer = base::subtle::NoBarrier_Load(storage); |
105 BrowserThreadDelegate* delegate = | 195 BrowserThreadDelegate* delegate = |
106 reinterpret_cast<BrowserThreadDelegate*>(stored_pointer); | 196 reinterpret_cast<BrowserThreadDelegate*>(stored_pointer); |
107 | 197 |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
376 AtomicWord* storage = reinterpret_cast<AtomicWord*>( | 466 AtomicWord* storage = reinterpret_cast<AtomicWord*>( |
377 &globals.thread_delegates[identifier]); | 467 &globals.thread_delegates[identifier]); |
378 AtomicWord old_pointer = base::subtle::NoBarrier_AtomicExchange( | 468 AtomicWord old_pointer = base::subtle::NoBarrier_AtomicExchange( |
379 storage, reinterpret_cast<AtomicWord>(delegate)); | 469 storage, reinterpret_cast<AtomicWord>(delegate)); |
380 | 470 |
381 // This catches registration when previously registered. | 471 // This catches registration when previously registered. |
382 DCHECK(!delegate || !old_pointer); | 472 DCHECK(!delegate || !old_pointer); |
383 } | 473 } |
384 | 474 |
385 } // namespace content | 475 } // namespace content |
OLD | NEW |