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

Unified Diff: base/memory/weak_ptr.h

Issue 10690080: Rename/re-comment tests and added new death tests for WeakPtr (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 5 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 | base/memory/weak_ptr_unittest.cc » ('j') | base/memory/weak_ptr_unittest.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « no previous file | base/memory/weak_ptr_unittest.cc » ('j') | base/memory/weak_ptr_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698