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 28 matching lines...) Expand all Loading... | |
39 namespace WTF { | 39 namespace WTF { |
40 | 40 |
41 class AtomicStringTable; | 41 class AtomicStringTable; |
42 struct ICUConverterWrapper; | 42 struct ICUConverterWrapper; |
43 | 43 |
44 class WTF_EXPORT WTFThreadData { | 44 class WTF_EXPORT WTFThreadData { |
45 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); | 45 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); |
46 WTF_MAKE_NONCOPYABLE(WTFThreadData); | 46 WTF_MAKE_NONCOPYABLE(WTFThreadData); |
47 | 47 |
48 public: | 48 public: |
49 WTFThreadData(); | 49 enum ThreadType { MainThread, Other }; |
50 explicit WTFThreadData(ThreadType = Other); | |
50 ~WTFThreadData(); | 51 ~WTFThreadData(); |
51 | 52 |
52 AtomicStringTable& getAtomicStringTable() { return *m_atomicStringTable; } | 53 AtomicStringTable& getAtomicStringTable() { return *m_atomicStringTable; } |
53 | 54 |
54 ICUConverterWrapper& cachedConverterICU() { return *m_cachedConverterICU; } | 55 ICUConverterWrapper& cachedConverterICU() { return *m_cachedConverterICU; } |
55 | 56 |
56 ThreadIdentifier threadId() const { return m_threadId; } | 57 ThreadIdentifier threadId() const { return m_threadId; } |
57 | 58 |
59 #if OS(WIN) && COMPILER(MSVC) | |
60 size_t threadStackSize(); | |
61 #endif | |
62 | |
63 static void initialize(); | |
64 | |
65 static WTFThreadData& current(); | |
66 | |
67 static bool isMainThread(); | |
68 | |
69 // Returns true if this is the main thread, via a stack address hueristic. | |
70 // This is a subtle method and most callers should prefer isMainThread. | |
71 static bool stackBasedIsMainThread(); | |
haraken
2017/01/16 04:42:30
Let's mention that this may return false even if i
Charlie Harrison
2017/01/18 01:49:48
Done.
| |
72 | |
58 private: | 73 private: |
74 static WTFThreadData& mainThreadData(); | |
75 // m_threadId must be initialized first, as following members need it for | |
76 // initialization. | |
77 const ThreadIdentifier m_threadId; | |
78 | |
79 #if OS(WIN) && COMPILER(MSVC) | |
80 size_t m_threadStackSize = 0u; | |
81 #endif | |
82 | |
59 std::unique_ptr<AtomicStringTable> m_atomicStringTable; | 83 std::unique_ptr<AtomicStringTable> m_atomicStringTable; |
60 std::unique_ptr<ICUConverterWrapper> m_cachedConverterICU; | 84 std::unique_ptr<ICUConverterWrapper> m_cachedConverterICU; |
61 | 85 |
62 ThreadIdentifier m_threadId; | 86 static uintptr_t s_mainThreadStackStart; |
87 static uintptr_t s_mainThreadUnderestimatedStackSize; | |
88 static uint8_t s_mainThreadDataStorage[]; | |
63 | 89 |
64 static ThreadSpecific<WTFThreadData>* staticData; | 90 static ThreadSpecific<WTFThreadData>* staticData; |
65 friend WTFThreadData& wtfThreadData(); | |
66 }; | 91 }; |
67 | 92 |
68 inline WTFThreadData& wtfThreadData() { | 93 bool operator==(const WTFThreadData& data1, const WTFThreadData& data2); |
69 // WTFThreadData is used on main thread before it could possibly be used | |
70 // on secondary ones, so there is no need for synchronization here. | |
71 if (!WTFThreadData::staticData) | |
72 WTFThreadData::staticData = new ThreadSpecific<WTFThreadData>; | |
73 return **WTFThreadData::staticData; | |
74 } | |
75 | 94 |
76 } // namespace WTF | 95 } // namespace WTF |
77 | 96 |
78 using WTF::WTFThreadData; | 97 using WTF::WTFThreadData; |
79 using WTF::wtfThreadData; | |
80 | 98 |
81 #endif // WTFThreadData_h | 99 #endif // WTFThreadData_h |
OLD | NEW |