Changeset 57829 in webkit for trunk/JavaScriptCore/wtf/WTFThreadData.h
- Timestamp:
- Apr 19, 2010, 1:05:53 PM (15 years ago)
- File:
-
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
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.