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

Side by Side Diff: third_party/WebKit/Source/wtf/ThreadSpecific.h

Issue 2728453006: WTF: Initialize main-thread stack estimates when WTF starts up. (Closed)
Patch Set: fix cast for windows 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) 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2008 Apple Inc. All rights reserved.
3 * Copyright (C) 2009 Jian Li <jianli@chromium.org> 3 * Copyright (C) 2009 Jian Li <jianli@chromium.org>
4 * Copyright (C) 2012 Patrick Gansterer <paroga@paroga.com> 4 * Copyright (C) 2012 Patrick Gansterer <paroga@paroga.com>
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 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 inline bool ThreadSpecific<T>::isSet() { 261 inline bool ThreadSpecific<T>::isSet() {
262 return !!get(); 262 return !!get();
263 } 263 }
264 264
265 template <typename T> 265 template <typename T>
266 inline ThreadSpecific<T>::operator T*() { 266 inline ThreadSpecific<T>::operator T*() {
267 T* offThreadPtr; 267 T* offThreadPtr;
268 #if defined(__GLIBC__) || OS(ANDROID) || OS(FREEBSD) 268 #if defined(__GLIBC__) || OS(ANDROID) || OS(FREEBSD)
269 // TLS is fast on these platforms. 269 // TLS is fast on these platforms.
270 // TODO(csharrison): Qualify this statement for Android. 270 // TODO(csharrison): Qualify this statement for Android.
271 const bool mainThreadAlwaysChecksTLS = true;
271 T** ptr = &offThreadPtr; 272 T** ptr = &offThreadPtr;
272 offThreadPtr = static_cast<T*>(get()); 273 offThreadPtr = static_cast<T*>(get());
273 #else 274 #else
275 const bool mainThreadAlwaysChecksTLS = false;
274 T** ptr = &m_mainThreadStorage; 276 T** ptr = &m_mainThreadStorage;
275 if (UNLIKELY(internal::mayNotBeMainThread())) { 277 if (UNLIKELY(mayNotBeMainThread())) {
276 offThreadPtr = static_cast<T*>(get()); 278 offThreadPtr = static_cast<T*>(get());
277 ptr = &offThreadPtr; 279 ptr = &offThreadPtr;
278 } 280 }
279 #endif 281 #endif
280 // Set up thread-specific value's memory pointer before invoking constructor, 282 // Set up thread-specific value's memory pointer before invoking constructor,
281 // in case any function it calls needs to access the value, to avoid 283 // in case any function it calls needs to access the value, to avoid
282 // recursion. 284 // recursion.
283 if (UNLIKELY(!*ptr)) { 285 if (UNLIKELY(!*ptr)) {
284 *ptr = static_cast<T*>(Partitions::fastZeroedMalloc( 286 *ptr = static_cast<T*>(Partitions::fastZeroedMalloc(
285 sizeof(T), WTF_HEAP_PROFILER_TYPE_NAME(T))); 287 sizeof(T), WTF_HEAP_PROFILER_TYPE_NAME(T)));
288
289 // Even if we didn't realize we're on the main thread, we might still be.
290 // We need to double-check so that |m_mainThreadStorage| is populated.
291 if (!mainThreadAlwaysChecksTLS && UNLIKELY(ptr != &m_mainThreadStorage) &&
haraken 2017/03/06 01:44:03 This code is in a slow path. So I'm okay with drop
jbroman 2017/03/06 16:14:03 Even though |m_mainThreadStorage| will never be re
292 isMainThread()) {
293 m_mainThreadStorage = *ptr;
haraken 2017/03/06 01:44:03 Just to confirm: |*ptr| populates the thread-local
jbroman 2017/03/06 16:14:03 |ptr| either points to |offThreadPtr| (in this sta
294 }
295
286 set(*ptr); 296 set(*ptr);
287 new (NotNull, *ptr) T; 297 new (NotNull, *ptr) T;
288 } 298 }
289 return *ptr; 299 return *ptr;
290 } 300 }
291 301
292 template <typename T> 302 template <typename T>
293 inline T* ThreadSpecific<T>::operator->() { 303 inline T* ThreadSpecific<T>::operator->() {
294 return operator T*(); 304 return operator T*();
295 } 305 }
296 306
297 template <typename T> 307 template <typename T>
298 inline T& ThreadSpecific<T>::operator*() { 308 inline T& ThreadSpecific<T>::operator*() {
299 return *operator T*(); 309 return *operator T*();
300 } 310 }
301 311
302 } // namespace WTF 312 } // namespace WTF
303 313
304 using WTF::ThreadSpecific; 314 using WTF::ThreadSpecific;
305 315
306 #endif // WTF_ThreadSpecific_h 316 #endif // WTF_ThreadSpecific_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698