Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(931)

Unified Diff: third_party/WebKit/Source/wtf/WTFThreadData.h

Issue 2646003003: Avoid checking for WTFThreadData::staticData in wtfThreadData() (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/wtf/WTFThreadData.h
diff --git a/third_party/WebKit/Source/wtf/WTFThreadData.h b/third_party/WebKit/Source/wtf/WTFThreadData.h
index a8228fce72e0e288153d3311b0ea25875cfe92b0..01a1a1b88ec6872c7d24dfbed26784877db49d94 100644
--- a/third_party/WebKit/Source/wtf/WTFThreadData.h
+++ b/third_party/WebKit/Source/wtf/WTFThreadData.h
@@ -55,6 +55,9 @@ class WTF_EXPORT WTFThreadData {
ThreadIdentifier threadId() const { return m_threadId; }
+ static void initializeOnOffThread();
+ static void initializeOnMainThread();
+
#if OS(WIN) && COMPILER(MSVC)
static size_t threadStackSize();
#endif
@@ -73,11 +76,37 @@ class WTF_EXPORT WTFThreadData {
friend WTFThreadData& wtfThreadData();
};
+// Special case WTFThreadData so accessors don't need to branch.
+template <>
+inline ThreadSpecific<WTFThreadData>::operator WTFThreadData*() {
+ DCHECK(isSet());
+#if defined(__GLIBC__) || OS(ANDROID) || OS(FREEBSD)
+ return static_cast<WTFThreadData*>(get());
+#else
+ if (UNLIKELY(internal::mayNotBeMainThread()))
+ return static_cast<WTFThreadData*>(get());
+ return m_mainThreadStorage;
+#endif
+}
+
+template <>
+inline void ThreadSpecific<WTFThreadData>::initializeOnOffThread() {
+ WTFThreadData* ptr = static_cast<WTFThreadData*>(Partitions::fastZeroedMalloc(
+ sizeof(WTFThreadData), WTF_HEAP_PROFILER_TYPE_NAME(WTFThreadData)));
+ set(ptr);
+ new (NotNull, ptr) WTFThreadData;
+}
+
+template <>
+inline void ThreadSpecific<WTFThreadData>::initializeOnMainThread() {
+ m_mainThreadStorage =
+ static_cast<WTFThreadData*>(Partitions::fastZeroedMalloc(
+ sizeof(WTFThreadData), WTF_HEAP_PROFILER_TYPE_NAME(WTFThreadData)));
+ set(m_mainThreadStorage);
+ new (NotNull, m_mainThreadStorage) WTFThreadData;
+}
+
inline WTFThreadData& wtfThreadData() {
- // WTFThreadData is used on main thread before it could possibly be used
- // on secondary ones, so there is no need for synchronization here.
- if (!WTFThreadData::staticData)
- WTFThreadData::staticData = new ThreadSpecific<WTFThreadData>;
return **WTFThreadData::staticData;
}

Powered by Google App Engine
This is Rietveld 408576698