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/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" |
11 #include "platform/heap/Visitor.h" | 11 #include "platform/heap/Visitor.h" |
12 #include "wtf/Allocator.h" | 12 #include "wtf/Allocator.h" |
13 #include "wtf/Atomics.h" | 13 #include "wtf/Atomics.h" |
| 14 #include "wtf/CrossThreadCopier.h" |
14 | 15 |
15 namespace blink { | 16 namespace blink { |
16 | 17 |
17 // Marker used to annotate persistent objects and collections with, | 18 // Marker used to annotate persistent objects and collections with, |
18 // so as to enable reliable testing for persistent references via | 19 // so as to enable reliable testing for persistent references via |
19 // a type trait (see TypeTraits.h's IsPersistentReferenceType<>.) | 20 // a type trait (see TypeTraits.h's IsPersistentReferenceType<>.) |
20 #define IS_PERSISTENT_REFERENCE_TYPE() \ | 21 #define IS_PERSISTENT_REFERENCE_TYPE() \ |
21 public: \ | 22 public: \ |
22 using IsPersistentReferenceTypeMarker = int; \ | 23 using IsPersistentReferenceTypeMarker = int; \ |
23 private: | 24 private: |
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
427 } | 428 } |
428 | 429 |
429 template<typename U> | 430 template<typename U> |
430 CrossThreadPersistent& operator=(const Member<U>& other) | 431 CrossThreadPersistent& operator=(const Member<U>& other) |
431 { | 432 { |
432 Parent::operator=(other); | 433 Parent::operator=(other); |
433 return *this; | 434 return *this; |
434 } | 435 } |
435 }; | 436 }; |
436 | 437 |
| 438 } // namespace blink |
| 439 |
| 440 namespace WTF { |
| 441 |
| 442 template<typename T> |
| 443 struct CrossThreadCopier<blink::CrossThreadPersistent<T>> : public CrossThreadCo
pierPassThrough<blink::CrossThreadPersistent<T>> { |
| 444 STATIC_ONLY(CrossThreadCopier); |
| 445 }; |
| 446 |
| 447 } // namespace WTF |
| 448 |
| 449 namespace blink { |
| 450 |
437 // Combines the behavior of CrossThreadPersistent and WeakPersistent. | 451 // Combines the behavior of CrossThreadPersistent and WeakPersistent. |
438 template<typename T> | 452 template<typename T> |
439 class CrossThreadWeakPersistent : public PersistentBase<T, WeakPersistentConfigu
ration, CrossThreadPersistentConfiguration> { | 453 class CrossThreadWeakPersistent : public PersistentBase<T, WeakPersistentConfigu
ration, CrossThreadPersistentConfiguration> { |
440 typedef PersistentBase<T, WeakPersistentConfiguration, CrossThreadPersistent
Configuration> Parent; | 454 typedef PersistentBase<T, WeakPersistentConfiguration, CrossThreadPersistent
Configuration> Parent; |
441 public: | 455 public: |
442 CrossThreadWeakPersistent() : Parent() { } | 456 CrossThreadWeakPersistent() : Parent() { } |
443 CrossThreadWeakPersistent(std::nullptr_t) : Parent(nullptr) { } | 457 CrossThreadWeakPersistent(std::nullptr_t) : Parent(nullptr) { } |
444 CrossThreadWeakPersistent(T* raw) : Parent(raw) { } | 458 CrossThreadWeakPersistent(T* raw) : Parent(raw) { } |
445 CrossThreadWeakPersistent(T& raw) : Parent(raw) { } | 459 CrossThreadWeakPersistent(T& raw) : Parent(raw) { } |
446 CrossThreadWeakPersistent(const CrossThreadWeakPersistent& other) : Parent(o
ther) { } | 460 CrossThreadWeakPersistent(const CrossThreadWeakPersistent& other) : Parent(o
ther) { } |
(...skipping 29 matching lines...) Expand all Loading... |
476 } | 490 } |
477 | 491 |
478 template<typename U> | 492 template<typename U> |
479 CrossThreadWeakPersistent& operator=(const Member<U>& other) | 493 CrossThreadWeakPersistent& operator=(const Member<U>& other) |
480 { | 494 { |
481 Parent::operator=(other); | 495 Parent::operator=(other); |
482 return *this; | 496 return *this; |
483 } | 497 } |
484 }; | 498 }; |
485 | 499 |
| 500 } // namespace blink |
| 501 |
| 502 namespace WTF { |
| 503 |
| 504 template<typename T> |
| 505 struct CrossThreadCopier<blink::CrossThreadWeakPersistent<T>> : public CrossThre
adCopierPassThrough<blink::CrossThreadWeakPersistent<T>> { |
| 506 STATIC_ONLY(CrossThreadCopier); |
| 507 }; |
| 508 |
| 509 } // namespace WTF |
| 510 |
| 511 namespace blink { |
| 512 |
486 template<typename Collection> | 513 template<typename Collection> |
487 class PersistentHeapCollectionBase : public Collection { | 514 class PersistentHeapCollectionBase : public Collection { |
488 // We overload the various new and delete operators with using the WTF Parti
tionAllocator to ensure persistent | 515 // We overload the various new and delete operators with using the WTF Parti
tionAllocator to ensure persistent |
489 // heap collections are always allocated off-heap. This allows persistent co
llections to be used in | 516 // heap collections are always allocated off-heap. This allows persistent co
llections to be used in |
490 // DEFINE_STATIC_LOCAL et. al. | 517 // DEFINE_STATIC_LOCAL et. al. |
491 WTF_USE_ALLOCATOR(PersistentHeapCollectionBase, WTF::PartitionAllocator); | 518 WTF_USE_ALLOCATOR(PersistentHeapCollectionBase, WTF::PartitionAllocator); |
492 IS_PERSISTENT_REFERENCE_TYPE(); | 519 IS_PERSISTENT_REFERENCE_TYPE(); |
493 public: | 520 public: |
494 PersistentHeapCollectionBase() | 521 PersistentHeapCollectionBase() |
495 { | 522 { |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
723 | 750 |
724 template <typename T> | 751 template <typename T> |
725 struct IsWeakReceiver<blink::WeakPersistent<T>> : std::true_type {}; | 752 struct IsWeakReceiver<blink::WeakPersistent<T>> : std::true_type {}; |
726 | 753 |
727 template <typename T> | 754 template <typename T> |
728 struct IsWeakReceiver<blink::CrossThreadWeakPersistent<T>> : std::true_type {}; | 755 struct IsWeakReceiver<blink::CrossThreadWeakPersistent<T>> : std::true_type {}; |
729 | 756 |
730 } | 757 } |
731 | 758 |
732 #endif // Persistent_h | 759 #endif // Persistent_h |
OLD | NEW |