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

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

Issue 2728453006: WTF: Initialize main-thread stack estimates when WTF starts up. (Closed)
Patch Set: comment about why currentThread works this way Created 3 years, 9 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
« no previous file with comments | « third_party/WebKit/Source/wtf/StackUtil.cpp ('k') | third_party/WebKit/Source/wtf/Threading.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/wtf/ThreadSpecific.h
diff --git a/third_party/WebKit/Source/wtf/ThreadSpecific.h b/third_party/WebKit/Source/wtf/ThreadSpecific.h
index 5b197de00b5e533550547a6575b3cc4d7f3dfa1a..57c6392d3b3708febb032e0ee0a3fc6b4c3f1a36 100644
--- a/third_party/WebKit/Source/wtf/ThreadSpecific.h
+++ b/third_party/WebKit/Source/wtf/ThreadSpecific.h
@@ -268,11 +268,13 @@ inline ThreadSpecific<T>::operator T*() {
#if defined(__GLIBC__) || OS(ANDROID) || OS(FREEBSD)
// TLS is fast on these platforms.
// TODO(csharrison): Qualify this statement for Android.
+ const bool mainThreadAlwaysChecksTLS = true;
T** ptr = &offThreadPtr;
offThreadPtr = static_cast<T*>(get());
#else
+ const bool mainThreadAlwaysChecksTLS = false;
T** ptr = &m_mainThreadStorage;
- if (UNLIKELY(internal::mayNotBeMainThread())) {
+ if (UNLIKELY(mayNotBeMainThread())) {
offThreadPtr = static_cast<T*>(get());
ptr = &offThreadPtr;
}
@@ -283,6 +285,14 @@ inline ThreadSpecific<T>::operator T*() {
if (UNLIKELY(!*ptr)) {
*ptr = static_cast<T*>(Partitions::fastZeroedMalloc(
sizeof(T), WTF_HEAP_PROFILER_TYPE_NAME(T)));
+
+ // Even if we didn't realize we're on the main thread, we might still be.
+ // We need to double-check so that |m_mainThreadStorage| is populated.
+ if (!mainThreadAlwaysChecksTLS && UNLIKELY(ptr != &m_mainThreadStorage) &&
+ isMainThread()) {
+ m_mainThreadStorage = *ptr;
+ }
+
set(*ptr);
new (NotNull, *ptr) T;
}
« no previous file with comments | « third_party/WebKit/Source/wtf/StackUtil.cpp ('k') | third_party/WebKit/Source/wtf/Threading.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698