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

Side by Side Diff: base/memory/weak_ptr_unittest.cc

Issue 8427007: Thread::Stop() must be called before any subclass's destructor completes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Latest version as trybot-ted Created 9 years, 1 month 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | base/threading/thread.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/memory/scoped_ptr.h" 5 #include "base/memory/scoped_ptr.h"
6 #include "base/memory/weak_ptr.h" 6 #include "base/memory/weak_ptr.h"
7 #include "testing/gtest/include/gtest/gtest.h" 7 #include "testing/gtest/include/gtest/gtest.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/synchronization/waitable_event.h" 9 #include "base/synchronization/waitable_event.h"
10 #include "base/threading/thread.h" 10 #include "base/threading/thread.h"
(...skipping 29 matching lines...) Expand all
40 struct Consumer { WeakPtr<Producer> producer; }; 40 struct Consumer { WeakPtr<Producer> producer; };
41 41
42 // Helper class to create and destroy weak pointer copies 42 // Helper class to create and destroy weak pointer copies
43 // and delete objects on a background thread. 43 // and delete objects on a background thread.
44 class BackgroundThread : public Thread { 44 class BackgroundThread : public Thread {
45 public: 45 public:
46 BackgroundThread() 46 BackgroundThread()
47 : Thread("owner_thread") { 47 : Thread("owner_thread") {
48 } 48 }
49 49
50 ~BackgroundThread() {
51 Stop();
52 }
53
50 void CreateConsumerFromProducer(Consumer** consumer, Producer* producer) { 54 void CreateConsumerFromProducer(Consumer** consumer, Producer* producer) {
51 WaitableEvent completion(true, false); 55 WaitableEvent completion(true, false);
52 message_loop()->PostTask( 56 message_loop()->PostTask(
53 FROM_HERE, 57 FROM_HERE,
54 NewRunnableFunction(&BackgroundThread::DoCreateFromProducer, 58 NewRunnableFunction(&BackgroundThread::DoCreateFromProducer,
55 consumer, 59 consumer,
56 producer, 60 producer,
57 &completion)); 61 &completion));
58 completion.Wait(); 62 completion.Wait();
59 } 63 }
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 Producer producer; 339 Producer producer;
336 Consumer consumer; 340 Consumer consumer;
337 consumer.producer = producer.AsWeakPtr(); 341 consumer.producer = producer.AsWeakPtr();
338 thread.CreateConsumerFromConsumer(&consumer_copy, &consumer); 342 thread.CreateConsumerFromConsumer(&consumer_copy, &consumer);
339 } 343 }
340 EXPECT_TRUE(consumer_copy->producer == NULL); 344 EXPECT_TRUE(consumer_copy->producer == NULL);
341 thread.DeleteConsumer(consumer_copy); 345 thread.DeleteConsumer(consumer_copy);
342 } 346 }
343 347
344 } // namespace base 348 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | base/threading/thread.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698