| OLD | NEW |
| 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 18 matching lines...) Expand all Loading... |
| 29 ScopedRefMessageData<AsyncClosure>* data = | 29 ScopedRefMessageData<AsyncClosure>* data = |
| 30 static_cast<ScopedRefMessageData<AsyncClosure>*>(msg->pdata); | 30 static_cast<ScopedRefMessageData<AsyncClosure>*>(msg->pdata); |
| 31 scoped_refptr<AsyncClosure> closure = data->data(); | 31 scoped_refptr<AsyncClosure> closure = data->data(); |
| 32 delete msg->pdata; | 32 delete msg->pdata; |
| 33 msg->pdata = NULL; | 33 msg->pdata = NULL; |
| 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 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>(Bind(&AsyncInvoker::Flush, this, thread, id)); |
| 45 return; | 45 return; |
| 46 } | 46 } |
| 47 | 47 |
| 48 MessageList removed; | 48 MessageList removed; |
| 49 thread->Clear(this, id, &removed); | 49 thread->Clear(this, id, &removed); |
| 50 for (MessageList::iterator it = removed.begin(); it != removed.end(); ++it) { | 50 for (MessageList::iterator it = removed.begin(); it != removed.end(); ++it) { |
| 51 // This message was pending on this thread, so run it now. | 51 // This message was pending on this thread, so run it now. |
| 52 thread->Send(it->phandler, | 52 thread->Send(it->phandler, |
| 53 it->message_id, | 53 it->message_id, |
| 54 it->pdata); | 54 it->pdata); |
| 55 } | 55 } |
| 56 } | 56 } |
| 57 | 57 |
| 58 void AsyncInvoker::DoInvoke(Thread* thread, | 58 void AsyncInvoker::DoInvoke(Thread* thread, |
| 59 const scoped_refptr<AsyncClosure>& closure, | 59 const scoped_refptr<AsyncClosure>& closure, |
| 60 uint32 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(this, id, new ScopedRefMessageData<AsyncClosure>(closure)); |
| 66 } | 66 } |
| 67 | 67 |
| 68 void AsyncInvoker::DoInvokeDelayed(Thread* thread, | 68 void AsyncInvoker::DoInvokeDelayed(Thread* thread, |
| 69 const scoped_refptr<AsyncClosure>& closure, | 69 const scoped_refptr<AsyncClosure>& closure, |
| 70 uint32 delay_ms, | 70 uint32_t delay_ms, |
| 71 uint32 id) { | 71 uint32_t id) { |
| 72 if (destroying_) { | 72 if (destroying_) { |
| 73 LOG(LS_WARNING) << "Tried to invoke while destroying the invoker."; | 73 LOG(LS_WARNING) << "Tried to invoke while destroying the invoker."; |
| 74 return; | 74 return; |
| 75 } | 75 } |
| 76 thread->PostDelayed(delay_ms, this, id, | 76 thread->PostDelayed(delay_ms, this, id, |
| 77 new ScopedRefMessageData<AsyncClosure>(closure)); | 77 new ScopedRefMessageData<AsyncClosure>(closure)); |
| 78 } | 78 } |
| 79 | 79 |
| 80 GuardedAsyncInvoker::GuardedAsyncInvoker() : thread_(Thread::Current()) { | 80 GuardedAsyncInvoker::GuardedAsyncInvoker() : thread_(Thread::Current()) { |
| 81 thread_->SignalQueueDestroyed.connect(this, | 81 thread_->SignalQueueDestroyed.connect(this, |
| 82 &GuardedAsyncInvoker::ThreadDestroyed); | 82 &GuardedAsyncInvoker::ThreadDestroyed); |
| 83 } | 83 } |
| 84 | 84 |
| 85 GuardedAsyncInvoker::~GuardedAsyncInvoker() { | 85 GuardedAsyncInvoker::~GuardedAsyncInvoker() { |
| 86 } | 86 } |
| 87 | 87 |
| 88 bool GuardedAsyncInvoker::Flush(uint32 id) { | 88 bool GuardedAsyncInvoker::Flush(uint32_t id) { |
| 89 rtc::CritScope cs(&crit_); | 89 rtc::CritScope cs(&crit_); |
| 90 if (thread_ == nullptr) | 90 if (thread_ == nullptr) |
| 91 return false; | 91 return false; |
| 92 invoker_.Flush(thread_, id); | 92 invoker_.Flush(thread_, id); |
| 93 return true; | 93 return true; |
| 94 } | 94 } |
| 95 | 95 |
| 96 void GuardedAsyncInvoker::ThreadDestroyed() { | 96 void GuardedAsyncInvoker::ThreadDestroyed() { |
| 97 rtc::CritScope cs(&crit_); | 97 rtc::CritScope cs(&crit_); |
| 98 // We should never get more than one notification about the thread dying. | 98 // We should never get more than one notification about the thread dying. |
| (...skipping 24 matching lines...) Expand all Loading... |
| 123 void NotifyingAsyncClosureBase::CancelCallback() { | 123 void NotifyingAsyncClosureBase::CancelCallback() { |
| 124 // If the callback is triggering when this is called, block the | 124 // If the callback is triggering when this is called, block the |
| 125 // destructor of the dying object here by waiting until the callback | 125 // destructor of the dying object here by waiting until the callback |
| 126 // is done triggering. | 126 // is done triggering. |
| 127 CritScope cs(&crit_); | 127 CritScope cs(&crit_); |
| 128 // calling_thread_ == NULL means do not trigger the callback. | 128 // calling_thread_ == NULL means do not trigger the callback. |
| 129 calling_thread_ = NULL; | 129 calling_thread_ = NULL; |
| 130 } | 130 } |
| 131 | 131 |
| 132 } // namespace rtc | 132 } // namespace rtc |
| OLD | NEW |