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

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

Issue 19522006: GLInProcessContext: support async flushes and dedicated GPU thread (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix linker error w/android component build Created 7 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/memory/weak_ptr.h ('k') | gpu/command_buffer/client/gl_in_process_context.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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/weak_ptr.h" 5 #include "base/memory/weak_ptr.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/debug/leak_annotations.h" 10 #include "base/debug/leak_annotations.h"
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 329
330 // The new WeakPtr is owned by background thread. 330 // The new WeakPtr is owned by background thread.
331 EXPECT_EQ(target, background.DeRef(&arrow)); 331 EXPECT_EQ(target, background.DeRef(&arrow));
332 } 332 }
333 333
334 // Target can only be deleted on background thread. 334 // Target can only be deleted on background thread.
335 background.DeleteTarget(target); 335 background.DeleteTarget(target);
336 background.DeleteArrow(arrow); 336 background.DeleteArrow(arrow);
337 } 337 }
338 338
339 TEST(WeakPtrTest, MoveOwnershipExplicitlyObjectNotReferenced) {
340 // Case 1: The target is not bound to any thread yet. So calling
341 // DetachFromThread() is a no-op.
342 Target target;
343 target.DetachFromThreadHack();
344
345 // Case 2: The target is bound to main thread but no WeakPtr is pointing to
346 // it. In this case, it will be re-bound to any thread trying to get a
347 // WeakPtr pointing to it. So detach function call is again no-op.
348 {
349 WeakPtr<Target> weak_ptr = target.AsWeakPtr();
350 }
351 target.DetachFromThreadHack();
352 }
353
354 TEST(WeakPtrTest, MoveOwnershipExplicitly) { 339 TEST(WeakPtrTest, MoveOwnershipExplicitly) {
355 BackgroundThread background; 340 BackgroundThread background;
356 background.Start(); 341 background.Start();
357 342
358 Arrow* arrow; 343 Arrow* arrow;
359 { 344 {
360 Target target; 345 Target target;
361 // Background thread creates WeakPtr(and implicitly owns the object). 346 // Background thread creates WeakPtr.
362 background.CreateArrowFromTarget(&arrow, &target); 347 background.CreateArrowFromTarget(&arrow, &target);
348
349 // Bind to background thread.
363 EXPECT_EQ(&target, background.DeRef(arrow)); 350 EXPECT_EQ(&target, background.DeRef(arrow));
364 351
365 // Detach from background thread. 352 // Invalidating the only weak pointer unbinds it from the background thread.
366 target.DetachFromThreadHack(); 353 arrow->target.reset();
Wez 2013/07/31 22:46:43 This should crash, since you're invalidating from
354 arrow->target = target.AsWeakPtr();
367 355
368 // Re-bind to main thread. 356 // Re-bind to main thread.
369 EXPECT_EQ(&target, arrow->target.get()); 357 EXPECT_EQ(&target, arrow->target.get());
370 358
371 // Main thread can now delete the target. 359 // Main thread can now delete the target.
372 } 360 }
373 361
374 // WeakPtr can be deleted on non-owner thread. 362 // WeakPtr can be deleted on non-owner thread.
375 background.DeleteArrow(arrow); 363 background.DeleteArrow(arrow);
376 } 364 }
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
582 background.Start(); 570 background.Start();
583 background.DeleteTarget(target.release()); 571 background.DeleteTarget(target.release());
584 572
585 // Main thread attempts to dereference the target, violating thread binding. 573 // Main thread attempts to dereference the target, violating thread binding.
586 ASSERT_DEATH(arrow.target.get(), ""); 574 ASSERT_DEATH(arrow.target.get(), "");
587 } 575 }
588 576
589 #endif 577 #endif
590 578
591 } // namespace base 579 } // namespace base
OLDNEW
« no previous file with comments | « base/memory/weak_ptr.h ('k') | gpu/command_buffer/client/gl_in_process_context.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698