OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2014 Google Inc. All rights reserved. | 2 * Copyright (C) 2014 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 #include "wtf/RawPtr.h" | 45 #include "wtf/RawPtr.h" |
46 #include "wtf/RefCounted.h" | 46 #include "wtf/RefCounted.h" |
47 #include "wtf/TypeTraits.h" | 47 #include "wtf/TypeTraits.h" |
48 | 48 |
49 #if defined(LEAK_SANITIZER) | 49 #if defined(LEAK_SANITIZER) |
50 #include "wtf/LeakAnnotations.h" | 50 #include "wtf/LeakAnnotations.h" |
51 #endif | 51 #endif |
52 | 52 |
53 namespace blink { | 53 namespace blink { |
54 | 54 |
| 55 // Marker used to annotate persistent objects and collections with, |
| 56 // so as to enable reliable testing for persistent references via |
| 57 // a type trait (see TypeTraits.h's IsPersistentReferenceType<>.) |
| 58 #define IS_PERSISTENT_REFERENCE_TYPE() \ |
| 59 public: \ |
| 60 using IsPersistentReferenceTypeMarker = int; \ |
| 61 private: |
| 62 |
55 enum WeaknessPersistentConfiguration { | 63 enum WeaknessPersistentConfiguration { |
56 NonWeakPersistentConfiguration, | 64 NonWeakPersistentConfiguration, |
57 WeakPersistentConfiguration | 65 WeakPersistentConfiguration |
58 }; | 66 }; |
59 | 67 |
60 enum CrossThreadnessPersistentConfiguration { | 68 enum CrossThreadnessPersistentConfiguration { |
61 SingleThreadPersistentConfiguration, | 69 SingleThreadPersistentConfiguration, |
62 CrossThreadPersistentConfiguration | 70 CrossThreadPersistentConfiguration |
63 }; | 71 }; |
64 | 72 |
65 template<typename T, WeaknessPersistentConfiguration weaknessConfiguration, Cros
sThreadnessPersistentConfiguration crossThreadnessConfiguration> | 73 template<typename T, WeaknessPersistentConfiguration weaknessConfiguration, Cros
sThreadnessPersistentConfiguration crossThreadnessConfiguration> |
66 class PersistentBase { | 74 class PersistentBase { |
| 75 IS_PERSISTENT_REFERENCE_TYPE(); |
67 public: | 76 public: |
68 PersistentBase() : m_raw(nullptr) | 77 PersistentBase() : m_raw(nullptr) |
69 { | 78 { |
70 initialize(); | 79 initialize(); |
71 } | 80 } |
72 | 81 |
73 PersistentBase(std::nullptr_t) : m_raw(nullptr) | 82 PersistentBase(std::nullptr_t) : m_raw(nullptr) |
74 { | 83 { |
75 initialize(); | 84 initialize(); |
76 } | 85 } |
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
524 return *this; | 533 return *this; |
525 } | 534 } |
526 }; | 535 }; |
527 | 536 |
528 template<typename Collection> | 537 template<typename Collection> |
529 class PersistentHeapCollectionBase : public Collection { | 538 class PersistentHeapCollectionBase : public Collection { |
530 // We overload the various new and delete operators with using the WTF Parti
tionAllocator to ensure persistent | 539 // We overload the various new and delete operators with using the WTF Parti
tionAllocator to ensure persistent |
531 // heap collections are always allocated off-heap. This allows persistent co
llections to be used in | 540 // heap collections are always allocated off-heap. This allows persistent co
llections to be used in |
532 // DEFINE_STATIC_LOCAL et. al. | 541 // DEFINE_STATIC_LOCAL et. al. |
533 WTF_USE_ALLOCATOR(PersistentHeapCollectionBase, WTF::PartitionAllocator); | 542 WTF_USE_ALLOCATOR(PersistentHeapCollectionBase, WTF::PartitionAllocator); |
| 543 IS_PERSISTENT_REFERENCE_TYPE(); |
534 public: | 544 public: |
535 PersistentHeapCollectionBase() | 545 PersistentHeapCollectionBase() |
536 { | 546 { |
537 initialize(); | 547 initialize(); |
538 } | 548 } |
539 | 549 |
540 PersistentHeapCollectionBase(const PersistentHeapCollectionBase& other) : Co
llection(other) | 550 PersistentHeapCollectionBase(const PersistentHeapCollectionBase& other) : Co
llection(other) |
541 { | 551 { |
542 initialize(); | 552 initialize(); |
543 } | 553 } |
(...skipping 1025 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1569 // TODO(sof): extend WTF::FunctionWrapper call overloading to also handle (C
rossThread)WeakPersistent. | 1579 // TODO(sof): extend WTF::FunctionWrapper call overloading to also handle (C
rossThread)WeakPersistent. |
1570 static T* unwrap(const StorageType& value) { return value.get(); } | 1580 static T* unwrap(const StorageType& value) { return value.get(); } |
1571 }; | 1581 }; |
1572 | 1582 |
1573 template<typename T> | 1583 template<typename T> |
1574 PassRefPtr<T> adoptRef(blink::RefCountedGarbageCollected<T>*) = delete; | 1584 PassRefPtr<T> adoptRef(blink::RefCountedGarbageCollected<T>*) = delete; |
1575 | 1585 |
1576 } // namespace WTF | 1586 } // namespace WTF |
1577 | 1587 |
1578 #endif | 1588 #endif |
OLD | NEW |