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

Unified Diff: webrtc/rtc_base/asyncinvoker.h

Issue 2885143005: Fixing race between ~AsyncInvoker and ~AsyncClosure, using ref-counting. (Closed)
Patch Set: Only clear current thread's message queue in destructor loop Created 3 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 | « no previous file | webrtc/rtc_base/asyncinvoker.cc » ('j') | webrtc/rtc_base/asyncinvoker.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/rtc_base/asyncinvoker.h
diff --git a/webrtc/rtc_base/asyncinvoker.h b/webrtc/rtc_base/asyncinvoker.h
index 17d702a37bdce677636475f7f09cd52c5ffe9f1d..5ba270a6a361fc647f59c81b9a2a2587b6b99fde 100644
--- a/webrtc/rtc_base/asyncinvoker.h
+++ b/webrtc/rtc_base/asyncinvoker.h
@@ -18,6 +18,8 @@
#include "webrtc/rtc_base/bind.h"
#include "webrtc/rtc_base/constructormagic.h"
#include "webrtc/rtc_base/event.h"
+#include "webrtc/rtc_base/refcountedobject.h"
+#include "webrtc/rtc_base/scoped_ref_ptr.h"
#include "webrtc/rtc_base/sigslot.h"
#include "webrtc/rtc_base/thread.h"
@@ -119,8 +121,18 @@ class AsyncInvoker : public MessageHandler {
uint32_t delay_ms,
uint32_t id);
volatile int pending_invocations_ = 0;
- Event invocation_complete_;
- bool destroying_ = false;
+
+ // Reference counted so that if the AsyncInvoker destructor finishes before
+ // an AsyncClosure's destructor that's about to call
+ // "invocation_complete_->Set()", it's not dereferenced after being
+ // destroyed.
+ scoped_refptr<RefCountedObject<Event>> invocation_complete_;
kwiberg-webrtc 2017/08/04 09:28:09 Umm... isn't this exactly how scoped_refptr isn't
Taylor Brandstetter 2017/08/04 19:14:22 Sorry, I still don't understand what the problem i
kwiberg-webrtc 2017/08/06 04:17:12 No, it's just me who's confused. The requirements
+
+ // This flag is used to ensure that if an application AsyncInvokes tasks that
+ // recursively AsyncInvoke other tasks ad infinitum, the cycle eventually
+ // terminates.
kwiberg-webrtc 2017/08/04 09:28:09 That's why you need it. Could you also explain wha
+ int destroying_ = 0;
kwiberg-webrtc 2017/08/04 09:28:09 Ooohhh... when reading the .cc file, I found that
Taylor Brandstetter 2017/08/04 19:14:22 Oh, apparently <atomic> is a feature chromium allo
+
friend class AsyncClosure;
RTC_DISALLOW_COPY_AND_ASSIGN(AsyncInvoker);
@@ -149,7 +161,7 @@ class GuardedAsyncInvoker : public sigslot::has_slots<> {
bool AsyncInvoke(const Location& posted_from,
const FunctorT& functor,
uint32_t id = 0) {
- rtc::CritScope cs(&crit_);
+ CritScope cs(&crit_);
if (thread_ == nullptr)
return false;
invoker_.AsyncInvoke<ReturnT, FunctorT>(posted_from, thread_, functor, id);
@@ -163,7 +175,7 @@ class GuardedAsyncInvoker : public sigslot::has_slots<> {
const FunctorT& functor,
uint32_t delay_ms,
uint32_t id = 0) {
- rtc::CritScope cs(&crit_);
+ CritScope cs(&crit_);
if (thread_ == nullptr)
return false;
invoker_.AsyncInvokeDelayed<ReturnT, FunctorT>(posted_from, thread_,
@@ -180,7 +192,7 @@ class GuardedAsyncInvoker : public sigslot::has_slots<> {
void (HostT::*callback)(ReturnT),
HostT* callback_host,
uint32_t id = 0) {
- rtc::CritScope cs(&crit_);
+ CritScope cs(&crit_);
if (thread_ == nullptr)
return false;
invoker_.AsyncInvoke<ReturnT, FunctorT, HostT>(
@@ -198,7 +210,7 @@ class GuardedAsyncInvoker : public sigslot::has_slots<> {
void (HostT::*callback)(),
HostT* callback_host,
uint32_t id = 0) {
- rtc::CritScope cs(&crit_);
+ CritScope cs(&crit_);
if (thread_ == nullptr)
return false;
invoker_.AsyncInvoke<ReturnT, FunctorT, HostT>(
« no previous file with comments | « no previous file | webrtc/rtc_base/asyncinvoker.cc » ('j') | webrtc/rtc_base/asyncinvoker.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698