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 #include <algorithm> | 10 #include <algorithm> |
(...skipping 26 matching lines...) Expand all Loading... |
37 *locked_ = false; | 37 *locked_ = false; |
38 cs_->Leave(); | 38 cs_->Leave(); |
39 } | 39 } |
40 | 40 |
41 private: | 41 private: |
42 const CriticalSection* const cs_; | 42 const CriticalSection* const cs_; |
43 bool* locked_; | 43 bool* locked_; |
44 | 44 |
45 RTC_DISALLOW_COPY_AND_ASSIGN(DebugNonReentrantCritScope); | 45 RTC_DISALLOW_COPY_AND_ASSIGN(DebugNonReentrantCritScope); |
46 }; | 46 }; |
| 47 |
| 48 class FunctorPostMessageHandler : public MessageHandler { |
| 49 public: |
| 50 void OnMessage(Message* msg) override { |
| 51 RunnableData* data = static_cast<RunnableData*>(msg->pdata); |
| 52 data->Run(); |
| 53 delete data; |
| 54 } |
| 55 }; |
| 56 |
47 } // namespace | 57 } // namespace |
48 | 58 |
49 //------------------------------------------------------------------ | 59 //------------------------------------------------------------------ |
50 // MessageQueueManager | 60 // MessageQueueManager |
51 | 61 |
52 MessageQueueManager* MessageQueueManager::instance_ = nullptr; | 62 MessageQueueManager* MessageQueueManager::instance_ = nullptr; |
53 | 63 |
54 MessageQueueManager* MessageQueueManager::Instance() { | 64 MessageQueueManager* MessageQueueManager::Instance() { |
55 // Note: This is not thread safe, but it is first called before threads are | 65 // Note: This is not thread safe, but it is first called before threads are |
56 // spawned. | 66 // spawned. |
(...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
522 int64_t start_time = TimeMillis(); | 532 int64_t start_time = TimeMillis(); |
523 pmsg->phandler->OnMessage(pmsg); | 533 pmsg->phandler->OnMessage(pmsg); |
524 int64_t end_time = TimeMillis(); | 534 int64_t end_time = TimeMillis(); |
525 int64_t diff = TimeDiff(end_time, start_time); | 535 int64_t diff = TimeDiff(end_time, start_time); |
526 if (diff >= kSlowDispatchLoggingThreshold) { | 536 if (diff >= kSlowDispatchLoggingThreshold) { |
527 LOG(LS_INFO) << "Message took " << diff << "ms to dispatch. Posted from: " | 537 LOG(LS_INFO) << "Message took " << diff << "ms to dispatch. Posted from: " |
528 << pmsg->posted_from.ToString(); | 538 << pmsg->posted_from.ToString(); |
529 } | 539 } |
530 } | 540 } |
531 | 541 |
| 542 void MessageQueue::PostFunctorInternal(const Location& posted_from, |
| 543 RunnableData* message_data) { |
| 544 // Use static to ensure it outlives this scope. Safe since |
| 545 // FunctorPostMessageHandler keeps no state. |
| 546 static FunctorPostMessageHandler handler; |
| 547 Post(posted_from, &handler, 0, message_data); |
| 548 } |
| 549 |
532 } // namespace rtc | 550 } // namespace rtc |
OLD | NEW |