Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(80)

Side by Side Diff: webrtc/base/messagequeue.cc

Issue 2915253002: Delete SignalThread class. (Closed)
Patch Set: Implement Destroy logic, using new method MessageQueue::PostFunctor. Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 };
52
53 void FunctorPostMessageHandler::OnMessage(Message* msg) {
54 CallableData* data = static_cast<CallableData*>(msg->pdata);
55 data->call();
56 delete data;
57 }
kwiberg-webrtc 2017/06/26 13:07:48 Define this function inline? There's no downside t
nisse-webrtc 2017/06/27 08:27:17 Done.
58
47 } // namespace 59 } // namespace
48 60
49 //------------------------------------------------------------------ 61 //------------------------------------------------------------------
50 // MessageQueueManager 62 // MessageQueueManager
51 63
52 MessageQueueManager* MessageQueueManager::instance_ = nullptr; 64 MessageQueueManager* MessageQueueManager::instance_ = nullptr;
53 65
54 MessageQueueManager* MessageQueueManager::Instance() { 66 MessageQueueManager* MessageQueueManager::Instance() {
55 // Note: This is not thread safe, but it is first called before threads are 67 // Note: This is not thread safe, but it is first called before threads are
56 // spawned. 68 // spawned.
(...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 int64_t start_time = TimeMillis(); 534 int64_t start_time = TimeMillis();
523 pmsg->phandler->OnMessage(pmsg); 535 pmsg->phandler->OnMessage(pmsg);
524 int64_t end_time = TimeMillis(); 536 int64_t end_time = TimeMillis();
525 int64_t diff = TimeDiff(end_time, start_time); 537 int64_t diff = TimeDiff(end_time, start_time);
526 if (diff >= kSlowDispatchLoggingThreshold) { 538 if (diff >= kSlowDispatchLoggingThreshold) {
527 LOG(LS_INFO) << "Message took " << diff << "ms to dispatch. Posted from: " 539 LOG(LS_INFO) << "Message took " << diff << "ms to dispatch. Posted from: "
528 << pmsg->posted_from.ToString(); 540 << pmsg->posted_from.ToString();
529 } 541 }
530 } 542 }
531 543
544 void MessageQueue::PostFunctorInternal(const Location& posted_from,
545 CallableData* message_data)
546 {
tommi 2017/06/27 12:01:14 can you run git cl format?
nisse-webrtc 2017/06/28 11:47:54 Already done, in ps#14.
547 // FunctorPostMessageHandler keeps no state, create a static object.
548 RTC_DEFINE_STATIC_LOCAL(FunctorPostMessageHandler, handler, ());
kwiberg-webrtc 2017/06/26 13:07:48 Why not just FunctorPostMessageHandler handler;
nisse-webrtc 2017/06/27 08:27:17 It has to outlive this scope, since it's accessed
kwiberg-webrtc 2017/06/27 09:16:28 Ah, right, it has a vtable. But yes, as of C++11,
nisse-webrtc 2017/06/28 11:47:54 Good. But it still has to be in a local scope? (If
549 Post(posted_from, &handler, 0, message_data);
550 }
551
532 } // namespace rtc 552 } // namespace rtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698