| Index: base/memory/weak_ptr.h
|
| diff --git a/base/memory/weak_ptr.h b/base/memory/weak_ptr.h
|
| index 0c6b4a70b46f3b06ef2bfab6b94cb7bc1b3da5e8..225c195d599d1e156dbef9616f076e02b6847e15 100644
|
| --- a/base/memory/weak_ptr.h
|
| +++ b/base/memory/weak_ptr.h
|
| @@ -55,6 +55,7 @@
|
| #include "base/base_api.h"
|
| #include "base/logging.h"
|
| #include "base/memory/ref_counted.h"
|
| +#include "base/synchronization/lock.h"
|
| #include "base/threading/thread_checker.h"
|
|
|
| namespace base {
|
| @@ -103,6 +104,7 @@ class BASE_API WeakReferenceOwner {
|
| WeakReference GetRef() const;
|
|
|
| bool HasRefs() const {
|
| + AutoLock auto_lock(lock_);
|
| return flag_ != NULL;
|
| }
|
|
|
| @@ -110,10 +112,14 @@ class BASE_API WeakReferenceOwner {
|
|
|
| // Indicates that this object will be used on another thread from now on.
|
| void DetachFromThread() {
|
| + AutoLock auto_lock(lock_);
|
| if (flag_) flag_->DetachFromThread();
|
| }
|
|
|
| private:
|
| + // Needs locking since WeakReference::Flag may be destroyed on a different
|
| + // thread.
|
| + mutable Lock lock_;
|
| mutable WeakReference::Flag* flag_;
|
| };
|
|
|
|
|