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

Unified Diff: base/memory/weak_ptr_unittest.cc

Issue 7677028: Make WeakPtr thread-safe, i.e. allow cross-thread copying of WeakPtr (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address comments, add a unit test Created 9 years, 4 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
« base/memory/weak_ptr.cc ('K') | « base/memory/weak_ptr.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/memory/weak_ptr_unittest.cc
diff --git a/base/memory/weak_ptr_unittest.cc b/base/memory/weak_ptr_unittest.cc
index c1a952634fd204615fa782a33b496bf173c13b06..77b629d35bcd52ccf615b9bc4a1c60a5a6dc7788 100644
--- a/base/memory/weak_ptr_unittest.cc
+++ b/base/memory/weak_ptr_unittest.cc
@@ -38,6 +38,14 @@ struct Derived : Base {};
struct Producer : SupportsWeakPtr<Producer> {};
struct Consumer { WeakPtr<Producer> producer; };
+struct Complex {
+ Complex() {
+ consumer.producer = producer.AsWeakPtr();
+ }
+ Producer producer;
+ Consumer consumer;
+};
+
} // namespace
TEST(WeakPtrTest, Basic) {
@@ -148,4 +156,14 @@ TEST(WeakPtrTest, SingleThreaded2) {
EXPECT_EQ(&producer, consumer->producer.get());
}
+TEST(WeakPtrTest, ReattachThread) {
+ // Test that we can move a class that supports weak references to another
+ // thread. This should work and not trip any runtime checks as long as
+ // there are no references in existence.
+ scoped_ptr<Complex> complex(OffThreadObjectCreator<Complex>::NewObject());
+ complex->consumer.producer.reset();
+ complex->consumer.producer = complex->producer.AsWeakPtr();
+ EXPECT_EQ(complex->consumer.producer.get(), &complex->producer);
+}
+
} // namespace base
« base/memory/weak_ptr.cc ('K') | « base/memory/weak_ptr.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698