OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 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 653 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
664 // We should attempt to restructure the WebAudio code so that the main thread | 664 // We should attempt to restructure the WebAudio code so that the main thread |
665 // alone determines life-time and receives messages about life-time from the | 665 // alone determines life-time and receives messages about life-time from the |
666 // audio thread. | 666 // audio thread. |
667 template<typename T> | 667 template<typename T> |
668 class ThreadSafeRefCountedGarbageCollected : public GarbageCollectedFinalized<T>
, public WTF::ThreadSafeRefCountedBase { | 668 class ThreadSafeRefCountedGarbageCollected : public GarbageCollectedFinalized<T>
, public WTF::ThreadSafeRefCountedBase { |
669 WTF_MAKE_NONCOPYABLE(ThreadSafeRefCountedGarbageCollected); | 669 WTF_MAKE_NONCOPYABLE(ThreadSafeRefCountedGarbageCollected); |
670 | 670 |
671 public: | 671 public: |
672 ThreadSafeRefCountedGarbageCollected() | 672 ThreadSafeRefCountedGarbageCollected() |
673 { | 673 { |
674 m_keepAlive = adoptPtr(new CrossThreadPersistent<T>(static_cast<T*>(this
))); | 674 makeKeepAlive(); |
675 } | 675 } |
676 | 676 |
677 // Override ref to deal with a case where a reference count goes up | 677 // Override ref to deal with a case where a reference count goes up |
678 // from 0 to 1. This can happen in the following scenario: | 678 // from 0 to 1. This can happen in the following scenario: |
679 // (1) The reference count becomes 0, but on-stack pointers keep references
to the object. | 679 // (1) The reference count becomes 0, but on-stack pointers keep references
to the object. |
680 // (2) The on-stack pointer is assigned to a RefPtr. The reference count bec
omes 1. | 680 // (2) The on-stack pointer is assigned to a RefPtr. The reference count bec
omes 1. |
681 // In this case, we have to resurrect m_keepAlive. | 681 // In this case, we have to resurrect m_keepAlive. |
682 void ref() | 682 void ref() |
683 { | 683 { |
684 MutexLocker lock(m_mutex); | 684 MutexLocker lock(m_mutex); |
685 if (UNLIKELY(!refCount())) { | 685 if (UNLIKELY(!refCount())) { |
686 ASSERT(!m_keepAlive); | 686 makeKeepAlive(); |
687 m_keepAlive = adoptPtr(new CrossThreadPersistent<T>(static_cast<T*>(
this))); | |
688 } | 687 } |
689 WTF::ThreadSafeRefCountedBase::ref(); | 688 WTF::ThreadSafeRefCountedBase::ref(); |
690 } | 689 } |
691 | 690 |
692 // Override deref to deal with our own deallocation based on ref counting. | 691 // Override deref to deal with our own deallocation based on ref counting. |
693 void deref() | 692 void deref() |
694 { | 693 { |
695 MutexLocker lock(m_mutex); | 694 MutexLocker lock(m_mutex); |
696 if (derefBase()) { | 695 if (derefBase()) { |
697 ASSERT(m_keepAlive); | 696 ASSERT(m_keepAlive); |
698 m_keepAlive.clear(); | 697 m_keepAlive.clear(); |
699 } | 698 } |
700 } | 699 } |
701 | 700 |
702 using GarbageCollectedFinalized<T>::operator new; | 701 using GarbageCollectedFinalized<T>::operator new; |
703 using GarbageCollectedFinalized<T>::operator delete; | 702 using GarbageCollectedFinalized<T>::operator delete; |
704 | 703 |
705 protected: | 704 protected: |
706 ~ThreadSafeRefCountedGarbageCollected() { } | 705 ~ThreadSafeRefCountedGarbageCollected() { } |
707 | 706 |
708 private: | 707 private: |
| 708 void makeKeepAlive() |
| 709 { |
| 710 ASSERT(!m_keepAlive); |
| 711 m_keepAlive = adoptPtr(new CrossThreadPersistent<T>(static_cast<T*>(this
))); |
| 712 } |
| 713 |
709 OwnPtr<CrossThreadPersistent<T> > m_keepAlive; | 714 OwnPtr<CrossThreadPersistent<T> > m_keepAlive; |
710 mutable Mutex m_mutex; | 715 mutable Mutex m_mutex; |
711 }; | 716 }; |
712 | 717 |
713 template<typename DataType> | 718 template<typename DataType> |
714 class PagePool { | 719 class PagePool { |
715 protected: | 720 protected: |
716 PagePool(); | 721 PagePool(); |
717 | 722 |
718 class PoolEntry { | 723 class PoolEntry { |
(...skipping 1727 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2446 }; | 2451 }; |
2447 | 2452 |
2448 template<typename T> | 2453 template<typename T> |
2449 struct IfWeakMember<WeakMember<T> > { | 2454 struct IfWeakMember<WeakMember<T> > { |
2450 static bool isDead(Visitor* visitor, const WeakMember<T>& t) { return !visit
or->isAlive(t.get()); } | 2455 static bool isDead(Visitor* visitor, const WeakMember<T>& t) { return !visit
or->isAlive(t.get()); } |
2451 }; | 2456 }; |
2452 | 2457 |
2453 } | 2458 } |
2454 | 2459 |
2455 #endif // Heap_h | 2460 #endif // Heap_h |
OLD | NEW |