| OLD | NEW |
| 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/Member.h" | 9 #include "platform/heap/Member.h" |
| 9 #include "platform/heap/PersistentNode.h" | 10 #include "platform/heap/PersistentNode.h" |
| 11 #include "platform/heap/Visitor.h" |
| 10 #include "wtf/Allocator.h" | 12 #include "wtf/Allocator.h" |
| 11 #include "wtf/Atomics.h" | 13 #include "wtf/Atomics.h" |
| 12 | 14 |
| 13 namespace blink { | 15 namespace blink { |
| 14 | 16 |
| 15 // Marker used to annotate persistent objects and collections with, | 17 // Marker used to annotate persistent objects and collections with, |
| 16 // so as to enable reliable testing for persistent references via | 18 // so as to enable reliable testing for persistent references via |
| 17 // a type trait (see TypeTraits.h's IsPersistentReferenceType<>.) | 19 // a type trait (see TypeTraits.h's IsPersistentReferenceType<>.) |
| 18 #define IS_PERSISTENT_REFERENCE_TYPE() \ | 20 #define IS_PERSISTENT_REFERENCE_TYPE() \ |
| 19 public: \ | 21 public: \ |
| (...skipping 613 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 633 public: | 635 public: |
| 634 PersistentHeapDeque() { } | 636 PersistentHeapDeque() { } |
| 635 | 637 |
| 636 template<size_t otherCapacity> | 638 template<size_t otherCapacity> |
| 637 PersistentHeapDeque(const HeapDeque<T, otherCapacity>& other) | 639 PersistentHeapDeque(const HeapDeque<T, otherCapacity>& other) |
| 638 : PersistentHeapCollectionBase<HeapDeque<T, inlineCapacity>>(other) | 640 : PersistentHeapCollectionBase<HeapDeque<T, inlineCapacity>>(other) |
| 639 { | 641 { |
| 640 } | 642 } |
| 641 }; | 643 }; |
| 642 | 644 |
| 643 // Only a very reduced form of weak heap object references can currently be held | |
| 644 // by WTF::Closure<>s. i.e., bound as a 'this' pointer only. | |
| 645 // | |
| 646 // TODO(sof): once wtf/Functional.h is able to work over platform/heap/ types | |
| 647 // (like CrossThreadWeakPersistent<>), drop the restriction on weak persistent | |
| 648 // use by function closures (and rename this ad-hoc type.) | |
| 649 template<typename T> | |
| 650 class WeakPersistentThisPointer { | |
| 651 STACK_ALLOCATED(); | |
| 652 public: | |
| 653 explicit WeakPersistentThisPointer(T* value) : m_value(value) { } | |
| 654 WeakPersistent<T> value() const { return m_value; } | |
| 655 private: | |
| 656 WeakPersistent<T> m_value; | |
| 657 }; | |
| 658 | |
| 659 template<typename T> | |
| 660 class CrossThreadWeakPersistentThisPointer { | |
| 661 STACK_ALLOCATED(); | |
| 662 public: | |
| 663 explicit CrossThreadWeakPersistentThisPointer(T* value) : m_value(value) { } | |
| 664 CrossThreadWeakPersistent<T> value() const { return m_value; } | |
| 665 private: | |
| 666 CrossThreadWeakPersistent<T> m_value; | |
| 667 }; | |
| 668 | |
| 669 template <typename T> | 645 template <typename T> |
| 670 Persistent<T> wrapPersistent(T* value) | 646 Persistent<T> wrapPersistent(T* value) |
| 671 { | 647 { |
| 672 return Persistent<T>(value); | 648 return Persistent<T>(value); |
| 673 } | 649 } |
| 674 | 650 |
| 675 template <typename T> | 651 template <typename T> |
| 652 WeakPersistent<T> wrapWeakPersistent(T* value) |
| 653 { |
| 654 return WeakPersistent<T>(value); |
| 655 } |
| 656 |
| 657 template <typename T> |
| 676 CrossThreadPersistent<T> wrapCrossThreadPersistent(T* value) | 658 CrossThreadPersistent<T> wrapCrossThreadPersistent(T* value) |
| 677 { | 659 { |
| 678 return CrossThreadPersistent<T>(value); | 660 return CrossThreadPersistent<T>(value); |
| 679 } | 661 } |
| 680 | 662 |
| 663 template <typename T> |
| 664 CrossThreadWeakPersistent<T> wrapCrossThreadWeakPersistent(T* value) |
| 665 { |
| 666 return CrossThreadWeakPersistent<T>(value); |
| 667 } |
| 668 |
| 681 // Comparison operators between (Weak)Members, Persistents, and UntracedMembers. | 669 // Comparison operators between (Weak)Members, Persistents, and UntracedMembers. |
| 682 template<typename T, typename U> inline bool operator==(const Member<T>& a, cons
t Member<U>& b) { return a.get() == b.get(); } | 670 template<typename T, typename U> inline bool operator==(const Member<T>& a, cons
t Member<U>& b) { return a.get() == b.get(); } |
| 683 template<typename T, typename U> inline bool operator!=(const Member<T>& a, cons
t Member<U>& b) { return a.get() != b.get(); } | 671 template<typename T, typename U> inline bool operator!=(const Member<T>& a, cons
t Member<U>& b) { return a.get() != b.get(); } |
| 684 template<typename T, typename U> inline bool operator==(const Persistent<T>& a,
const Persistent<U>& b) { return a.get() == b.get(); } | 672 template<typename T, typename U> inline bool operator==(const Persistent<T>& a,
const Persistent<U>& b) { return a.get() == b.get(); } |
| 685 template<typename T, typename U> inline bool operator!=(const Persistent<T>& a,
const Persistent<U>& b) { return a.get() != b.get(); } | 673 template<typename T, typename U> inline bool operator!=(const Persistent<T>& a,
const Persistent<U>& b) { return a.get() != b.get(); } |
| 686 | 674 |
| 687 template<typename T, typename U> inline bool operator==(const Member<T>& a, cons
t Persistent<U>& b) { return a.get() == b.get(); } | 675 template<typename T, typename U> inline bool operator==(const Member<T>& a, cons
t Persistent<U>& b) { return a.get() == b.get(); } |
| 688 template<typename T, typename U> inline bool operator!=(const Member<T>& a, cons
t Persistent<U>& b) { return a.get() != b.get(); } | 676 template<typename T, typename U> inline bool operator!=(const Member<T>& a, cons
t Persistent<U>& b) { return a.get() != b.get(); } |
| 689 template<typename T, typename U> inline bool operator==(const Persistent<T>& a,
const Member<U>& b) { return a.get() == b.get(); } | 677 template<typename T, typename U> inline bool operator==(const Persistent<T>& a,
const Member<U>& b) { return a.get() == b.get(); } |
| 690 template<typename T, typename U> inline bool operator!=(const Persistent<T>& a,
const Member<U>& b) { return a.get() != b.get(); } | 678 template<typename T, typename U> inline bool operator!=(const Persistent<T>& a,
const Member<U>& b) { return a.get() != b.get(); } |
| (...skipping 19 matching lines...) Expand all Loading... |
| 710 STATIC_ONLY(DefaultHash); | 698 STATIC_ONLY(DefaultHash); |
| 711 using Hash = MemberHash<T>; | 699 using Hash = MemberHash<T>; |
| 712 }; | 700 }; |
| 713 | 701 |
| 714 template <typename T> | 702 template <typename T> |
| 715 struct DefaultHash<blink::CrossThreadWeakPersistent<T>> { | 703 struct DefaultHash<blink::CrossThreadWeakPersistent<T>> { |
| 716 STATIC_ONLY(DefaultHash); | 704 STATIC_ONLY(DefaultHash); |
| 717 using Hash = MemberHash<T>; | 705 using Hash = MemberHash<T>; |
| 718 }; | 706 }; |
| 719 | 707 |
| 720 template<typename T> | |
| 721 struct ParamStorageTraits<blink::WeakPersistentThisPointer<T>> { | |
| 722 STATIC_ONLY(ParamStorageTraits); | |
| 723 static_assert(sizeof(T), "T must be fully defined"); | |
| 724 using StorageType = blink::WeakPersistent<T>; | |
| 725 | |
| 726 static StorageType wrap(const blink::WeakPersistentThisPointer<T>& value) {
return value.value(); } | |
| 727 | |
| 728 // WTF::FunctionWrapper<> handles WeakPtr<>, so recast this weak persistent | |
| 729 // into it. | |
| 730 // | |
| 731 // TODO(sof): remove this hack once wtf/Functional.h can also work with a ty
pe like | |
| 732 // WeakPersistent<>. | |
| 733 static WeakPtr<T> unwrap(const StorageType& value) { return WeakPtr<T>(WeakR
eference<T>::create(value.get())); } | |
| 734 }; | |
| 735 | |
| 736 template<typename T> | |
| 737 struct ParamStorageTraits<blink::CrossThreadWeakPersistentThisPointer<T>> { | |
| 738 STATIC_ONLY(ParamStorageTraits); | |
| 739 static_assert(sizeof(T), "T must be fully defined"); | |
| 740 using StorageType = blink::CrossThreadWeakPersistent<T>; | |
| 741 | |
| 742 static StorageType wrap(const blink::CrossThreadWeakPersistentThisPointer<T>
& value) { return value.value(); } | |
| 743 | |
| 744 // WTF::FunctionWrapper<> handles WeakPtr<>, so recast this weak persistent | |
| 745 // into it. | |
| 746 // | |
| 747 // TODO(sof): remove this hack once wtf/Functional.h can also work with a ty
pe like | |
| 748 // CrossThreadWeakPersistent<>. | |
| 749 static WeakPtr<T> unwrap(const StorageType& value) { return WeakPtr<T>(WeakR
eference<T>::create(value.get())); } | |
| 750 }; | |
| 751 | |
| 752 } // namespace WTF | 708 } // namespace WTF |
| 753 | 709 |
| 710 namespace base { |
| 711 |
| 712 template <typename T> |
| 713 struct IsWeakReceiver<blink::WeakPersistent<T>> : std::true_type {}; |
| 714 |
| 715 template <typename T> |
| 716 struct IsWeakReceiver<blink::CrossThreadWeakPersistent<T>> : std::true_type {}; |
| 717 |
| 718 } |
| 719 |
| 754 #endif // Persistent_h | 720 #endif // Persistent_h |
| OLD | NEW |