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

Side by Side Diff: third_party/WebKit/Source/platform/heap/Persistent.h

Issue 2207333002: Support CrossThreadWeakPersistent PostTask on per thread heap enabled thread (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix Created 4 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 #ifndef Persistent_h 5 #ifndef Persistent_h
6 #define Persistent_h 6 #define Persistent_h
7 7
8 #include "platform/heap/Heap.h" 8 #include "platform/heap/Heap.h"
9 #include "platform/heap/Member.h" 9 #include "platform/heap/Member.h"
10 #include "platform/heap/PersistentNode.h" 10 #include "platform/heap/PersistentNode.h"
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 } 64 }
65 65
66 PersistentBase(const PersistentBase& other) : m_raw(other) 66 PersistentBase(const PersistentBase& other) : m_raw(other)
67 { 67 {
68 saveCreationThreadHeap(); 68 saveCreationThreadHeap();
69 initialize(); 69 initialize();
70 checkPointer(); 70 checkPointer();
71 } 71 }
72 72
73 template<typename U> 73 template<typename U>
74 PersistentBase(const PersistentBase<U, weaknessConfiguration, crossThreadnes sConfiguration>& other) : m_raw(other) 74 PersistentBase(const PersistentBase<U, weaknessConfiguration, crossThreadnes sConfiguration>& other)
75 { 75 {
76 saveCreationThreadHeap(); 76 saveCreationThreadHeap();
77 initialize(); 77 if (crossThreadnessConfiguration == CrossThreadPersistentConfiguration & & weaknessConfiguration == WeakPersistentConfiguration) {
78 CrossThreadPersistentRegion::LockScope persistentLock(ProcessHeap::c rossThreadPersistentRegion());
haraken 2016/08/18 13:15:31 I wonder why you need to add the LockScope here. I
keishi 2016/08/22 09:48:55 The original code sets m_raw then calls allocatePe
haraken 2016/08/22 13:59:59 I'd say that if that happens, it's a bug of the ca
79 m_raw = other;
80 initialize();
81 } else {
82 m_raw = other;
83 initialize();
84 }
78 checkPointer(); 85 checkPointer();
79 } 86 }
80 87
81 template<typename U> 88 template<typename U>
82 PersistentBase(const Member<U>& other) : m_raw(other) 89 PersistentBase(const Member<U>& other) : m_raw(other)
83 { 90 {
84 saveCreationThreadHeap(); 91 saveCreationThreadHeap();
85 initialize(); 92 initialize();
86 checkPointer(); 93 checkPointer();
87 } 94 }
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 137
131 PersistentBase& operator=(const PersistentBase& other) 138 PersistentBase& operator=(const PersistentBase& other)
132 { 139 {
133 assign(other); 140 assign(other);
134 return *this; 141 return *this;
135 } 142 }
136 143
137 template<typename U> 144 template<typename U>
138 PersistentBase& operator=(const PersistentBase<U, weaknessConfiguration, cro ssThreadnessConfiguration>& other) 145 PersistentBase& operator=(const PersistentBase<U, weaknessConfiguration, cro ssThreadnessConfiguration>& other)
139 { 146 {
140 assign(other); 147 if (crossThreadnessConfiguration == CrossThreadPersistentConfiguration & & weaknessConfiguration == WeakPersistentConfiguration) {
148 CrossThreadPersistentRegion::LockScope persistentLock(ProcessHeap::c rossThreadPersistentRegion());
149 assign(other);
150 } else {
151 assign(other);
152 }
141 return *this; 153 return *this;
142 } 154 }
143 155
144 template<typename U> 156 template<typename U>
145 PersistentBase& operator=(const Member<U>& other) 157 PersistentBase& operator=(const Member<U>& other)
146 { 158 {
147 assign(other); 159 assign(other);
148 return *this; 160 return *this;
149 } 161 }
150 162
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 } 421 }
410 422
411 template<typename U> 423 template<typename U>
412 WeakPersistent& operator=(const Member<U>& other) 424 WeakPersistent& operator=(const Member<U>& other)
413 { 425 {
414 Parent::operator=(other); 426 Parent::operator=(other);
415 return *this; 427 return *this;
416 } 428 }
417 }; 429 };
418 430
431 // Combines the behavior of CrossThreadPersistent and WeakPersistent.
432 template<typename T>
433 class CrossThreadWeakPersistent : public PersistentBase<T, WeakPersistentConfigu ration, CrossThreadPersistentConfiguration> {
434 typedef PersistentBase<T, WeakPersistentConfiguration, CrossThreadPersistent Configuration> Parent;
435 public:
436 CrossThreadWeakPersistent() : Parent() { }
437 CrossThreadWeakPersistent(std::nullptr_t) : Parent(nullptr) { }
438 CrossThreadWeakPersistent(T* raw) : Parent(raw) { }
439 CrossThreadWeakPersistent(T& raw) : Parent(raw) { }
440 CrossThreadWeakPersistent(const CrossThreadWeakPersistent& other) : Parent(o ther) { }
441 template<typename U>
442 CrossThreadWeakPersistent(const CrossThreadWeakPersistent<U>& other) : Paren t(other) { }
443 template<typename U>
444 CrossThreadWeakPersistent(const Member<U>& other) : Parent(other) { }
445 CrossThreadWeakPersistent(WTF::HashTableDeletedValueType x) : Parent(x) { }
446
447 template<typename U>
448 CrossThreadWeakPersistent& operator=(U* other)
449 {
450 Parent::operator=(other);
451 return *this;
452 }
453
454 CrossThreadWeakPersistent& operator=(std::nullptr_t)
455 {
456 Parent::operator=(nullptr);
457 return *this;
458 }
459
460 CrossThreadWeakPersistent& operator=(const CrossThreadWeakPersistent& other)
461 {
462 Parent::operator=(other);
463 return *this;
464 }
465
466 template<typename U>
467 CrossThreadWeakPersistent& operator=(const CrossThreadWeakPersistent<U>& oth er)
468 {
469 Parent::operator=(other);
470 return *this;
471 }
472
473 template<typename U>
474 CrossThreadWeakPersistent& operator=(const Member<U>& other)
475 {
476 Parent::operator=(other);
477 return *this;
478 }
479 };
480
419 // Unlike Persistent, we can destruct a CrossThreadPersistent in a thread 481 // Unlike Persistent, we can destruct a CrossThreadPersistent in a thread
420 // different from the construction thread. 482 // different from the construction thread.
421 template<typename T> 483 template<typename T>
422 class CrossThreadPersistent : public PersistentBase<T, NonWeakPersistentConfigur ation, CrossThreadPersistentConfiguration> { 484 class CrossThreadPersistent : public PersistentBase<T, NonWeakPersistentConfigur ation, CrossThreadPersistentConfiguration> {
423 typedef PersistentBase<T, NonWeakPersistentConfiguration, CrossThreadPersist entConfiguration> Parent; 485 typedef PersistentBase<T, NonWeakPersistentConfiguration, CrossThreadPersist entConfiguration> Parent;
424 public: 486 public:
425 CrossThreadPersistent() : Parent() { } 487 CrossThreadPersistent() : Parent() { }
426 CrossThreadPersistent(std::nullptr_t) : Parent(nullptr) { } 488 CrossThreadPersistent(std::nullptr_t) : Parent(nullptr) { }
427 CrossThreadPersistent(T* raw) : Parent(raw) { } 489 CrossThreadPersistent(T* raw) : Parent(raw) { }
428 CrossThreadPersistent(T& raw) : Parent(raw) { } 490 CrossThreadPersistent(T& raw) : Parent(raw) { }
429 CrossThreadPersistent(const CrossThreadPersistent& other) : Parent(other) { } 491 CrossThreadPersistent(const CrossThreadPersistent& other) : Parent(other) { }
430 template<typename U> 492 template<typename U>
431 CrossThreadPersistent(const CrossThreadPersistent<U>& other) : Parent(other) { } 493 CrossThreadPersistent(const CrossThreadPersistent<U>& other) : Parent(other) { }
432 template<typename U> 494 template<typename U>
495 CrossThreadPersistent(const CrossThreadWeakPersistent<U>& other) : Parent(ot her) { }
496 template<typename U>
433 CrossThreadPersistent(const Member<U>& other) : Parent(other) { } 497 CrossThreadPersistent(const Member<U>& other) : Parent(other) { }
434 CrossThreadPersistent(WTF::HashTableDeletedValueType x) : Parent(x) { } 498 CrossThreadPersistent(WTF::HashTableDeletedValueType x) : Parent(x) { }
435 499
436 T* atomicGet() { return Parent::atomicGet(); } 500 T* atomicGet() { return Parent::atomicGet(); }
437 501
438 template<typename U> 502 template<typename U>
439 CrossThreadPersistent& operator=(U* other) 503 CrossThreadPersistent& operator=(U* other)
440 { 504 {
441 Parent::operator=(other); 505 Parent::operator=(other);
442 return *this; 506 return *this;
(...skipping 16 matching lines...) Expand all
459 { 523 {
460 Parent::operator=(other); 524 Parent::operator=(other);
461 return *this; 525 return *this;
462 } 526 }
463 527
464 template<typename U> 528 template<typename U>
465 CrossThreadPersistent& operator=(const Member<U>& other) 529 CrossThreadPersistent& operator=(const Member<U>& other)
466 { 530 {
467 Parent::operator=(other); 531 Parent::operator=(other);
468 return *this; 532 return *this;
469 }
470 };
471
472 // Combines the behavior of CrossThreadPersistent and WeakPersistent.
473 template<typename T>
474 class CrossThreadWeakPersistent : public PersistentBase<T, WeakPersistentConfigu ration, CrossThreadPersistentConfiguration> {
475 typedef PersistentBase<T, WeakPersistentConfiguration, CrossThreadPersistent Configuration> Parent;
476 public:
477 CrossThreadWeakPersistent() : Parent() { }
478 CrossThreadWeakPersistent(std::nullptr_t) : Parent(nullptr) { }
479 CrossThreadWeakPersistent(T* raw) : Parent(raw) { }
480 CrossThreadWeakPersistent(T& raw) : Parent(raw) { }
481 CrossThreadWeakPersistent(const CrossThreadWeakPersistent& other) : Parent(o ther) { }
482 template<typename U>
483 CrossThreadWeakPersistent(const CrossThreadWeakPersistent<U>& other) : Paren t(other) { }
484 template<typename U>
485 CrossThreadWeakPersistent(const Member<U>& other) : Parent(other) { }
486
487 template<typename U>
488 CrossThreadWeakPersistent& operator=(U* other)
489 {
490 Parent::operator=(other);
491 return *this;
492 }
493
494 CrossThreadWeakPersistent& operator=(std::nullptr_t)
495 {
496 Parent::operator=(nullptr);
497 return *this;
498 }
499
500 CrossThreadWeakPersistent& operator=(const CrossThreadWeakPersistent& other)
501 {
502 Parent::operator=(other);
503 return *this;
504 }
505
506 template<typename U>
507 CrossThreadWeakPersistent& operator=(const CrossThreadWeakPersistent<U>& oth er)
508 {
509 Parent::operator=(other);
510 return *this;
511 }
512
513 template<typename U>
514 CrossThreadWeakPersistent& operator=(const Member<U>& other)
515 {
516 Parent::operator=(other);
517 return *this;
518 } 533 }
519 }; 534 };
520 535
521 template<typename Collection> 536 template<typename Collection>
522 class PersistentHeapCollectionBase : public Collection { 537 class PersistentHeapCollectionBase : public Collection {
523 // We overload the various new and delete operators with using the WTF Parti tionAllocator to ensure persistent 538 // We overload the various new and delete operators with using the WTF Parti tionAllocator to ensure persistent
524 // heap collections are always allocated off-heap. This allows persistent co llections to be used in 539 // heap collections are always allocated off-heap. This allows persistent co llections to be used in
525 // DEFINE_STATIC_LOCAL et. al. 540 // DEFINE_STATIC_LOCAL et. al.
526 WTF_USE_ALLOCATOR(PersistentHeapCollectionBase, WTF::PartitionAllocator); 541 WTF_USE_ALLOCATOR(PersistentHeapCollectionBase, WTF::PartitionAllocator);
527 IS_PERSISTENT_REFERENCE_TYPE(); 542 IS_PERSISTENT_REFERENCE_TYPE();
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
755 } // namespace WTF 770 } // namespace WTF
756 771
757 namespace base { 772 namespace base {
758 773
759 template <typename T> 774 template <typename T>
760 struct IsWeakReceiver<blink::WeakPersistent<T>> : std::true_type {}; 775 struct IsWeakReceiver<blink::WeakPersistent<T>> : std::true_type {};
761 776
762 template <typename T> 777 template <typename T>
763 struct IsWeakReceiver<blink::CrossThreadWeakPersistent<T>> : std::true_type {}; 778 struct IsWeakReceiver<blink::CrossThreadWeakPersistent<T>> : std::true_type {};
764 779
780 template <typename T>
781 blink::CrossThreadPersistent<T> Unwrap(const blink::CrossThreadWeakPersistent<T> & wrapped)
782 {
783 return blink::CrossThreadPersistent<T>(wrapped);
784 }
785
765 } 786 }
766 787
767 #endif // Persistent_h 788 #endif // Persistent_h
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698