OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. | 2 * Copyright (C) 2008 Apple 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 | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 public: | 48 public: |
49 WTFThreadData(); | 49 WTFThreadData(); |
50 ~WTFThreadData(); | 50 ~WTFThreadData(); |
51 | 51 |
52 AtomicStringTable& getAtomicStringTable() { return *m_atomicStringTable; } | 52 AtomicStringTable& getAtomicStringTable() { return *m_atomicStringTable; } |
53 | 53 |
54 ICUConverterWrapper& cachedConverterICU() { return *m_cachedConverterICU; } | 54 ICUConverterWrapper& cachedConverterICU() { return *m_cachedConverterICU; } |
55 | 55 |
56 ThreadIdentifier threadId() const { return m_threadId; } | 56 ThreadIdentifier threadId() const { return m_threadId; } |
57 | 57 |
| 58 static void initializeOnOffThread(); |
| 59 static void initializeOnMainThread(); |
| 60 |
58 #if OS(WIN) && COMPILER(MSVC) | 61 #if OS(WIN) && COMPILER(MSVC) |
59 static size_t threadStackSize(); | 62 static size_t threadStackSize(); |
60 #endif | 63 #endif |
61 | 64 |
62 private: | 65 private: |
63 std::unique_ptr<AtomicStringTable> m_atomicStringTable; | 66 std::unique_ptr<AtomicStringTable> m_atomicStringTable; |
64 std::unique_ptr<ICUConverterWrapper> m_cachedConverterICU; | 67 std::unique_ptr<ICUConverterWrapper> m_cachedConverterICU; |
65 | 68 |
66 ThreadIdentifier m_threadId; | 69 ThreadIdentifier m_threadId; |
67 | 70 |
68 #if OS(WIN) && COMPILER(MSVC) | 71 #if OS(WIN) && COMPILER(MSVC) |
69 size_t m_threadStackSize = 0u; | 72 size_t m_threadStackSize = 0u; |
70 #endif | 73 #endif |
71 | 74 |
72 static ThreadSpecific<WTFThreadData>* staticData; | 75 static ThreadSpecific<WTFThreadData>* staticData; |
73 friend WTFThreadData& wtfThreadData(); | 76 friend WTFThreadData& wtfThreadData(); |
74 }; | 77 }; |
75 | 78 |
| 79 // Special case WTFThreadData so accessors don't need to branch. |
| 80 template <> |
| 81 inline ThreadSpecific<WTFThreadData>::operator WTFThreadData*() { |
| 82 DCHECK(isSet()); |
| 83 #if defined(__GLIBC__) || OS(ANDROID) || OS(FREEBSD) |
| 84 return static_cast<WTFThreadData*>(get()); |
| 85 #else |
| 86 if (UNLIKELY(internal::mayNotBeMainThread())) |
| 87 return static_cast<WTFThreadData*>(get()); |
| 88 return m_mainThreadStorage; |
| 89 #endif |
| 90 } |
| 91 |
| 92 template <> |
| 93 inline void ThreadSpecific<WTFThreadData>::initializeOnOffThread() { |
| 94 WTFThreadData* ptr = static_cast<WTFThreadData*>(Partitions::fastZeroedMalloc( |
| 95 sizeof(WTFThreadData), WTF_HEAP_PROFILER_TYPE_NAME(WTFThreadData))); |
| 96 set(ptr); |
| 97 new (NotNull, ptr) WTFThreadData; |
| 98 } |
| 99 |
| 100 template <> |
| 101 inline void ThreadSpecific<WTFThreadData>::initializeOnMainThread() { |
| 102 m_mainThreadStorage = |
| 103 static_cast<WTFThreadData*>(Partitions::fastZeroedMalloc( |
| 104 sizeof(WTFThreadData), WTF_HEAP_PROFILER_TYPE_NAME(WTFThreadData))); |
| 105 set(m_mainThreadStorage); |
| 106 new (NotNull, m_mainThreadStorage) WTFThreadData; |
| 107 } |
| 108 |
76 inline WTFThreadData& wtfThreadData() { | 109 inline WTFThreadData& wtfThreadData() { |
77 // WTFThreadData is used on main thread before it could possibly be used | |
78 // on secondary ones, so there is no need for synchronization here. | |
79 if (!WTFThreadData::staticData) | |
80 WTFThreadData::staticData = new ThreadSpecific<WTFThreadData>; | |
81 return **WTFThreadData::staticData; | 110 return **WTFThreadData::staticData; |
82 } | 111 } |
83 | 112 |
84 } // namespace WTF | 113 } // namespace WTF |
85 | 114 |
86 using WTF::WTFThreadData; | 115 using WTF::WTFThreadData; |
87 using WTF::wtfThreadData; | 116 using WTF::wtfThreadData; |
88 | 117 |
89 #endif // WTFThreadData_h | 118 #endif // WTFThreadData_h |
OLD | NEW |