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

Side by Side Diff: third_party/WebKit/Source/wtf/ThreadSpecific.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 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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 WTF_EXPORT void ThreadSpecificThreadExit(); 66 WTF_EXPORT void ThreadSpecificThreadExit();
67 #endif 67 #endif
68 68
69 template <typename T> 69 template <typename T>
70 class ThreadSpecific { 70 class ThreadSpecific {
71 USING_FAST_MALLOC(ThreadSpecific); 71 USING_FAST_MALLOC(ThreadSpecific);
72 WTF_MAKE_NONCOPYABLE(ThreadSpecific); 72 WTF_MAKE_NONCOPYABLE(ThreadSpecific);
73 73
74 public: 74 public:
75 ThreadSpecific(); 75 ThreadSpecific();
76 bool 76
77 isSet(); // Useful as a fast check to see if this thread has set this value. 77 // Useful as a fast check to see if this thread has set this value.
78 bool isSet();
79
80 // Must only be called during thread initialization.
81 void initializeOnOffThread();
esprehn 2017/01/19 23:47:45 OnOffThread is weirdly named, did this lose a word
Charlie Harrison 2017/01/19 23:54:41 Nope, I'm just awkward at naming things :P
82 void initializeOnMainThread();
78 T* operator->(); 83 T* operator->();
79 operator T*(); 84 operator T*();
80 T& operator*(); 85 T& operator*();
81 86
82 private: 87 private:
83 #if OS(WIN) 88 #if OS(WIN)
84 WTF_EXPORT friend void ThreadSpecificThreadExit(); 89 WTF_EXPORT friend void ThreadSpecificThreadExit();
85 #endif 90 #endif
86 91
87 // Not implemented. It's technically possible to destroy a thread specific 92 // Not implemented. It's technically possible to destroy a thread specific
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 // We want get() to keep working while data destructor works, because it can 238 // We want get() to keep working while data destructor works, because it can
234 // be called indirectly by the destructor. Some pthreads implementations 239 // be called indirectly by the destructor. Some pthreads implementations
235 // zero out the pointer before calling destroy(), so we temporarily reset it. 240 // zero out the pointer before calling destroy(), so we temporarily reset it.
236 pthread_setspecific(data->owner->m_key, ptr); 241 pthread_setspecific(data->owner->m_key, ptr);
237 #endif 242 #endif
238 243
239 // Never call destructors on the main thread. This is fine because Blink no 244 // Never call destructors on the main thread. This is fine because Blink no
240 // longer has a graceful shutdown sequence. Be careful to call this function 245 // longer has a graceful shutdown sequence. Be careful to call this function
241 // (which can be re-entrant) while the pointer is still set, to avoid lazily 246 // (which can be re-entrant) while the pointer is still set, to avoid lazily
242 // allocating WTFThreadData after it is destroyed. 247 // allocating WTFThreadData after it is destroyed.
243 if (isMainThread()) 248 if (internal::isMainThreadSyscall())
244 return; 249 return;
245 250
246 data->value->~T(); 251 data->value->~T();
247 Partitions::fastFree(data->value); 252 Partitions::fastFree(data->value);
248 253
249 #if OS(POSIX) 254 #if OS(POSIX)
250 pthread_setspecific(data->owner->m_key, 0); 255 pthread_setspecific(data->owner->m_key, 0);
251 #elif OS(WIN) 256 #elif OS(WIN)
252 TlsSetValue(tlsKeys()[data->owner->m_index], 0); 257 TlsSetValue(tlsKeys()[data->owner->m_index], 0);
253 #else 258 #else
(...skipping 29 matching lines...) Expand all
283 if (UNLIKELY(!*ptr)) { 288 if (UNLIKELY(!*ptr)) {
284 *ptr = static_cast<T*>(Partitions::fastZeroedMalloc( 289 *ptr = static_cast<T*>(Partitions::fastZeroedMalloc(
285 sizeof(T), WTF_HEAP_PROFILER_TYPE_NAME(T))); 290 sizeof(T), WTF_HEAP_PROFILER_TYPE_NAME(T)));
286 set(*ptr); 291 set(*ptr);
287 new (NotNull, *ptr) T; 292 new (NotNull, *ptr) T;
288 } 293 }
289 return *ptr; 294 return *ptr;
290 } 295 }
291 296
292 template <typename T> 297 template <typename T>
298 inline void ThreadSpecific<T>::initializeOnOffThread() {}
299 template <typename T>
300 inline void ThreadSpecific<T>::initializeOnMainThread() {}
301
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