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

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

Issue 2204183002: Prepare CompositorWorker for per thread heap (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix Created 4 years, 3 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
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 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 assign(nullptr); 107 assign(nullptr);
108 return result; 108 return result;
109 } 109 }
110 110
111 void clear() { assign(nullptr); } 111 void clear() { assign(nullptr); }
112 T& operator*() const { return *m_raw; } 112 T& operator*() const { return *m_raw; }
113 explicit operator bool() const { return m_raw; } 113 explicit operator bool() const { return m_raw; }
114 operator T*() const { return m_raw; } 114 operator T*() const { return m_raw; }
115 T* operator->() const { return *this; } 115 T* operator->() const { return *this; }
116 T* get() const { return m_raw; } 116 T* get() const { return m_raw; }
117 T* getInternal() const { return m_raw; }
117 118
118 template<typename U> 119 template<typename U>
119 PersistentBase& operator=(U* other) 120 PersistentBase& operator=(U* other)
120 { 121 {
121 assign(other); 122 assign(other);
122 return *this; 123 return *this;
123 } 124 }
124 125
125 PersistentBase& operator=(std::nullptr_t) 126 PersistentBase& operator=(std::nullptr_t)
126 { 127 {
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 Parent::operator=(other); 465 Parent::operator=(other);
465 return *this; 466 return *this;
466 } 467 }
467 468
468 template<typename U> 469 template<typename U>
469 CrossThreadPersistent& operator=(const Member<U>& other) 470 CrossThreadPersistent& operator=(const Member<U>& other)
470 { 471 {
471 Parent::operator=(other); 472 Parent::operator=(other);
472 return *this; 473 return *this;
473 } 474 }
475
476 template<typename U>
477 static CrossThreadPersistent<U> protectWeak(const PersistentBase<U, WeakPers istentConfiguration, CrossThreadPersistentConfiguration>& other)
478 {
479 CrossThreadPersistentRegion::LockScope persistentLock(ProcessHeap::cross ThreadPersistentRegion());
480 return CrossThreadPersistent<U>(other.getInternal());
481 }
474 }; 482 };
475 483
476 // Combines the behavior of CrossThreadPersistent and WeakPersistent. 484 // Combines the behavior of CrossThreadPersistent and WeakPersistent.
477 template<typename T> 485 template<typename T>
478 class CrossThreadWeakPersistent : public PersistentBase<T, WeakPersistentConfigu ration, CrossThreadPersistentConfiguration> { 486 class CrossThreadWeakPersistent : public PersistentBase<T, WeakPersistentConfigu ration, CrossThreadPersistentConfiguration> {
479 typedef PersistentBase<T, WeakPersistentConfiguration, CrossThreadPersistent Configuration> Parent; 487 typedef PersistentBase<T, WeakPersistentConfiguration, CrossThreadPersistent Configuration> Parent;
480 public: 488 public:
481 CrossThreadWeakPersistent() : Parent() { } 489 CrossThreadWeakPersistent() : Parent() { }
482 CrossThreadWeakPersistent(std::nullptr_t) : Parent(nullptr) { } 490 CrossThreadWeakPersistent(std::nullptr_t) : Parent(nullptr) { }
483 CrossThreadWeakPersistent(T* raw) : Parent(raw) { } 491 CrossThreadWeakPersistent(T* raw) : Parent(raw) { }
(...skipping 29 matching lines...) Expand all
513 Parent::operator=(other); 521 Parent::operator=(other);
514 return *this; 522 return *this;
515 } 523 }
516 524
517 template<typename U> 525 template<typename U>
518 CrossThreadWeakPersistent& operator=(const Member<U>& other) 526 CrossThreadWeakPersistent& operator=(const Member<U>& other)
519 { 527 {
520 Parent::operator=(other); 528 Parent::operator=(other);
521 return *this; 529 return *this;
522 } 530 }
531
532 T& operator*() const
533 {
534 DCHECK(!Parent::get() || !ThreadState::current() || &ThreadState::fromOb ject(Parent::get())->heap() == &ThreadState::current()->heap());
haraken 2016/09/07 15:10:30 I don't think we should add the '|| !ThreadState::
keishi 2016/09/12 09:00:48 Done.
535 return Parent::operator*();
536 }
537 explicit operator bool() const
538 {
539 DCHECK(!Parent::get() || !ThreadState::current() || &ThreadState::fromOb ject(Parent::get())->heap() == &ThreadState::current()->heap());
540 return Parent::operator bool();
541 }
542 operator T*() const
543 {
544 DCHECK(!Parent::get() || !ThreadState::current() || &ThreadState::fromOb ject(Parent::get())->heap() == &ThreadState::current()->heap());
545 return Parent::operator T*();
546 }
547 T* operator->() const
548 {
549 DCHECK(!Parent::get() || !ThreadState::current() || &ThreadState::fromOb ject(Parent::get())->heap() == &ThreadState::current()->heap());
550 return Parent::operator->();
551 }
552 T* get() const
553 {
554 DCHECK(!Parent::get() || !ThreadState::current() || &ThreadState::fromOb ject(Parent::get())->heap() == &ThreadState::current()->heap());
555 return Parent::get();
556 }
523 }; 557 };
524 558
525 template<typename Collection> 559 template<typename Collection>
526 class PersistentHeapCollectionBase : public Collection { 560 class PersistentHeapCollectionBase : public Collection {
527 // We overload the various new and delete operators with using the WTF Parti tionAllocator to ensure persistent 561 // We overload the various new and delete operators with using the WTF Parti tionAllocator to ensure persistent
528 // heap collections are always allocated off-heap. This allows persistent co llections to be used in 562 // heap collections are always allocated off-heap. This allows persistent co llections to be used in
529 // DEFINE_STATIC_LOCAL et. al. 563 // DEFINE_STATIC_LOCAL et. al.
530 WTF_USE_ALLOCATOR(PersistentHeapCollectionBase, WTF::PartitionAllocator); 564 WTF_USE_ALLOCATOR(PersistentHeapCollectionBase, WTF::PartitionAllocator);
531 IS_PERSISTENT_REFERENCE_TYPE(); 565 IS_PERSISTENT_REFERENCE_TYPE();
532 public: 566 public:
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
762 796
763 template <typename T> 797 template <typename T>
764 struct IsWeakReceiver<blink::WeakPersistent<T>> : std::true_type {}; 798 struct IsWeakReceiver<blink::WeakPersistent<T>> : std::true_type {};
765 799
766 template <typename T> 800 template <typename T>
767 struct IsWeakReceiver<blink::CrossThreadWeakPersistent<T>> : std::true_type {}; 801 struct IsWeakReceiver<blink::CrossThreadWeakPersistent<T>> : std::true_type {};
768 802
769 } 803 }
770 804
771 #endif // Persistent_h 805 #endif // Persistent_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698