Chromium Code Reviews| 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 52 | 52 |
| 53 namespace blink { | 53 namespace blink { |
| 54 | 54 |
| 55 enum WeaknessPersistentConfiguration { | 55 enum WeaknessPersistentConfiguration { |
| 56 NonWeakPersistentConfiguration, | 56 NonWeakPersistentConfiguration, |
| 57 WeakPersistentConfiguration | 57 WeakPersistentConfiguration |
| 58 }; | 58 }; |
| 59 | 59 |
| 60 enum CrossThreadnessPersistentConfiguration { | 60 enum CrossThreadnessPersistentConfiguration { |
| 61 SingleThreadPersistentConfiguration, | 61 SingleThreadPersistentConfiguration, |
| 62 CrossThreadPersistentConfiguration | 62 CrossThreadPersistentConfiguration, |
| 63 XThreadPersistentConfiguration | |
| 63 }; | 64 }; |
| 64 | 65 |
| 65 template<typename T, WeaknessPersistentConfiguration weaknessConfiguration, Cros sThreadnessPersistentConfiguration crossThreadnessConfiguration> | 66 template<typename T, WeaknessPersistentConfiguration weaknessConfiguration, Cros sThreadnessPersistentConfiguration crossThreadnessConfiguration> |
| 66 class PersistentBase { | 67 class PersistentBase { |
| 67 public: | 68 public: |
| 68 PersistentBase() : m_raw(nullptr) | 69 PersistentBase() : m_raw(nullptr) |
| 69 { | 70 { |
| 70 initialize(); | 71 initialize(); |
| 71 } | 72 } |
| 72 | 73 |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 196 LEAK_SANITIZER_IGNORE_OBJECT(this); | 197 LEAK_SANITIZER_IGNORE_OBJECT(this); |
| 197 } | 198 } |
| 198 return this; | 199 return this; |
| 199 } | 200 } |
| 200 #endif | 201 #endif |
| 201 | 202 |
| 202 private: | 203 private: |
| 203 NO_LAZY_SWEEP_SANITIZE_ADDRESS | 204 NO_LAZY_SWEEP_SANITIZE_ADDRESS |
| 204 void assign(T* ptr) | 205 void assign(T* ptr) |
| 205 { | 206 { |
| 207 if (crossThreadnessConfiguration == XThreadPersistentConfiguration | |
| 208 && ThreadState::forObject(m_raw) != ThreadState::forObject(ptr)) { | |
| 209 uninitialize(); | |
| 210 } | |
| 206 m_raw = ptr; | 211 m_raw = ptr; |
| 207 checkPointer(); | 212 checkPointer(); |
| 208 if (m_raw) { | 213 if (m_raw) { |
| 209 if (!m_persistentNode) | 214 if (!m_persistentNode) |
| 210 initialize(); | 215 initialize(); |
| 211 return; | 216 return; |
| 212 } | 217 } |
| 213 if (m_persistentNode && crossThreadnessConfiguration != CrossThreadPersi stentConfiguration) | 218 if (m_persistentNode && crossThreadnessConfiguration != CrossThreadPersi stentConfiguration) |
| 214 uninitialize(); | 219 uninitialize(); |
| 215 } | 220 } |
| 216 | 221 |
| 217 NO_LAZY_SWEEP_SANITIZE_ADDRESS | 222 NO_LAZY_SWEEP_SANITIZE_ADDRESS |
| 218 void initialize() | 223 void initialize() |
| 219 { | 224 { |
| 220 ASSERT(!m_persistentNode); | 225 ASSERT(!m_persistentNode); |
| 221 if (!m_raw) | 226 if (!m_raw || m_raw == reinterpret_cast<T*>(-1)) |
| 222 return; | 227 return; |
| 223 | 228 |
| 224 TraceCallback traceCallback = TraceMethodDelegate<PersistentBase<T, weak nessConfiguration, crossThreadnessConfiguration>, &PersistentBase<T, weaknessCon figuration, crossThreadnessConfiguration>::trace>::trampoline; | 229 TraceCallback traceCallback = TraceMethodDelegate<PersistentBase<T, weak nessConfiguration, crossThreadnessConfiguration>, &PersistentBase<T, weaknessCon figuration, crossThreadnessConfiguration>::trace>::trampoline; |
| 225 if (crossThreadnessConfiguration == CrossThreadPersistentConfiguration) { | 230 if (crossThreadnessConfiguration == XThreadPersistentConfiguration) { |
| 231 BasePage* page = pageFromObject(m_raw); | |
| 232 ASSERT(page); | |
| 233 m_persistentNode = page->heap()->threadState()->xThreadPersistentReg ion()->allocatePersistentNode(this, traceCallback); | |
| 234 } else if (crossThreadnessConfiguration == CrossThreadPersistentConfigur ation) { | |
| 226 m_persistentNode = ThreadState::crossThreadPersistentRegion().alloca tePersistentNode(this, traceCallback); | 235 m_persistentNode = ThreadState::crossThreadPersistentRegion().alloca tePersistentNode(this, traceCallback); |
| 227 } else { | 236 } else { |
| 228 ThreadState* state = ThreadStateFor<ThreadingTrait<T>::Affinity>::st ate(); | 237 ThreadState* state = ThreadStateFor<ThreadingTrait<T>::Affinity>::st ate(); |
| 229 ASSERT(state->checkThread()); | 238 ASSERT(state->checkThread()); |
| 230 m_persistentNode = state->persistentRegion()->allocatePersistentNode (this, traceCallback); | 239 m_persistentNode = state->persistentRegion()->allocatePersistentNode (this, traceCallback); |
| 231 #if ENABLE(ASSERT) | 240 #if ENABLE(ASSERT) |
| 232 m_state = state; | 241 m_state = state; |
| 233 #endif | 242 #endif |
| 234 } | 243 } |
| 235 } | 244 } |
| 236 | 245 |
| 237 void uninitialize() | 246 void uninitialize() |
| 238 { | 247 { |
| 239 if (!m_persistentNode) | 248 if (!m_persistentNode) |
| 240 return; | 249 return; |
| 241 | 250 |
| 242 if (crossThreadnessConfiguration == CrossThreadPersistentConfiguration) { | 251 if (crossThreadnessConfiguration == XThreadPersistentConfiguration) { |
| 252 ASSERT(m_raw); | |
| 253 ASSERT(m_raw != reinterpret_cast<T*>(-1)); | |
| 254 BasePage* page = pageFromObject(m_raw); | |
| 255 ASSERT(page); | |
| 256 page->heap()->threadState()->xThreadPersistentRegion()->freePersiste ntNode(m_persistentNode); | |
| 257 } else if (crossThreadnessConfiguration == CrossThreadPersistentConfigur ation) { | |
| 243 ThreadState::crossThreadPersistentRegion().freePersistentNode(m_pers istentNode); | 258 ThreadState::crossThreadPersistentRegion().freePersistentNode(m_pers istentNode); |
| 244 } else { | 259 } else { |
| 245 ThreadState* state = ThreadStateFor<ThreadingTrait<T>::Affinity>::st ate(); | 260 ThreadState* state = ThreadStateFor<ThreadingTrait<T>::Affinity>::st ate(); |
| 246 ASSERT(state->checkThread()); | 261 ASSERT(state->checkThread()); |
| 247 // Persistent handle must be created and destructed in the same thre ad. | 262 // Persistent handle must be created and destructed in the same thre ad. |
| 248 ASSERT(m_state == state); | 263 ASSERT(m_state == state); |
| 249 state->persistentRegion()->freePersistentNode(m_persistentNode); | 264 state->persistentRegion()->freePersistentNode(m_persistentNode); |
| 250 } | 265 } |
| 251 m_persistentNode = nullptr; | 266 m_persistentNode = nullptr; |
| 252 } | 267 } |
| 253 | 268 |
| 254 void checkPointer() | 269 void checkPointer() |
| 255 { | 270 { |
| 271 if (crossThreadnessConfiguration == CrossThreadPersistentConfiguration) { | |
| 272 ThreadState* threadState = ThreadState::forObject(m_raw); | |
| 273 ASSERT(!threadState || !threadState->perThreadHeapEnabled()); | |
| 274 } | |
| 256 #if ENABLE(ASSERT) && defined(ADDRESS_SANITIZER) | 275 #if ENABLE(ASSERT) && defined(ADDRESS_SANITIZER) |
| 257 if (!m_raw) | 276 if (!m_raw) |
| 258 return; | 277 return; |
| 259 | 278 |
| 260 // Heap::isHeapObjectAlive(m_raw) checks that m_raw is a traceable | 279 // Heap::isHeapObjectAlive(m_raw) checks that m_raw is a traceable |
| 261 // object. In other words, it checks that the pointer is either of: | 280 // object. In other words, it checks that the pointer is either of: |
| 262 // | 281 // |
| 263 // (a) a pointer to the head of an on-heap object. | 282 // (a) a pointer to the head of an on-heap object. |
| 264 // (b) a pointer to the head of an on-heap mixin object. | 283 // (b) a pointer to the head of an on-heap mixin object. |
| 265 // | 284 // |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 518 } | 537 } |
| 519 | 538 |
| 520 template<typename U> | 539 template<typename U> |
| 521 CrossThreadWeakPersistent& operator=(const RawPtr<U>& other) | 540 CrossThreadWeakPersistent& operator=(const RawPtr<U>& other) |
| 522 { | 541 { |
| 523 Parent::operator=(other); | 542 Parent::operator=(other); |
| 524 return *this; | 543 return *this; |
| 525 } | 544 } |
| 526 }; | 545 }; |
| 527 | 546 |
| 547 template<typename T> | |
| 548 class XThreadPersistent : public PersistentBase<T, NonWeakPersistentConfiguratio n, XThreadPersistentConfiguration> { | |
|
haraken
2016/01/07 08:06:22
I'm considering a way to land the per-thread heap
| |
| 549 typedef PersistentBase<T, NonWeakPersistentConfiguration, XThreadPersistentC onfiguration> Parent; | |
| 550 public: | |
| 551 XThreadPersistent() : Parent() { } | |
| 552 XThreadPersistent(std::nullptr_t) : Parent(nullptr) { } | |
| 553 XThreadPersistent(T* raw) : Parent(raw) { } | |
| 554 XThreadPersistent(T& raw) : Parent(raw) { } | |
| 555 XThreadPersistent(const XThreadPersistent& other) : Parent(other) { } | |
| 556 template<typename U> | |
| 557 XThreadPersistent(const XThreadPersistent<U>& other) : Parent(other) { } | |
| 558 template<typename U> | |
| 559 XThreadPersistent(const Member<U>& other) : Parent(other) { } | |
| 560 template<typename U> | |
| 561 XThreadPersistent(const RawPtr<U>& other) : Parent(other.get()) { } | |
| 562 | |
| 563 template<typename U> | |
| 564 XThreadPersistent& operator=(U* other) | |
| 565 { | |
| 566 Parent::operator=(other); | |
| 567 return *this; | |
| 568 } | |
| 569 | |
| 570 XThreadPersistent& operator=(std::nullptr_t) | |
| 571 { | |
| 572 Parent::operator=(nullptr); | |
| 573 return *this; | |
| 574 } | |
| 575 | |
| 576 XThreadPersistent& operator=(const XThreadPersistent& other) | |
| 577 { | |
| 578 Parent::operator=(other); | |
| 579 return *this; | |
| 580 } | |
| 581 | |
| 582 template<typename U> | |
| 583 XThreadPersistent& operator=(const XThreadPersistent<U>& other) | |
| 584 { | |
| 585 Parent::operator=(other); | |
| 586 return *this; | |
| 587 } | |
| 588 | |
| 589 template<typename U> | |
| 590 XThreadPersistent& operator=(const Member<U>& other) | |
| 591 { | |
| 592 Parent::operator=(other); | |
| 593 return *this; | |
| 594 } | |
| 595 | |
| 596 template<typename U> | |
| 597 XThreadPersistent& operator=(const RawPtr<U>& other) | |
| 598 { | |
| 599 Parent::operator=(other); | |
| 600 return *this; | |
| 601 } | |
| 602 | |
| 603 explicit XThreadPersistent(WTF::HashTableDeletedValueType) : Parent(reinterp ret_cast<T*>(-1)) | |
| 604 { | |
| 605 } | |
| 606 | |
| 607 bool isHashTableDeletedValue() const { return *this == reinterpret_cast<T*>( -1); } | |
| 608 }; | |
| 609 | |
| 528 template<typename Collection> | 610 template<typename Collection> |
| 529 class PersistentHeapCollectionBase : public Collection { | 611 class PersistentHeapCollectionBase : public Collection { |
| 530 // We overload the various new and delete operators with using the WTF Parti tionAllocator to ensure persistent | 612 // 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 | 613 // heap collections are always allocated off-heap. This allows persistent co llections to be used in |
| 532 // DEFINE_STATIC_LOCAL et. al. | 614 // DEFINE_STATIC_LOCAL et. al. |
| 533 WTF_USE_ALLOCATOR(PersistentHeapCollectionBase, WTF::PartitionAllocator); | 615 WTF_USE_ALLOCATOR(PersistentHeapCollectionBase, WTF::PartitionAllocator); |
| 534 public: | 616 public: |
| 535 PersistentHeapCollectionBase() | 617 PersistentHeapCollectionBase() |
| 536 { | 618 { |
| 537 initialize(); | 619 initialize(); |
| (...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1023 #define ThreadSafeRefCountedWillBeGarbageCollected blink::GarbageCollected | 1105 #define ThreadSafeRefCountedWillBeGarbageCollected blink::GarbageCollected |
| 1024 #define ThreadSafeRefCountedWillBeGarbageCollectedFinalized blink::GarbageCollec tedFinalized | 1106 #define ThreadSafeRefCountedWillBeGarbageCollectedFinalized blink::GarbageCollec tedFinalized |
| 1025 #define PersistentWillBeMember blink::Member | 1107 #define PersistentWillBeMember blink::Member |
| 1026 #define CrossThreadPersistentWillBeMember blink::Member | 1108 #define CrossThreadPersistentWillBeMember blink::Member |
| 1027 #define RefPtrWillBePersistent blink::Persistent | 1109 #define RefPtrWillBePersistent blink::Persistent |
| 1028 #define RefPtrWillBeRawPtr WTF::RawPtr | 1110 #define RefPtrWillBeRawPtr WTF::RawPtr |
| 1029 #define RefPtrWillBeMember blink::Member | 1111 #define RefPtrWillBeMember blink::Member |
| 1030 #define RefPtrWillBeWeakMember blink::WeakMember | 1112 #define RefPtrWillBeWeakMember blink::WeakMember |
| 1031 #define RefPtrWillBeWeakPersistent blink::WeakPersistent | 1113 #define RefPtrWillBeWeakPersistent blink::WeakPersistent |
| 1032 #define RefPtrWillBeCrossThreadPersistent blink::CrossThreadPersistent | 1114 #define RefPtrWillBeCrossThreadPersistent blink::CrossThreadPersistent |
| 1115 #define RefPtrWillBeXThreadPersistent blink::XThreadPersistent | |
| 1033 #define RawPtrWillBeMember blink::Member | 1116 #define RawPtrWillBeMember blink::Member |
| 1034 #define RawPtrWillBePersistent blink::Persistent | 1117 #define RawPtrWillBePersistent blink::Persistent |
| 1118 #define RawPtrWillBeXThreadPersistent blink::XThreadPersistent | |
| 1035 #define RawPtrWillBeWeakMember blink::WeakMember | 1119 #define RawPtrWillBeWeakMember blink::WeakMember |
| 1036 #define RawPtrWillBeWeakPersistent blink::WeakPersistent | 1120 #define RawPtrWillBeWeakPersistent blink::WeakPersistent |
| 1037 #define RawPtrWillBeUntracedMember blink::UntracedMember | 1121 #define RawPtrWillBeUntracedMember blink::UntracedMember |
| 1038 #define OwnPtrWillBeCrossThreadPersistent blink::CrossThreadPersistent | 1122 #define OwnPtrWillBeCrossThreadPersistent blink::CrossThreadPersistent |
| 1123 #define OwnPtrWillBeXThreadPersistent blink::XThreadPersistent | |
| 1039 #define OwnPtrWillBeMember blink::Member | 1124 #define OwnPtrWillBeMember blink::Member |
| 1040 #define OwnPtrWillBePersistent blink::Persistent | 1125 #define OwnPtrWillBePersistent blink::Persistent |
| 1041 #define OwnPtrWillBeRawPtr WTF::RawPtr | 1126 #define OwnPtrWillBeRawPtr WTF::RawPtr |
| 1042 #define PassOwnPtrWillBeRawPtr WTF::RawPtr | 1127 #define PassOwnPtrWillBeRawPtr WTF::RawPtr |
| 1043 #define WeakPtrWillBeCrossThreadWeakPersistent blink::CrossThreadWeakPersistent | 1128 #define WeakPtrWillBeCrossThreadWeakPersistent blink::CrossThreadWeakPersistent |
| 1044 #define WeakPtrWillBeMember blink::Member | 1129 #define WeakPtrWillBeMember blink::Member |
| 1045 #define WeakPtrWillBeRawPtr WTF::RawPtr | 1130 #define WeakPtrWillBeRawPtr WTF::RawPtr |
| 1046 #define WeakPtrWillBeWeakMember blink::WeakMember | 1131 #define WeakPtrWillBeWeakMember blink::WeakMember |
| 1047 #define WeakPtrWillBeWeakPersistent blink::WeakPersistent | 1132 #define WeakPtrWillBeWeakPersistent blink::WeakPersistent |
| 1048 #define NoBaseWillBeGarbageCollected blink::GarbageCollected | 1133 #define NoBaseWillBeGarbageCollected blink::GarbageCollected |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1114 #define ThreadSafeRefCountedWillBeGarbageCollected WTF::ThreadSafeRefCounted | 1199 #define ThreadSafeRefCountedWillBeGarbageCollected WTF::ThreadSafeRefCounted |
| 1115 #define ThreadSafeRefCountedWillBeGarbageCollectedFinalized WTF::ThreadSafeRefCo unted | 1200 #define ThreadSafeRefCountedWillBeGarbageCollectedFinalized WTF::ThreadSafeRefCo unted |
| 1116 #define PersistentWillBeMember blink::Persistent | 1201 #define PersistentWillBeMember blink::Persistent |
| 1117 #define CrossThreadPersistentWillBeMember blink::CrossThreadPersistent | 1202 #define CrossThreadPersistentWillBeMember blink::CrossThreadPersistent |
| 1118 #define RefPtrWillBePersistent WTF::RefPtr | 1203 #define RefPtrWillBePersistent WTF::RefPtr |
| 1119 #define RefPtrWillBeRawPtr WTF::RefPtr | 1204 #define RefPtrWillBeRawPtr WTF::RefPtr |
| 1120 #define RefPtrWillBeMember WTF::RefPtr | 1205 #define RefPtrWillBeMember WTF::RefPtr |
| 1121 #define RefPtrWillBeWeakMember WTF::RefPtr | 1206 #define RefPtrWillBeWeakMember WTF::RefPtr |
| 1122 #define RefPtrWillBeWeakPersistent WTF::RefPtr | 1207 #define RefPtrWillBeWeakPersistent WTF::RefPtr |
| 1123 #define RefPtrWillBeCrossThreadPersistent WTF::RefPtr | 1208 #define RefPtrWillBeCrossThreadPersistent WTF::RefPtr |
| 1209 #define RefPtrWillBeXThreadPersistent WTF::RefPtr | |
| 1124 #define RawPtrWillBeMember WTF::RawPtr | 1210 #define RawPtrWillBeMember WTF::RawPtr |
| 1125 #define RawPtrWillBePersistent WTF::RawPtr | 1211 #define RawPtrWillBePersistent WTF::RawPtr |
| 1212 #define RawPtrWillBeXThreadPersistent WTF::RawPtr | |
| 1126 #define RawPtrWillBeWeakMember WTF::RawPtr | 1213 #define RawPtrWillBeWeakMember WTF::RawPtr |
| 1127 #define RawPtrWillBeWeakPersistent WTF::RawPtr | 1214 #define RawPtrWillBeWeakPersistent WTF::RawPtr |
| 1128 #define RawPtrWillBeUntracedMember WTF::RawPtr | 1215 #define RawPtrWillBeUntracedMember WTF::RawPtr |
| 1129 #define OwnPtrWillBeCrossThreadPersistent WTF::OwnPtr | 1216 #define OwnPtrWillBeCrossThreadPersistent WTF::OwnPtr |
| 1217 #define OwnPtrWillBeXThreadPersistent WTF::OwnPtr | |
| 1130 #define OwnPtrWillBeMember WTF::OwnPtr | 1218 #define OwnPtrWillBeMember WTF::OwnPtr |
| 1131 #define OwnPtrWillBePersistent WTF::OwnPtr | 1219 #define OwnPtrWillBePersistent WTF::OwnPtr |
| 1132 #define OwnPtrWillBeRawPtr WTF::OwnPtr | 1220 #define OwnPtrWillBeRawPtr WTF::OwnPtr |
| 1133 #define PassOwnPtrWillBeRawPtr WTF::PassOwnPtr | 1221 #define PassOwnPtrWillBeRawPtr WTF::PassOwnPtr |
| 1134 #define WeakPtrWillBeCrossThreadWeakPersistent WTF::WeakPtr | 1222 #define WeakPtrWillBeCrossThreadWeakPersistent WTF::WeakPtr |
| 1135 #define WeakPtrWillBeMember WTF::WeakPtr | 1223 #define WeakPtrWillBeMember WTF::WeakPtr |
| 1136 #define WeakPtrWillBeRawPtr WTF::WeakPtr | 1224 #define WeakPtrWillBeRawPtr WTF::WeakPtr |
| 1137 #define WeakPtrWillBeWeakMember WTF::WeakPtr | 1225 #define WeakPtrWillBeWeakMember WTF::WeakPtr |
| 1138 #define WeakPtrWillBeWeakPersistent WTF::WeakPtr | 1226 #define WeakPtrWillBeWeakPersistent WTF::WeakPtr |
| 1139 #define NoBaseWillBeGarbageCollected blink::DummyBase | 1227 #define NoBaseWillBeGarbageCollected blink::DummyBase |
| (...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1535 static_assert(sizeof(T), "T must be fully defined"); | 1623 static_assert(sizeof(T), "T must be fully defined"); |
| 1536 using StorageType = T*; | 1624 using StorageType = T*; |
| 1537 | 1625 |
| 1538 static StorageType wrap(T* value) { return value; } | 1626 static StorageType wrap(T* value) { return value; } |
| 1539 static T* unwrap(const StorageType& value) { return value; } | 1627 static T* unwrap(const StorageType& value) { return value; } |
| 1540 }; | 1628 }; |
| 1541 | 1629 |
| 1542 template<typename T> | 1630 template<typename T> |
| 1543 struct PointerParamStorageTraits<T*, true> { | 1631 struct PointerParamStorageTraits<T*, true> { |
| 1544 static_assert(sizeof(T), "T must be fully defined"); | 1632 static_assert(sizeof(T), "T must be fully defined"); |
| 1545 using StorageType = blink::CrossThreadPersistent<T>; | 1633 using StorageType = blink::XThreadPersistent<T>; |
| 1546 | 1634 |
| 1547 static StorageType wrap(T* value) { return value; } | 1635 static StorageType wrap(T* value) { return value; } |
| 1548 static T* unwrap(const StorageType& value) { return value.get(); } | 1636 static T* unwrap(const StorageType& value) { return value.get(); } |
| 1549 }; | 1637 }; |
| 1550 | 1638 |
| 1551 template<typename T> | 1639 template<typename T> |
| 1552 struct ParamStorageTraits<T*> : public PointerParamStorageTraits<T*, blink::IsGa rbageCollectedType<T>::value> { | 1640 struct ParamStorageTraits<T*> : public PointerParamStorageTraits<T*, blink::IsGa rbageCollectedType<T>::value> { |
| 1553 static_assert(sizeof(T), "T must be fully defined"); | 1641 static_assert(sizeof(T), "T must be fully defined"); |
| 1554 }; | 1642 }; |
| 1555 | 1643 |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 1566 static StorageType wrap(const blink::AllowCrossThreadWeakPersistent<T>& valu e) { return value.value(); } | 1654 static StorageType wrap(const blink::AllowCrossThreadWeakPersistent<T>& valu e) { return value.value(); } |
| 1567 | 1655 |
| 1568 // Currently assume that the call sites of this unwrap() account for cleared weak references also. | 1656 // Currently assume that the call sites of this unwrap() account for cleared weak references also. |
| 1569 // TODO(sof): extend WTF::FunctionWrapper call overloading to also handle (C rossThread)WeakPersistent. | 1657 // TODO(sof): extend WTF::FunctionWrapper call overloading to also handle (C rossThread)WeakPersistent. |
| 1570 static T* unwrap(const StorageType& value) { return value.get(); } | 1658 static T* unwrap(const StorageType& value) { return value.get(); } |
| 1571 }; | 1659 }; |
| 1572 | 1660 |
| 1573 template<typename T> | 1661 template<typename T> |
| 1574 PassRefPtr<T> adoptRef(blink::RefCountedGarbageCollected<T>*) = delete; | 1662 PassRefPtr<T> adoptRef(blink::RefCountedGarbageCollected<T>*) = delete; |
| 1575 | 1663 |
| 1664 template<typename T> struct HashTraits<blink::XThreadPersistent<T>> : SimpleClas sHashTraits<blink::XThreadPersistent<T>> { | |
| 1665 static const bool emptyValueIsZero = false; // Persistent's constructor need s to be called properly. | |
| 1666 | |
| 1667 // FIXME: The distinction between PeekInType and PassInType is there for | |
| 1668 // the sake of the reference counting handles. When they are gone the two | |
| 1669 // types can be merged into PassInType. | |
| 1670 // FIXME: Implement proper const'ness for iterator types. Requires support | |
| 1671 // in the marking Visitor. | |
| 1672 using PeekInType = const blink::XThreadPersistent<T>&; | |
| 1673 using PassInType = const blink::XThreadPersistent<T>&; | |
| 1674 using IteratorGetType = blink::XThreadPersistent<T>*; | |
| 1675 using IteratorConstGetType = const blink::XThreadPersistent<T>*; | |
| 1676 using IteratorReferenceType = blink::XThreadPersistent<T>&; | |
| 1677 using IteratorConstReferenceType = const blink::XThreadPersistent<T>&; | |
| 1678 static IteratorReferenceType getToReferenceConversion(IteratorGetType x) { r eturn *x; } | |
| 1679 static IteratorConstReferenceType getToReferenceConstConversion(IteratorCons tGetType x) { return *x; } | |
| 1680 // FIXME: Similarly, there is no need for a distinction between PeekOutType | |
| 1681 // and PassOutType without reference counting. | |
| 1682 using PeekOutType = T*; | |
| 1683 using PassOutType = T*; | |
| 1684 | |
| 1685 template<typename U> | |
| 1686 static void store(const U& value, blink::Persistent<T>& storage) { storage = value; } | |
| 1687 | |
| 1688 static PeekOutType peek(const blink::XThreadPersistent<T>& value) { return v alue; } | |
| 1689 static PassOutType passOut(const blink::XThreadPersistent<T>& value) { retur n value; } | |
| 1690 }; | |
| 1691 | |
| 1692 template<typename T> struct PtrHash<blink::XThreadPersistent<T>> : PtrHash<T*> { | |
| 1693 static unsigned hash(const blink::XThreadPersistent<T>& key) { return PtrHas h<T*>::hash(key.get()); } | |
| 1694 static bool equal(const blink::XThreadPersistent<T>& a, const blink::XThread Persistent<T>& b) { return a == b; } | |
| 1695 }; | |
| 1696 | |
| 1697 template<typename T> struct DefaultHash<blink::XThreadPersistent<T>> { | |
| 1698 using Hash = PtrHash<blink::XThreadPersistent<T>>; | |
| 1699 }; | |
| 1700 | |
| 1576 } // namespace WTF | 1701 } // namespace WTF |
| 1577 | 1702 |
| 1578 #endif | 1703 #endif |
| OLD | NEW |