Changeset 139780 in webkit
- Timestamp:
- Jan 15, 2013 1:35:08 PM (11 years ago)
- Location:
- trunk/Source
- Files:
-
- 1 added
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WTF/ChangeLog
r139553 r139780 1 2013-01-15 Adam Barth <abarth@webkit.org> 2 3 Generalize DocumentWeakReference into WTF::WeakPtr 4 https://bugs.webkit.org/show_bug.cgi?id=106854 5 6 Reviewed by Darin Adler. 7 8 This patch adds a simple WeakPtr object to WTF. To use WeakPtr, objects 9 must hold a WeakPtrFactory member variable, which clears the WeakPtrs 10 when the object is destructed. The underlying storage is a 11 ThreadSafeRefCounted "WeakReference" object, which is shared by all the 12 WeakPtrs. 13 14 WeakPtr is a generalization of DocumentWeakReference, which is used to 15 check whether the Document object is alive when tasks arive on the main 16 thread from worker threads. We plan to use a similar pattern in the 17 threaded HTML parser, but we want to send tasks to objects other than 18 Document. 19 20 * GNUmakefile.list.am: 21 * WTF.gypi: 22 * WTF.pro: 23 * WTF.vcproj/WTF.vcproj: 24 * WTF.xcodeproj/project.pbxproj: 25 * wtf/CMakeLists.txt: 26 * wtf/WeakPtr.h: Added. 27 (WeakReference): 28 - The ThreadSafeRefCounted object shared by all the WeakPtr 29 instances. This patch uses ThreadSafeRefCounted so that we can 30 use WeakPtrs to cancel cross-thread messages. 31 (WTF::WeakReference::create): 32 (WTF::WeakReference::get): 33 (WTF::WeakReference::clear): 34 - When the object is destroyed, WeakPtrFactory calls this function 35 to clear all the WeakPtrs. 36 (WTF::WeakReference::WeakReference): 37 (WTF::WeakPtr::WeakPtr): 38 (WTF::WeakPtr::get): 39 - We might want to add implicit conversions and Boolean operators 40 in the future, but I've kept this class simple for now. 41 (WTF::WeakPtrFactory::WeakPtrFactory): 42 (WTF::WeakPtrFactory::~WeakPtrFactory): 43 (WTF::WeakPtrFactory::createWeakPtr): 44 1 45 2013-01-12 Csaba Osztrogonác <ossy@webkit.org> 2 46 -
trunk/Source/WTF/GNUmakefile.list.am
r139184 r139780 194 194 Source/WTF/wtf/WTFThreadData.cpp \ 195 195 Source/WTF/wtf/WTFThreadData.h \ 196 Source/WTF/wtf/WeakPtr.h \ 196 197 Source/WTF/wtf/dtoa.cpp \ 197 198 Source/WTF/wtf/dtoa.h \ -
trunk/Source/WTF/WTF.gypi
r138628 r139780 113 113 'wtf/VectorTraits.h', 114 114 'wtf/WTFThreadData.h', 115 'wtf/WeakPtr.h', 115 116 'wtf/dtoa.h', 116 117 'wtf/dtoa/bignum-dtoa.h', -
trunk/Source/WTF/WTF.pro
r136096 r139780 189 189 VectorTraits.h \ 190 190 VMTags.h \ 191 WTFThreadData.h 191 WTFThreadData.h \ 192 WeakPtr.h 192 193 193 194 unix: HEADERS += ThreadIdentifierDataPthreads.h -
trunk/Source/WTF/WTF.vcproj/WTF.vcproj
r136096 r139780 1329 1329 > 1330 1330 </File> 1331 <File 1332 RelativePath="..\wtf\WeakPtr.h" 1333 > 1334 </File> 1331 1335 </Files> 1332 1336 <Globals> -
trunk/Source/WTF/WTF.xcodeproj/project.pbxproj
r139010 r139780 73 73 8134013815B092FD001FF0B8 /* Base64.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 8134013615B092FD001FF0B8 /* Base64.cpp */; }; 74 74 8134013915B092FD001FF0B8 /* Base64.h in Headers */ = {isa = PBXBuildFile; fileRef = 8134013715B092FD001FF0B8 /* Base64.h */; }; 75 974CFC8E16A4F327006D5404 /* WeakPtr.h in Headers */ = {isa = PBXBuildFile; fileRef = 974CFC8D16A4F327006D5404 /* WeakPtr.h */; }; 75 76 A876DBD8151816E500DADB95 /* Platform.h in Headers */ = {isa = PBXBuildFile; fileRef = A876DBD7151816E500DADB95 /* Platform.h */; }; 76 77 A8A4737F151A825B004123FF /* Alignment.h in Headers */ = {isa = PBXBuildFile; fileRef = A8A47254151A825A004123FF /* Alignment.h */; }; … … 380 381 8134013615B092FD001FF0B8 /* Base64.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Base64.cpp; sourceTree = "<group>"; }; 381 382 8134013715B092FD001FF0B8 /* Base64.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Base64.h; sourceTree = "<group>"; }; 383 974CFC8D16A4F327006D5404 /* WeakPtr.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WeakPtr.h; sourceTree = "<group>"; }; 382 384 A876DBD7151816E500DADB95 /* Platform.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Platform.h; sourceTree = "<group>"; }; 383 385 A8A47254151A825A004123FF /* Alignment.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Alignment.h; sourceTree = "<group>"; }; … … 877 879 A8A47371151A825B004123FF /* VectorTraits.h */, 878 880 A8A47372151A825B004123FF /* VMTags.h */, 881 974CFC8D16A4F327006D5404 /* WeakPtr.h */, 879 882 A8A4737A151A825B004123FF /* WTFThreadData.cpp */, 880 883 A8A4737B151A825B004123FF /* WTFThreadData.h */, … … 1251 1254 A8A4747F151A825B004123FF /* VectorTraits.h in Headers */, 1252 1255 A8A47480151A825B004123FF /* VMTags.h in Headers */, 1256 974CFC8E16A4F327006D5404 /* WeakPtr.h in Headers */, 1253 1257 A8A47446151A825B004123FF /* WTFString.h in Headers */, 1254 1258 A8A47487151A825B004123FF /* WTFThreadData.h in Headers */, -
trunk/Source/WTF/wtf/CMakeLists.txt
r136790 r139780 123 123 VectorTraits.h 124 124 WTFThreadData.h 125 WeakPtr.h 125 126 dtoa.h 126 127 -
trunk/Source/WebCore/ChangeLog
r139777 r139780 1 2013-01-15 Adam Barth <abarth@webkit.org> 2 3 Generalize DocumentWeakReference into WTF::WeakPtr 4 https://bugs.webkit.org/show_bug.cgi?id=106854 5 6 Reviewed by Darin Adler. 7 8 This patch replaces DocumentWeakReference with WeakPtr. There should be 9 no change in behavior. 10 11 * dom/Document.cpp: 12 (WebCore): 13 (WebCore::Document::Document): 14 (WebCore::Document::~Document): 15 (WebCore::PerformTaskContext::PerformTaskContext): 16 (PerformTaskContext): 17 (WebCore::Document::didReceiveTask): 18 (WebCore::Document::postTask): 19 (WebCore::Document::reportMemoryUsage): 20 * dom/Document.h: 21 (WebCore): 22 (Document): 23 1 24 2013-01-15 James Simonsen <simonjam@chromium.org> 2 25 -
trunk/Source/WebCore/dom/Document.cpp
r139762 r139780 405 405 static HashSet<Document*>* documentsThatNeedStyleRecalc = 0; 406 406 407 class DocumentWeakReference : public ThreadSafeRefCounted<DocumentWeakReference> {408 public:409 static PassRefPtr<DocumentWeakReference> create(Document* document)410 {411 return adoptRef(new DocumentWeakReference(document));412 }413 414 Document* document()415 {416 ASSERT(isMainThread());417 return m_document;418 }419 420 void clear()421 {422 ASSERT(isMainThread());423 m_document = 0;424 }425 426 private:427 DocumentWeakReference(Document* document)428 : m_document(document)429 {430 ASSERT(isMainThread());431 }432 433 Document* m_document;434 };435 436 407 uint64_t Document::s_globalTreeVersion = 0; 437 408 … … 482 453 , m_renderer(0) 483 454 , m_eventQueue(DocumentEventQueue::create(this)) 484 , m_weak Reference(DocumentWeakReference::create(this))455 , m_weakFactory(this) 485 456 , m_idAttributeName(idAttr) 486 457 #if ENABLE(FULLSCREEN_API) … … 657 628 if (m_elemSheet) 658 629 m_elemSheet->clearOwnerNode(); 659 660 m_weakReference->clear();661 630 662 631 clearStyleResolver(); // We need to destory CSSFontSelector before destroying m_cachedResourceLoader. … … 4809 4778 WTF_MAKE_NONCOPYABLE(PerformTaskContext); WTF_MAKE_FAST_ALLOCATED; 4810 4779 public: 4811 PerformTaskContext( PassRefPtr<DocumentWeakReference> documentReference, PassOwnPtr<ScriptExecutionContext::Task> task)4812 : documentReference(document Reference)4780 PerformTaskContext(WeakPtr<Document> document, PassOwnPtr<ScriptExecutionContext::Task> task) 4781 : documentReference(document) 4813 4782 , task(task) 4814 4783 { 4815 4784 } 4816 4785 4817 RefPtr<DocumentWeakReference> documentReference;4786 WeakPtr<Document> documentReference; 4818 4787 OwnPtr<ScriptExecutionContext::Task> task; 4819 4788 }; … … 4826 4795 ASSERT(context); 4827 4796 4828 Document* document = context->documentReference ->document();4797 Document* document = context->documentReference.get(); 4829 4798 if (!document) 4830 4799 return; … … 4841 4810 void Document::postTask(PassOwnPtr<Task> task) 4842 4811 { 4843 callOnMainThread(didReceiveTask, new PerformTaskContext(m_weak Reference, task));4812 callOnMainThread(didReceiveTask, new PerformTaskContext(m_weakFactory.createWeakPtr(), task)); 4844 4813 } 4845 4814 … … 5993 5962 info.addMember(m_selectorQueryCache); 5994 5963 info.addMember(m_renderer); 5995 info.addMember(m_weak Reference);5964 info.addMember(m_weakFactory); 5996 5965 info.addMember(m_idAttributeName); 5997 5966 #if ENABLE(FULLSCREEN_API) -
trunk/Source/WebCore/dom/Document.h
r139751 r139780 54 54 #include <wtf/PassOwnPtr.h> 55 55 #include <wtf/PassRefPtr.h> 56 #include <wtf/WeakPtr.h> 56 57 57 58 namespace WebCore { … … 82 83 class DocumentStyleSheetCollection; 83 84 class DocumentType; 84 class DocumentWeakReference;85 85 class Element; 86 86 class EntityReference; … … 1476 1476 RefPtr<DocumentEventQueue> m_eventQueue; 1477 1477 1478 RefPtr<DocumentWeakReference> m_weakReference;1478 WeakPtrFactory<Document> m_weakFactory; 1479 1479 1480 1480 HashSet<MediaCanStartListener*> m_mediaCanStartListeners;
Note: See TracChangeset
for help on using the changeset viewer.