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

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

Issue 2019423006: Adding more detail to MessageQueue::Dispatch logging. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Fixing one more place where RTC_FROM_HERE wasn't used. Created 4 years, 6 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
« no previous file with comments | « webrtc/base/asyncinvoker.h ('k') | webrtc/base/asyncinvoker-inl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2014 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2014 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 23 matching lines...) Expand all
34 34
35 // Execute the closure and trigger the return message if needed. 35 // Execute the closure and trigger the return message if needed.
36 closure->Execute(); 36 closure->Execute();
37 } 37 }
38 38
39 void AsyncInvoker::Flush(Thread* thread, uint32_t id /*= MQID_ANY*/) { 39 void AsyncInvoker::Flush(Thread* thread, uint32_t id /*= MQID_ANY*/) {
40 if (destroying_) return; 40 if (destroying_) return;
41 41
42 // Run this on |thread| to reduce the number of context switches. 42 // Run this on |thread| to reduce the number of context switches.
43 if (Thread::Current() != thread) { 43 if (Thread::Current() != thread) {
44 thread->Invoke<void>(Bind(&AsyncInvoker::Flush, this, thread, id)); 44 thread->Invoke<void>(RTC_FROM_HERE,
45 Bind(&AsyncInvoker::Flush, this, thread, id));
45 return; 46 return;
46 } 47 }
47 48
48 MessageList removed; 49 MessageList removed;
49 thread->Clear(this, id, &removed); 50 thread->Clear(this, id, &removed);
50 for (MessageList::iterator it = removed.begin(); it != removed.end(); ++it) { 51 for (MessageList::iterator it = removed.begin(); it != removed.end(); ++it) {
51 // This message was pending on this thread, so run it now. 52 // This message was pending on this thread, so run it now.
52 thread->Send(it->phandler, 53 thread->Send(it->posted_from, it->phandler, it->message_id, it->pdata);
53 it->message_id,
54 it->pdata);
55 } 54 }
56 } 55 }
57 56
58 void AsyncInvoker::DoInvoke(Thread* thread, 57 void AsyncInvoker::DoInvoke(const Location& posted_from,
58 Thread* thread,
59 const scoped_refptr<AsyncClosure>& closure, 59 const scoped_refptr<AsyncClosure>& closure,
60 uint32_t id) { 60 uint32_t id) {
61 if (destroying_) { 61 if (destroying_) {
62 LOG(LS_WARNING) << "Tried to invoke while destroying the invoker."; 62 LOG(LS_WARNING) << "Tried to invoke while destroying the invoker.";
63 return; 63 return;
64 } 64 }
65 thread->Post(this, id, new ScopedRefMessageData<AsyncClosure>(closure)); 65 thread->Post(posted_from, this, id,
66 new ScopedRefMessageData<AsyncClosure>(closure));
66 } 67 }
67 68
68 void AsyncInvoker::DoInvokeDelayed(Thread* thread, 69 void AsyncInvoker::DoInvokeDelayed(const Location& posted_from,
70 Thread* thread,
69 const scoped_refptr<AsyncClosure>& closure, 71 const scoped_refptr<AsyncClosure>& closure,
70 uint32_t delay_ms, 72 uint32_t delay_ms,
71 uint32_t id) { 73 uint32_t id) {
72 if (destroying_) { 74 if (destroying_) {
73 LOG(LS_WARNING) << "Tried to invoke while destroying the invoker."; 75 LOG(LS_WARNING) << "Tried to invoke while destroying the invoker.";
74 return; 76 return;
75 } 77 }
76 thread->PostDelayed(delay_ms, this, id, 78 thread->PostDelayed(posted_from, delay_ms, this, id,
77 new ScopedRefMessageData<AsyncClosure>(closure)); 79 new ScopedRefMessageData<AsyncClosure>(closure));
78 } 80 }
79 81
80 GuardedAsyncInvoker::GuardedAsyncInvoker() : thread_(Thread::Current()) { 82 GuardedAsyncInvoker::GuardedAsyncInvoker() : thread_(Thread::Current()) {
81 thread_->SignalQueueDestroyed.connect(this, 83 thread_->SignalQueueDestroyed.connect(this,
82 &GuardedAsyncInvoker::ThreadDestroyed); 84 &GuardedAsyncInvoker::ThreadDestroyed);
83 } 85 }
84 86
85 GuardedAsyncInvoker::~GuardedAsyncInvoker() { 87 GuardedAsyncInvoker::~GuardedAsyncInvoker() {
86 } 88 }
87 89
88 bool GuardedAsyncInvoker::Flush(uint32_t id) { 90 bool GuardedAsyncInvoker::Flush(uint32_t id) {
89 rtc::CritScope cs(&crit_); 91 rtc::CritScope cs(&crit_);
90 if (thread_ == nullptr) 92 if (thread_ == nullptr)
91 return false; 93 return false;
92 invoker_.Flush(thread_, id); 94 invoker_.Flush(thread_, id);
93 return true; 95 return true;
94 } 96 }
95 97
96 void GuardedAsyncInvoker::ThreadDestroyed() { 98 void GuardedAsyncInvoker::ThreadDestroyed() {
97 rtc::CritScope cs(&crit_); 99 rtc::CritScope cs(&crit_);
98 // We should never get more than one notification about the thread dying. 100 // We should never get more than one notification about the thread dying.
99 RTC_DCHECK(thread_ != nullptr); 101 RTC_DCHECK(thread_ != nullptr);
100 thread_ = nullptr; 102 thread_ = nullptr;
101 } 103 }
102 104
103 NotifyingAsyncClosureBase::NotifyingAsyncClosureBase(AsyncInvoker* invoker, 105 NotifyingAsyncClosureBase::NotifyingAsyncClosureBase(
104 Thread* calling_thread) 106 AsyncInvoker* invoker,
105 : invoker_(invoker), calling_thread_(calling_thread) { 107 const Location& callback_posted_from,
108 Thread* calling_thread)
109 : invoker_(invoker),
110 callback_posted_from_(callback_posted_from),
111 calling_thread_(calling_thread) {
106 calling_thread->SignalQueueDestroyed.connect( 112 calling_thread->SignalQueueDestroyed.connect(
107 this, &NotifyingAsyncClosureBase::CancelCallback); 113 this, &NotifyingAsyncClosureBase::CancelCallback);
108 invoker->SignalInvokerDestroyed.connect( 114 invoker->SignalInvokerDestroyed.connect(
109 this, &NotifyingAsyncClosureBase::CancelCallback); 115 this, &NotifyingAsyncClosureBase::CancelCallback);
110 } 116 }
111 117
112 NotifyingAsyncClosureBase::~NotifyingAsyncClosureBase() { 118 NotifyingAsyncClosureBase::~NotifyingAsyncClosureBase() {
113 disconnect_all(); 119 disconnect_all();
114 } 120 }
115 121
116 void NotifyingAsyncClosureBase::TriggerCallback() { 122 void NotifyingAsyncClosureBase::TriggerCallback() {
117 CritScope cs(&crit_); 123 CritScope cs(&crit_);
118 if (!CallbackCanceled() && !callback_.empty()) { 124 if (!CallbackCanceled() && !callback_.empty()) {
119 invoker_->AsyncInvoke<void>(calling_thread_, callback_); 125 invoker_->AsyncInvoke<void>(callback_posted_from_, calling_thread_,
126 callback_);
120 } 127 }
121 } 128 }
122 129
123 void NotifyingAsyncClosureBase::CancelCallback() { 130 void NotifyingAsyncClosureBase::CancelCallback() {
124 // If the callback is triggering when this is called, block the 131 // If the callback is triggering when this is called, block the
125 // destructor of the dying object here by waiting until the callback 132 // destructor of the dying object here by waiting until the callback
126 // is done triggering. 133 // is done triggering.
127 CritScope cs(&crit_); 134 CritScope cs(&crit_);
128 // calling_thread_ == NULL means do not trigger the callback. 135 // calling_thread_ == NULL means do not trigger the callback.
129 calling_thread_ = NULL; 136 calling_thread_ = NULL;
130 } 137 }
131 138
132 } // namespace rtc 139 } // namespace rtc
OLDNEW
« no previous file with comments | « webrtc/base/asyncinvoker.h ('k') | webrtc/base/asyncinvoker-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698