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