Changeset 57829 in webkit for trunk/JavaScriptCore/wtf
- Timestamp:
- Apr 19, 2010, 1:05:53 PM (15 years ago)
- Location:
- trunk/JavaScriptCore/wtf
- Files:
-
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/wtf/WTFThreadData.cpp
r57765 r57829 1 1 /* 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved.2 * Copyright (C) 2008, 2010 Apple Inc. All Rights Reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 26 26 27 27 #include "config.h" 28 #include " ThreadGlobalData.h"28 #include "WTFThreadData.h" 29 29 30 #include "EventNames.h" 31 #include "StringImpl.h" 32 #include "ThreadTimers.h" 33 #include <wtf/UnusedParam.h> 30 namespace WTF { 34 31 35 #if USE(ICU_UNICODE) 36 #include "TextCodecICU.h" 32 #if WTFTHREADDATA_MULTITHREADED 33 ThreadSpecific<WTFThreadData>* WTFThreadData::staticData; 34 #else 35 WTFThreadData* WTFThreadData::staticData; 37 36 #endif 38 37 39 #if PLATFORM(MAC) 40 #include "TextCodecMac.h" 41 #endif 42 43 #if ENABLE(WORKERS) 44 #include <wtf/Threading.h> 45 #include <wtf/ThreadSpecific.h> 46 using namespace WTF; 47 #endif 48 49 namespace WebCore { 50 51 #if ENABLE(WORKERS) 52 ThreadSpecific<ThreadGlobalData>* ThreadGlobalData::staticData; 53 #else 54 ThreadGlobalData* ThreadGlobalData::staticData; 55 #endif 56 57 ThreadGlobalData::ThreadGlobalData() 58 : m_atomicStringTable(new HashSet<StringImpl*>) 59 , m_eventNames(new EventNames) 60 , m_threadTimers(new ThreadTimers) 61 #ifndef NDEBUG 62 , m_isMainThread(isMainThread()) 63 #endif 64 #if USE(ICU_UNICODE) 65 , m_cachedConverterICU(new ICUConverterWrapper) 66 #endif 67 #if PLATFORM(MAC) 68 , m_cachedConverterTEC(new TECConverterWrapper) 38 WTFThreadData::WTFThreadData() 39 : m_atomicStringTable(0) 40 , m_atomicStringTableDestructor(0) 41 #if USE(JSC) 42 , m_defaultIdentifierTable(0) 43 , m_currentIdentifierTable(0) 69 44 #endif 70 45 { 71 // StringImpl::empty() does not construct its static string in a threadsafe fashion,72 // so ensure it has been initialized from here.73 //74 // This constructor will have been called on the main thread before being called on75 // any other thread, and is only called once per thread.76 StringImpl::empty();77 46 } 78 47 79 ThreadGlobalData::~ThreadGlobalData()48 WTFThreadData::~WTFThreadData() 80 49 { 81 #if PLATFORM(MAC) 82 delete m_cachedConverterTEC; 83 #endif 84 #if USE(ICU_UNICODE) 85 delete m_cachedConverterICU; 86 #endif 87 delete m_eventNames; 88 delete m_atomicStringTable; 89 delete m_threadTimers; 50 if (m_atomicStringTableDestructor) 51 m_atomicStringTableDestructor(m_atomicStringTable); 90 52 } 91 53 -
trunk/JavaScriptCore/wtf/WTFThreadData.h
r57765 r57829 25 25 */ 26 26 27 #ifndef ThreadGlobalData_h28 #define ThreadGlobalData_h27 #ifndef WTFThreadData_h 28 #define WTFThreadData_h 29 29 30 #include "StringHash.h"31 30 #include <wtf/HashMap.h> 32 31 #include <wtf/HashSet.h> 33 32 #include <wtf/Noncopyable.h> 34 33 35 #if ENABLE(WORKERS) 34 // This was ENABLE(WORKERS) in WebCore, but this is not defined when compiling JSC. 35 // However this check was not correct anyway, re this comment: 36 // // FIXME: Workers are not necessarily the only feature that make per-thread global data necessary. 37 // // We need to check for e.g. database objects manipulating strings on secondary threads. 38 // Always enabling this is safe, and should be a better option until we can come up 39 // with a better define. 40 #define WTFTHREADDATA_MULTITHREADED 1 41 42 #if WTFTHREADDATA_MULTITHREADED 36 43 #include <wtf/ThreadSpecific.h> 37 44 #include <wtf/Threading.h> 38 using WTF::ThreadSpecific;39 45 #endif 40 46 47 // FIXME: This is a temporary layering violation while we move more string code to WTF. 48 namespace JSC { 49 class IdentifierTable; 50 } 51 52 // FIXME: This is a temporary layering violation while we move more string code to WTF. 41 53 namespace WebCore { 54 class AtomicStringTable; 55 } 42 56 43 class EventNames; 44 struct ICUConverterWrapper; 45 struct TECConverterWrapper; 46 class ThreadTimers; 57 typedef void (*AtomicStringTableDestructor)(WebCore::AtomicStringTable*); 47 58 48 class ThreadGlobalData : public Noncopyable { 49 public: 50 ThreadGlobalData(); 51 ~ThreadGlobalData(); 59 namespace WTF { 52 60 53 EventNames& eventNames() { return *m_eventNames; } 54 HashSet<StringImpl*>& atomicStringTable() { return *m_atomicStringTable; } 55 ThreadTimers& threadTimers() { return *m_threadTimers; } 61 class WTFThreadData : public Noncopyable { 62 public: 63 WTFThreadData(); 64 ~WTFThreadData(); 56 65 57 #if USE(ICU_UNICODE) 58 ICUConverterWrapper& cachedConverterICU() { return *m_cachedConverterICU; } 66 WebCore::AtomicStringTable* atomicStringTable() 67 { 68 return m_atomicStringTable; 69 } 70 71 #if USE(JSC) 72 void initializeIdentifierTable(JSC::IdentifierTable* identifierTable) 73 { 74 m_defaultIdentifierTable = identifierTable; 75 m_currentIdentifierTable = identifierTable; 76 } 77 78 JSC::IdentifierTable* currentIdentifierTable() 79 { 80 return m_currentIdentifierTable; 81 } 82 83 JSC::IdentifierTable* setCurrentIdentifierTable(JSC::IdentifierTable* identifierTable) 84 { 85 JSC::IdentifierTable* oldIdentifierTable = m_currentIdentifierTable; 86 m_currentIdentifierTable = identifierTable; 87 return oldIdentifierTable; 88 } 89 90 void resetCurrentIdentifierTable() 91 { 92 m_currentIdentifierTable = m_defaultIdentifierTable; 93 } 59 94 #endif 60 95 61 #if PLATFORM(MAC) 62 TECConverterWrapper& cachedConverterTEC() { return *m_cachedConverterTEC; } 96 private: 97 WebCore::AtomicStringTable* m_atomicStringTable; 98 AtomicStringTableDestructor m_atomicStringTableDestructor; 99 100 #if USE(JSC) 101 JSC::IdentifierTable* m_defaultIdentifierTable; 102 JSC::IdentifierTable* m_currentIdentifierTable; 63 103 #endif 64 104 65 private: 66 HashSet<StringImpl*>* m_atomicStringTable; 67 EventNames* m_eventNames; 68 ThreadTimers* m_threadTimers; 105 #if WTFTHREADDATA_MULTITHREADED 106 static ThreadSpecific<WTFThreadData>* staticData; 107 #else 108 static WTFThreadData* staticData; 109 #endif 110 friend WTFThreadData& wtfThreadData(); 111 friend class WebCore::AtomicStringTable; 112 }; 69 113 70 #ifndef NDEBUG 71 bool m_isMainThread; 72 #endif 73 74 #if USE(ICU_UNICODE) 75 ICUConverterWrapper* m_cachedConverterICU; 76 #endif 77 78 #if PLATFORM(MAC) 79 TECConverterWrapper* m_cachedConverterTEC; 80 #endif 81 82 #if ENABLE(WORKERS) 83 static ThreadSpecific<ThreadGlobalData>* staticData; 114 inline WTFThreadData& wtfThreadData() 115 { 116 #if WTFTHREADDATA_MULTITHREADED 117 // WRT WebCore: 118 // WTFThreadData is used on main thread before it could possibly be used 119 // on secondary ones, so there is no need for synchronization here. 120 // WRT JavaScriptCore: 121 // wtfThreadData() is initially called from initializeThreading(), ensuring 122 // this is initially called in a pthread_once locked context. 123 if (!WTFThreadData::staticData) 124 WTFThreadData::staticData = new ThreadSpecific<WTFThreadData>; 125 return **WTFThreadData::staticData; 84 126 #else 85 static ThreadGlobalData* staticData; 86 #endif 87 friend ThreadGlobalData& threadGlobalData(); 88 }; 89 90 inline ThreadGlobalData& threadGlobalData() 91 { 92 // FIXME: Workers are not necessarily the only feature that make per-thread global data necessary. 93 // We need to check for e.g. database objects manipulating strings on secondary threads. 94 95 #if ENABLE(WORKERS) 96 // ThreadGlobalData is used on main thread before it could possibly be used on secondary ones, so there is no need for synchronization here. 97 if (!ThreadGlobalData::staticData) 98 ThreadGlobalData::staticData = new ThreadSpecific<ThreadGlobalData>; 99 return **ThreadGlobalData::staticData; 100 #else 101 if (!ThreadGlobalData::staticData) { 102 ThreadGlobalData::staticData = static_cast<ThreadGlobalData*>(fastMalloc(sizeof(ThreadGlobalData))); 103 // ThreadGlobalData constructor indirectly uses staticData, so we need to set up the memory before invoking it. 104 new (ThreadGlobalData::staticData) ThreadGlobalData; 127 if (!WTFThreadData::staticData) { 128 WTFThreadData::staticData = static_cast<WTFThreadData*>(fastMalloc(sizeof(WTFThreadData))); 129 // WTFThreadData constructor indirectly uses staticData, so we need to set up the memory before invoking it. 130 new (WTFThreadData::staticData) WTFThreadData; 105 131 } 106 return * ThreadGlobalData::staticData;132 return *WTFThreadData::staticData; 107 133 #endif 108 134 } 109 110 } // namespace WebCore111 135 112 #endif // ThreadGlobalData_h 136 } // namespace WTF 137 138 using WTF::WTFThreadData; 139 using WTF::wtfThreadData; 140 141 #endif // WTFThreadData_h
Note:
See TracChangeset
for help on using the changeset viewer.