Changeset 220569 in webkit
- Timestamp:
- Aug 10, 2017 5:41:53 PM (7 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r220566 r220569 1 2017-08-10 Yusuke Suzuki <utatane.tea@gmail.com> 2 3 Make ThreadGlobalData RefCounted for web thread 4 https://bugs.webkit.org/show_bug.cgi?id=175439 5 6 Reviewed by Mark Lam. 7 8 When the web thread is enabled, we share ThreadGlobalData between the web thread and the main thread. 9 The problem happens when the main thread is dying. It could start deallocating TLS and the web 10 thread may see the destructed ThreadGlobalData. 11 12 Even though, the current implementation is safe because the main thread do not perform TLS deallocation 13 in the Darwin environment. But this is not true in Windows. And we should not rely on this condition 14 that depends on the platforms. 15 16 In this patch, we make ThreadGlobalData ThreadSafeRefCounted. This type verbosely describes that 17 ThreadGlobalData could be shared between threads when the web thread enabled. And make the life time 18 management simple instead of relying on the platform dependent TLS implementation. 19 20 * platform/ThreadGlobalData.cpp: 21 (WebCore::ThreadGlobalData::setWebCoreThreadData): 22 (WebCore::threadGlobalData): 23 * platform/ThreadGlobalData.h: 24 (WebCore::ThreadGlobalData::cachedResourceRequestInitiators): Deleted. 25 (WebCore::ThreadGlobalData::eventNames): Deleted. 26 (WebCore::ThreadGlobalData::threadTimers): Deleted. 27 (WebCore::ThreadGlobalData::qualifiedNameCache): Deleted. 28 (WebCore::ThreadGlobalData::cachedConverterICU): Deleted. 29 (WebCore::ThreadGlobalData::cachedConverterTEC): Deleted. 30 1 31 2017-08-10 Yusuke Suzuki <utatane.tea@gmail.com> 2 32 -
trunk/Source/WebCore/platform/ThreadGlobalData.cpp
r220548 r220569 82 82 83 83 #if USE(WEB_THREAD) 84 static ThreadSpecific< std::unique_ptr<ThreadGlobalData>>* staticData { nullptr };84 static ThreadSpecific<RefPtr<ThreadGlobalData>>* staticData { nullptr }; 85 85 static ThreadGlobalData* sharedMainThreadStaticData { nullptr }; 86 86 … … 91 91 92 92 // Set WebThread's ThreadGlobalData object to be the same as the main UI thread. 93 // The web thread never finishes, and we expect the main thread to also never finish. 94 // Hence, it is safe to store the same ThreadGlobalData pointer in a thread specific std::unique_ptr. 95 // FIXME: Make ThreadGlobalData RefCounted for web thread. 96 // https://bugs.webkit.org/show_bug.cgi?id=175439 97 (**staticData).reset(sharedMainThreadStaticData); 93 **staticData = adoptRef(sharedMainThreadStaticData); 98 94 99 95 ASSERT(&threadGlobalData() == sharedMainThreadStaticData); … … 103 99 { 104 100 if (UNLIKELY(!staticData)) { 105 staticData = new ThreadSpecific< std::unique_ptr<ThreadGlobalData>>;101 staticData = new ThreadSpecific<RefPtr<ThreadGlobalData>>; 106 102 auto& result = **staticData; 107 103 ASSERT(!result); 108 result .reset(new ThreadGlobalData());104 result = adoptRef(new ThreadGlobalData); 109 105 // WebThread and main UI thread need to share the same object. Save it in a static 110 106 // here, the WebThread will pick it up in setWebCoreThreadData(). 111 if (pthread_main_np()) 107 if (pthread_main_np()) { 112 108 sharedMainThreadStaticData = result.get(); 109 result->ref(); 110 } 113 111 return *result; 114 112 } … … 116 114 auto& result = **staticData; 117 115 if (!result) 118 result .reset(new ThreadGlobalData());116 result = adoptRef(new ThreadGlobalData); 119 117 return *result; 120 118 } -
trunk/Source/WebCore/platform/ThreadGlobalData.h
r220548 r220569 28 28 #define ThreadGlobalData_h 29 29 30 #include <wtf/ThreadSafeRefCounted.h> 30 31 #include <wtf/text/StringHash.h> 31 32 … … 40 41 struct TECConverterWrapper; 41 42 43 #if USE(WEB_THREAD) 44 class ThreadGlobalData : public ThreadSafeRefCounted<ThreadGlobalData> { 45 #else 42 46 class ThreadGlobalData { 47 #endif 43 48 WTF_MAKE_NONCOPYABLE(ThreadGlobalData); 44 49 WTF_MAKE_FAST_ALLOCATED;
Note: See TracChangeset
for help on using the changeset viewer.