Index: base/callback_internal.cc |
diff --git a/base/callback_internal.cc b/base/callback_internal.cc |
index 4afd567f0fe32ee65c911f8a1cf55c061c7b95c3..c309a88c7363056a615e90ca5cf43355a6b2c94f 100644 |
--- a/base/callback_internal.cc |
+++ b/base/callback_internal.cc |
@@ -17,6 +17,10 @@ bool ReturnFalse(const BindStateBase*) { |
} // namespace |
+bool BindStateBase::HasOneRef() const { |
+ return AtomicRefCountIsOne(&ref_count_); |
+} |
+ |
BindStateBase::BindStateBase(InvokeFuncStorage polymorphic_invoke, |
void (*destructor)(const BindStateBase*)) |
: BindStateBase(polymorphic_invoke, destructor, &ReturnFalse) { |
@@ -26,12 +30,17 @@ BindStateBase::BindStateBase(InvokeFuncStorage polymorphic_invoke, |
void (*destructor)(const BindStateBase*), |
bool (*is_cancelled)(const BindStateBase*)) |
: polymorphic_invoke_(polymorphic_invoke), |
- ref_count_(0), |
+ ref_count_(1), |
destructor_(destructor), |
is_cancelled_(is_cancelled) {} |
void BindStateBase::AddRef() const { |
+#if DCHECK_IS_ON() |
+ AtomicRefCount ref_count = subtle::Barrier_AtomicIncrement(&ref_count_, 1); |
+ DCHECK_NE(1, ref_count); |
+#else |
AtomicRefCountInc(&ref_count_); |
+#endif |
} |
void BindStateBase::Release() const { |
@@ -70,9 +79,8 @@ bool CallbackBase<CopyMode::MoveOnly>::EqualsInternal( |
return bind_state_ == other.bind_state_; |
} |
-CallbackBase<CopyMode::MoveOnly>::CallbackBase( |
- BindStateBase* bind_state) |
- : bind_state_(bind_state) { |
+CallbackBase<CopyMode::MoveOnly>::CallbackBase(BindStateBase* bind_state) |
+ : bind_state_(AdoptRef(bind_state)) { |
DCHECK(!bind_state_.get() || bind_state_->ref_count_ == 1); |
} |