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

Side by Side Diff: third_party/WebKit/Source/wtf/ThreadingPthreads.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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2007, 2009 Apple Inc. All rights reserved. 2 * Copyright (C) 2007, 2009 Apple Inc. All rights reserved.
3 * Copyright (C) 2007 Justin Haygood (jhaygood@reaktix.com) 3 * Copyright (C) 2007 Justin Haygood (jhaygood@reaktix.com)
4 * Copyright (C) 2011 Research In Motion Limited. All rights reserved. 4 * Copyright (C) 2011 Research In Motion Limited. All rights reserved.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 9 *
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 void initializeThreading() { 78 void initializeThreading() {
79 // This should only be called once. 79 // This should only be called once.
80 WTFThreadData::initialize(); 80 WTFThreadData::initialize();
81 81
82 initializeDates(); 82 initializeDates();
83 // Force initialization of static DoubleToStringConverter converter variable 83 // Force initialization of static DoubleToStringConverter converter variable
84 // inside EcmaScriptConverter function while we are in single thread mode. 84 // inside EcmaScriptConverter function while we are in single thread mode.
85 double_conversion::DoubleToStringConverter::EcmaScriptConverter(); 85 double_conversion::DoubleToStringConverter::EcmaScriptConverter();
86 } 86 }
87 87
88 namespace {
89 ThreadSpecificKey s_currentThreadKey;
90 bool s_currentThreadKeyInitialized = false;
91 } // namespace
92
93 void initializeCurrentThread() {
94 DCHECK(!s_currentThreadKeyInitialized);
95 threadSpecificKeyCreate(&s_currentThreadKey, [](void*) {});
96 s_currentThreadKeyInitialized = true;
97 }
98
88 ThreadIdentifier currentThread() { 99 ThreadIdentifier currentThread() {
89 return wtfThreadData().threadId(); 100 // This doesn't use WTF::ThreadSpecific (e.g. WTFThreadData) because
101 // ThreadSpecific now depends on currentThread. It is necessary to avoid this
102 // or a similar loop:
103 //
104 // currentThread
105 // -> wtfThreadData
106 // -> ThreadSpecific::operator*
107 // -> isMainThread
108 // -> currentThread
109 static_assert(sizeof(ThreadIdentifier) <= sizeof(void*),
110 "ThreadIdentifier must fit in a void*.");
111 DCHECK(s_currentThreadKeyInitialized);
112 void* value = threadSpecificGet(s_currentThreadKey);
113 if (UNLIKELY(!value)) {
114 value = reinterpret_cast<void*>(
115 static_cast<intptr_t>(internal::currentThreadSyscall()));
116 DCHECK(value);
117 threadSpecificSet(s_currentThreadKey, value);
118 }
119 return reinterpret_cast<intptr_t>(threadSpecificGet(s_currentThreadKey));
90 } 120 }
91 121
92 MutexBase::MutexBase(bool recursive) { 122 MutexBase::MutexBase(bool recursive) {
93 pthread_mutexattr_t attr; 123 pthread_mutexattr_t attr;
94 pthread_mutexattr_init(&attr); 124 pthread_mutexattr_init(&attr);
95 pthread_mutexattr_settype( 125 pthread_mutexattr_settype(
96 &attr, recursive ? PTHREAD_MUTEX_RECURSIVE : PTHREAD_MUTEX_NORMAL); 126 &attr, recursive ? PTHREAD_MUTEX_RECURSIVE : PTHREAD_MUTEX_NORMAL);
97 127
98 int result = pthread_mutex_init(&m_mutex.m_internalMutex, &attr); 128 int result = pthread_mutex_init(&m_mutex.m_internalMutex, &attr);
99 DCHECK_EQ(result, 0); 129 DCHECK_EQ(result, 0);
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 } 254 }
225 255
226 void willCreateThread() { 256 void willCreateThread() {
227 s_threadCreated = true; 257 s_threadCreated = true;
228 } 258 }
229 #endif 259 #endif
230 260
231 } // namespace WTF 261 } // namespace WTF
232 262
233 #endif // OS(POSIX) 263 #endif // OS(POSIX)
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/wtf/Threading.h ('k') | third_party/WebKit/Source/wtf/ThreadingWin.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698