OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 Restart(); // reset IsQuitting() if the thread is being restarted | 221 Restart(); // reset IsQuitting() if the thread is being restarted |
222 | 222 |
223 // Make sure that ThreadManager is created on the main thread before | 223 // Make sure that ThreadManager is created on the main thread before |
224 // we start a new thread. | 224 // we start a new thread. |
225 ThreadManager::Instance(); | 225 ThreadManager::Instance(); |
226 | 226 |
227 ThreadInit* init = new ThreadInit; | 227 ThreadInit* init = new ThreadInit; |
228 init->thread = this; | 228 init->thread = this; |
229 init->runnable = runnable; | 229 init->runnable = runnable; |
230 #if defined(WEBRTC_WIN) | 230 #if defined(WEBRTC_WIN) |
231 thread_ = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)PreRun, init, 0, | 231 thread_ = CreateThread(NULL, 0, PreRun, init, 0, &thread_id_); |
232 &thread_id_); | |
233 if (thread_) { | 232 if (thread_) { |
234 running_.Set(); | 233 running_.Set(); |
235 } else { | 234 } else { |
236 return false; | 235 return false; |
237 } | 236 } |
238 #elif defined(WEBRTC_POSIX) | 237 #elif defined(WEBRTC_POSIX) |
239 pthread_attr_t attr; | 238 pthread_attr_t attr; |
240 pthread_attr_init(&attr); | 239 pthread_attr_init(&attr); |
241 | 240 |
242 int error_code = pthread_create(&thread_, &attr, PreRun, init); | 241 int error_code = pthread_create(&thread_, &attr, PreRun, init); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
301 } | 300 } |
302 | 301 |
303 // static | 302 // static |
304 void Thread::AssertBlockingIsAllowedOnCurrentThread() { | 303 void Thread::AssertBlockingIsAllowedOnCurrentThread() { |
305 #if !defined(NDEBUG) | 304 #if !defined(NDEBUG) |
306 Thread* current = Thread::Current(); | 305 Thread* current = Thread::Current(); |
307 RTC_DCHECK(!current || current->blocking_calls_allowed_); | 306 RTC_DCHECK(!current || current->blocking_calls_allowed_); |
308 #endif | 307 #endif |
309 } | 308 } |
310 | 309 |
| 310 // static |
| 311 #if defined(WEBRTC_WIN) |
| 312 DWORD WINAPI Thread::PreRun(LPVOID pv) { |
| 313 #else |
311 void* Thread::PreRun(void* pv) { | 314 void* Thread::PreRun(void* pv) { |
| 315 #endif |
312 ThreadInit* init = static_cast<ThreadInit*>(pv); | 316 ThreadInit* init = static_cast<ThreadInit*>(pv); |
313 ThreadManager::Instance()->SetCurrentThread(init->thread); | 317 ThreadManager::Instance()->SetCurrentThread(init->thread); |
314 rtc::SetCurrentThreadName(init->thread->name_.c_str()); | 318 rtc::SetCurrentThreadName(init->thread->name_.c_str()); |
315 #if __has_feature(objc_arc) | 319 #if __has_feature(objc_arc) |
316 @autoreleasepool | 320 @autoreleasepool |
317 #elif defined(WEBRTC_MAC) | 321 #elif defined(WEBRTC_MAC) |
318 // Make sure the new thread has an autoreleasepool | 322 // Make sure the new thread has an autoreleasepool |
319 ScopedAutoreleasePool pool; | 323 ScopedAutoreleasePool pool; |
320 #endif | 324 #endif |
321 { | 325 { |
322 if (init->runnable) { | 326 if (init->runnable) { |
323 init->runnable->Run(init->thread); | 327 init->runnable->Run(init->thread); |
324 } else { | 328 } else { |
325 init->thread->Run(); | 329 init->thread->Run(); |
326 } | 330 } |
327 delete init; | 331 delete init; |
328 return NULL; | 332 #ifdef WEBRTC_WIN |
| 333 return 0; |
| 334 #else |
| 335 return nullptr; |
| 336 #endif |
329 } | 337 } |
330 } | 338 } |
331 | 339 |
332 void Thread::Run() { | 340 void Thread::Run() { |
333 ProcessMessages(kForever); | 341 ProcessMessages(kForever); |
334 } | 342 } |
335 | 343 |
336 bool Thread::IsOwned() { | 344 bool Thread::IsOwned() { |
337 return owned_; | 345 return owned_; |
338 } | 346 } |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
559 if (SUCCEEDED(hr)) { | 567 if (SUCCEEDED(hr)) { |
560 Thread::Run(); | 568 Thread::Run(); |
561 CoUninitialize(); | 569 CoUninitialize(); |
562 } else { | 570 } else { |
563 LOG(LS_ERROR) << "CoInitialize failed, hr=" << hr; | 571 LOG(LS_ERROR) << "CoInitialize failed, hr=" << hr; |
564 } | 572 } |
565 } | 573 } |
566 #endif | 574 #endif |
567 | 575 |
568 } // namespace rtc | 576 } // namespace rtc |
OLD | NEW |