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

Unified Diff: webrtc/base/asyncinvoker.cc

Issue 1303443003: Add helper class GuardedAsyncInvoker to protect against thread dying (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: tommi@s comments Created 5 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webrtc/base/asyncinvoker.h ('k') | webrtc/base/thread_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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) {
« no previous file with comments | « webrtc/base/asyncinvoker.h ('k') | webrtc/base/thread_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698