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

Unified Diff: webrtc/base/asyncinvoker-inl.h

Issue 2694723004: Making AsyncInvoker destructor thread-safe. (Closed)
Patch Set: Switch to MessageQueueManager::Clear, for when multiple threads are blocked. Created 3 years, 10 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-inl.h
diff --git a/webrtc/base/asyncinvoker-inl.h b/webrtc/base/asyncinvoker-inl.h
index 15fafa888b1fca715f28bb8b4161432f82f9e538..db5c2696e55df711c687d4dd0d5d0e264bd6ec49 100644
--- a/webrtc/base/asyncinvoker-inl.h
+++ b/webrtc/base/asyncinvoker-inl.h
@@ -11,6 +11,7 @@
#ifndef WEBRTC_BASE_ASYNCINVOKER_INL_H_
#define WEBRTC_BASE_ASYNCINVOKER_INL_H_
+#include "webrtc/base/atomicops.h"
#include "webrtc/base/bind.h"
#include "webrtc/base/callback.h"
#include "webrtc/base/criticalsection.h"
@@ -29,19 +30,23 @@ class AsyncInvoker;
// lifetime can be independent of AsyncInvoker.
class AsyncClosure : public RefCountInterface {
public:
+ explicit AsyncClosure(AsyncInvoker* invoker) : invoker_(invoker) {}
// Runs the asynchronous task, and triggers a callback to the calling
// thread if needed. Should be called from the target thread.
virtual void Execute() = 0;
protected:
- ~AsyncClosure() override {}
+ ~AsyncClosure() override;
+
+ AsyncInvoker* invoker_;
};
// Simple closure that doesn't trigger a callback for the calling thread.
template <class FunctorT>
class FireAndForgetAsyncClosure : public AsyncClosure {
public:
- explicit FireAndForgetAsyncClosure(const FunctorT& functor)
- : functor_(functor) {}
+ explicit FireAndForgetAsyncClosure(AsyncInvoker* invoker,
+ const FunctorT& functor)
+ : AsyncClosure(invoker), functor_(functor) {}
virtual void Execute() {
functor_();
}
@@ -69,7 +74,6 @@ class NotifyingAsyncClosureBase : public AsyncClosure,
bool CallbackCanceled() const { return calling_thread_ == NULL; }
private:
- AsyncInvoker* invoker_;
Location callback_posted_from_;
Callback0<void> callback_;
CriticalSection crit_;

Powered by Google App Engine
This is Rietveld 408576698