Chromium Code Reviews| 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>( |