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

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: Remove AttachToThread() functionality 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
Index: webrtc/base/asyncinvoker.cc
diff --git a/webrtc/base/asyncinvoker.cc b/webrtc/base/asyncinvoker.cc
index 56f1a19d543bfeecc54b4ef7ffb7abbcb4400847..5e300bd1a4898826215ecc076ebb1f36e034df16 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,25 @@ void AsyncInvoker::DoInvokeDelayed(Thread* thread,
new ScopedRefMessageData<AsyncClosure>(closure));
}
+GuardedAsyncInvoker::GuardedAsyncInvoker() : thread_(Thread::Current()) {
+ thread_->SignalQueueDestroyed.connect(this,
+ &GuardedAsyncInvoker::ThreadDestroyed);
+}
+
+GuardedAsyncInvoker::~GuardedAsyncInvoker() {
+}
+
+void GuardedAsyncInvoker::Flush(uint32 id) {
+ rtc::CritScope cs(&crit_);
+ if (thread_ != nullptr)
+ invoker_.Flush(thread_, id);
+}
+
+void GuardedAsyncInvoker::ThreadDestroyed() {
+ rtc::CritScope cs(&crit_);
+ thread_ = nullptr;
tommi (sloooow) - chröme 2015/08/19 20:01:54 should we DCHECK that thread_ is not nullptr first
magjed_webrtc 2015/08/20 10:28:33 Done.
+}
+
NotifyingAsyncClosureBase::NotifyingAsyncClosureBase(AsyncInvoker* invoker,
Thread* calling_thread)
: invoker_(invoker), calling_thread_(calling_thread) {

Powered by Google App Engine
This is Rietveld 408576698