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

Unified Diff: third_party/WebKit/Source/wtf/ThreadingWin.cpp

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/ThreadingPthreads.cpp ('k') | third_party/WebKit/Source/wtf/WTF.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/wtf/ThreadingWin.cpp
diff --git a/third_party/WebKit/Source/wtf/ThreadingWin.cpp b/third_party/WebKit/Source/wtf/ThreadingWin.cpp
index 44c81a573568b4c0ebd6952dc44647241e39ae66..7f207e1cc2714c4a483424918e78136014a4ac51 100644
--- a/third_party/WebKit/Source/wtf/ThreadingWin.cpp
+++ b/third_party/WebKit/Source/wtf/ThreadingWin.cpp
@@ -143,8 +143,37 @@ void initializeThreading() {
double_conversion::DoubleToStringConverter::EcmaScriptConverter();
}
+namespace {
+ThreadSpecificKey s_currentThreadKey;
+bool s_currentThreadKeyInitialized = false;
+} // namespace
+
+void initializeCurrentThread() {
+ DCHECK(!s_currentThreadKeyInitialized);
+ threadSpecificKeyCreate(&s_currentThreadKey, [](void*) {});
+ s_currentThreadKeyInitialized = true;
+}
+
ThreadIdentifier currentThread() {
- return wtfThreadData().threadId();
+ // This doesn't use WTF::ThreadSpecific (e.g. WTFThreadData) because
+ // ThreadSpecific now depends on currentThread. It is necessary to avoid this
+ // or a similar loop:
+ //
+ // currentThread
+ // -> wtfThreadData
+ // -> ThreadSpecific::operator*
+ // -> isMainThread
+ // -> currentThread
+ static_assert(sizeof(ThreadIdentifier) <= sizeof(void*),
+ "ThreadIdentifier must fit in a void*.");
+ DCHECK(s_currentThreadKeyInitialized);
+ void* value = threadSpecificGet(s_currentThreadKey);
+ if (UNLIKELY(!value)) {
+ value = reinterpret_cast<void*>(internal::currentThreadSyscall());
+ DCHECK(value);
+ threadSpecificSet(s_currentThreadKey, value);
+ }
+ return reinterpret_cast<intptr_t>(threadSpecificGet(s_currentThreadKey));
}
MutexBase::MutexBase(bool recursive) {
« no previous file with comments | « third_party/WebKit/Source/wtf/ThreadingPthreads.cpp ('k') | third_party/WebKit/Source/wtf/WTF.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698