Index: webrtc/base/asyncinvoker.cc |
diff --git a/webrtc/base/asyncinvoker.cc b/webrtc/base/asyncinvoker.cc |
index 56f1a19d543bfeecc54b4ef7ffb7abbcb4400847..ee53e04184cf06cda4a674bcfec9bdf6e4a06666 100644 |
--- a/webrtc/base/asyncinvoker.cc |
+++ b/webrtc/base/asyncinvoker.cc |
@@ -10,6 +10,7 @@ |
#include "webrtc/base/asyncinvoker.h" |
+#include "webrtc/base/checks.h" |
#include "webrtc/base/logging.h" |
namespace rtc { |
@@ -76,6 +77,29 @@ void AsyncInvoker::DoInvokeDelayed(Thread* thread, |
new ScopedRefMessageData<AsyncClosure>(closure)); |
} |
+GuardedAsyncInvoker::GuardedAsyncInvoker() : thread_(Thread::Current()) { |
+ thread_->SignalQueueDestroyed.connect(this, |
+ &GuardedAsyncInvoker::ThreadDestroyed); |
+} |
+ |
+GuardedAsyncInvoker::~GuardedAsyncInvoker() { |
+} |
+ |
+bool GuardedAsyncInvoker::Flush(uint32 id) { |
+ rtc::CritScope cs(&crit_); |
+ if (thread_ == nullptr) |
+ return false; |
+ invoker_.Flush(thread_, id); |
+ return true; |
+} |
+ |
+void GuardedAsyncInvoker::ThreadDestroyed() { |
+ rtc::CritScope cs(&crit_); |
+ // We should never get more than one notification about the thread dying. |
+ DCHECK(thread_ != nullptr); |
+ thread_ = nullptr; |
+} |
+ |
NotifyingAsyncClosureBase::NotifyingAsyncClosureBase(AsyncInvoker* invoker, |
Thread* calling_thread) |
: invoker_(invoker), calling_thread_(calling_thread) { |