Chromium Code Reviews| Index: base/memory/weak_ptr.h |
| =================================================================== |
| --- base/memory/weak_ptr.h (revision 145398) |
| +++ base/memory/weak_ptr.h (working copy) |
| @@ -8,14 +8,17 @@ |
| // reference counting is not a good fit. |
| // |
| // Thread-safety notes: |
| -// When you get a WeakPtr (from a WeakPtrFactory or SupportsWeakPtr), |
| -// the WeakPtr becomes bound to the current thread. You may only |
| -// dereference the WeakPtr on that thread. However, it is safe to |
| -// destroy the WeakPtr object on another thread. |
| -// Since a WeakPtr object may be destroyed on a background thread, |
| -// querying WeakPtrFactory's HasWeakPtrs() method can be racy. |
| +// When you get a WeakPtr (from a WeakPtrFactory or SupportsWeakPtr), the |
| +// WeakPtr becomes bound to the current thread. You may only dereference the |
| +// WeakPtr on that thread. However, it is safe to destroy the WeakPtr object |
| +// on another thread. Since a WeakPtr object may be destroyed on a background |
| +// thread, querying WeakPtrFactory's HasWeakPtrs() method can be racy. |
| +// On the other hand, the object that supports WeakPtr (extends |
| +// SupportsWeakPtr) will be bound to the first thread that creates a WeakPtr |
| +// pointing to it, and can not be deleted from other threads unless all |
| +// WeakPtrs are deleted. To work around of this, call |
|
Ryan Sleevi
2012/07/10 00:06:44
nit: To work around this
kaiwang
2012/07/10 22:21:19
Done.
|
| +// SupportsWeakPtr::DetachFromThread(). |
|
Ryan Sleevi
2012/07/10 00:06:44
I'm not sure we should encourage calling DetachFro
kaiwang
2012/07/10 22:21:19
Changed the wording.
|
| // |
| -// |
| // A common alternative to weak pointers is to have the shared object hold a |
| // list of all referrers, and then when the shared object is destroyed, it |
| // calls a method on the referrers to tell them to drop their references. This |
| @@ -225,7 +228,8 @@ |
| friend class WeakPtrFactory<T>; |
| WeakPtr(const internal::WeakReference& ref, T* ptr) |
| - : WeakPtrBase(ref), ptr_(ptr) { |
| + : WeakPtrBase(ref), |
| + ptr_(ptr) { |
| } |
| // This pointer is only valid when ref_.is_valid() is true. Otherwise, its |