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 |
11 #include "webrtc/base/thread.h" | 11 #include "webrtc/base/thread.h" |
12 | 12 |
13 #ifndef __has_feature | 13 #ifndef __has_feature |
14 #define __has_feature(x) 0 // Compatibility with non-clang or LLVM compilers. | 14 #define __has_feature(x) 0 // Compatibility with non-clang or LLVM compilers. |
15 #endif // __has_feature | 15 #endif // __has_feature |
16 | 16 |
17 #if defined(WEBRTC_WIN) | 17 #if defined(WEBRTC_WIN) |
18 #include <comdef.h> | 18 #include <comdef.h> |
19 #elif defined(WEBRTC_POSIX) | 19 #elif defined(WEBRTC_POSIX) |
20 #include <time.h> | 20 #include <time.h> |
21 #endif | 21 #endif |
22 | 22 |
23 #include "webrtc/base/common.h" | 23 #include "webrtc/base/common.h" |
24 #include "webrtc/base/logging.h" | 24 #include "webrtc/base/logging.h" |
25 #include "webrtc/base/nullsocketserver.h" | 25 #include "webrtc/base/nullsocketserver.h" |
26 #include "webrtc/base/platform_thread.h" | 26 #include "webrtc/base/platform_thread.h" |
27 #include "webrtc/base/stringutils.h" | 27 #include "webrtc/base/stringutils.h" |
28 #include "webrtc/base/timeutils.h" | 28 #include "webrtc/base/timeutils.h" |
| 29 #include "webrtc/base/trace_event.h" |
29 | 30 |
30 #if !__has_feature(objc_arc) && (defined(WEBRTC_MAC)) | 31 #if !__has_feature(objc_arc) && (defined(WEBRTC_MAC)) |
31 #include "webrtc/base/maccocoathreadhelper.h" | 32 #include "webrtc/base/maccocoathreadhelper.h" |
32 #include "webrtc/base/scoped_autorelease_pool.h" | 33 #include "webrtc/base/scoped_autorelease_pool.h" |
33 #endif | 34 #endif |
34 | 35 |
35 #include "webrtc/base/trace_event.h" | |
36 | |
37 namespace rtc { | 36 namespace rtc { |
38 | 37 |
39 ThreadManager* ThreadManager::Instance() { | 38 ThreadManager* ThreadManager::Instance() { |
40 RTC_DEFINE_STATIC_LOCAL(ThreadManager, thread_manager, ()); | 39 RTC_DEFINE_STATIC_LOCAL(ThreadManager, thread_manager, ()); |
41 return &thread_manager; | 40 return &thread_manager; |
42 } | 41 } |
43 | 42 |
44 // static | 43 // static |
45 Thread* Thread::Current() { | 44 Thread* Thread::Current() { |
46 return ThreadManager::Instance()->CurrentThread(); | 45 return ThreadManager::Instance()->CurrentThread(); |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 | 335 |
337 bool Thread::IsOwned() { | 336 bool Thread::IsOwned() { |
338 return owned_; | 337 return owned_; |
339 } | 338 } |
340 | 339 |
341 void Thread::Stop() { | 340 void Thread::Stop() { |
342 MessageQueue::Quit(); | 341 MessageQueue::Quit(); |
343 Join(); | 342 Join(); |
344 } | 343 } |
345 | 344 |
346 void Thread::Send(MessageHandler* phandler, uint32_t id, MessageData* pdata) { | 345 void Thread::Send(const Location& posted_from, |
| 346 MessageHandler* phandler, |
| 347 uint32_t id, |
| 348 MessageData* pdata) { |
347 if (fStop_) | 349 if (fStop_) |
348 return; | 350 return; |
349 | 351 |
350 // Sent messages are sent to the MessageHandler directly, in the context | 352 // Sent messages are sent to the MessageHandler directly, in the context |
351 // of "thread", like Win32 SendMessage. If in the right context, | 353 // of "thread", like Win32 SendMessage. If in the right context, |
352 // call the handler directly. | 354 // call the handler directly. |
353 Message msg; | 355 Message msg; |
| 356 msg.posted_from = posted_from; |
354 msg.phandler = phandler; | 357 msg.phandler = phandler; |
355 msg.message_id = id; | 358 msg.message_id = id; |
356 msg.pdata = pdata; | 359 msg.pdata = pdata; |
357 if (IsCurrent()) { | 360 if (IsCurrent()) { |
358 phandler->OnMessage(&msg); | 361 phandler->OnMessage(&msg); |
359 return; | 362 return; |
360 } | 363 } |
361 | 364 |
362 AssertBlockingIsAllowedOnCurrentThread(); | 365 AssertBlockingIsAllowedOnCurrentThread(); |
363 | 366 |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
437 it != sendlist_.end(); ++it) { | 440 it != sendlist_.end(); ++it) { |
438 if (it->thread == source || source == NULL) { | 441 if (it->thread == source || source == NULL) { |
439 *msg = *it; | 442 *msg = *it; |
440 sendlist_.erase(it); | 443 sendlist_.erase(it); |
441 return true; | 444 return true; |
442 } | 445 } |
443 } | 446 } |
444 return false; | 447 return false; |
445 } | 448 } |
446 | 449 |
447 void Thread::InvokeBegin() { | 450 void Thread::InvokeInternal(const Location& posted_from, |
448 TRACE_EVENT_BEGIN0("webrtc", "Thread::Invoke"); | 451 MessageHandler* handler) { |
449 } | 452 TRACE_EVENT2("webrtc", "Thread::Invoke", "src_file_and_line", |
450 | 453 posted_from.file_and_line(), "src_func", |
451 void Thread::InvokeEnd() { | 454 posted_from.function_name()); |
452 TRACE_EVENT_END0("webrtc", "Thread::Invoke"); | 455 Send(posted_from, handler); |
453 } | 456 } |
454 | 457 |
455 void Thread::Clear(MessageHandler* phandler, | 458 void Thread::Clear(MessageHandler* phandler, |
456 uint32_t id, | 459 uint32_t id, |
457 MessageList* removed) { | 460 MessageList* removed) { |
458 CritScope cs(&crit_); | 461 CritScope cs(&crit_); |
459 | 462 |
460 // Remove messages on sendlist_ with phandler | 463 // Remove messages on sendlist_ with phandler |
461 // Object target cleared: remove from send list, wakeup/set ready | 464 // Object target cleared: remove from send list, wakeup/set ready |
462 // if sender not NULL. | 465 // if sender not NULL. |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
556 if (SUCCEEDED(hr)) { | 559 if (SUCCEEDED(hr)) { |
557 Thread::Run(); | 560 Thread::Run(); |
558 CoUninitialize(); | 561 CoUninitialize(); |
559 } else { | 562 } else { |
560 LOG(LS_ERROR) << "CoInitialize failed, hr=" << hr; | 563 LOG(LS_ERROR) << "CoInitialize failed, hr=" << hr; |
561 } | 564 } |
562 } | 565 } |
563 #endif | 566 #endif |
564 | 567 |
565 } // namespace rtc | 568 } // namespace rtc |
OLD | NEW |