OLD | NEW |
---|---|
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 27 matching lines...) Expand all Loading... | |
38 * This semantic discrepancy does not impose any problem because nowhere in | 38 * This semantic discrepancy does not impose any problem because nowhere in |
39 * WebKit the repeated call bahavior is utilized. | 39 * WebKit the repeated call bahavior is utilized. |
40 */ | 40 */ |
41 | 41 |
42 #ifndef WTF_ThreadSpecific_h | 42 #ifndef WTF_ThreadSpecific_h |
43 #define WTF_ThreadSpecific_h | 43 #define WTF_ThreadSpecific_h |
44 | 44 |
45 #include "wtf/Allocator.h" | 45 #include "wtf/Allocator.h" |
46 #include "wtf/Noncopyable.h" | 46 #include "wtf/Noncopyable.h" |
47 #include "wtf/StdLibExtras.h" | 47 #include "wtf/StdLibExtras.h" |
48 #include "wtf/Threading.h" | |
Charlie Harrison
2017/01/13 16:38:45
Remove this.
Charlie Harrison
2017/01/13 16:56:55
Done.
| |
48 #include "wtf/WTF.h" | 49 #include "wtf/WTF.h" |
49 #include "wtf/WTFExport.h" | 50 #include "wtf/WTFExport.h" |
50 #include "wtf/allocator/PartitionAllocator.h" | 51 #include "wtf/allocator/PartitionAllocator.h" |
51 #include "wtf/allocator/Partitions.h" | 52 #include "wtf/allocator/Partitions.h" |
52 | 53 |
53 #if OS(POSIX) | 54 #if OS(POSIX) |
54 #include <pthread.h> | 55 #include <pthread.h> |
55 #elif OS(WIN) | 56 #elif OS(WIN) |
56 #include <windows.h> | 57 #include <windows.h> |
57 #endif | 58 #endif |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
217 data->destructor = &ThreadSpecific<T>::destroy; | 218 data->destructor = &ThreadSpecific<T>::destroy; |
218 TlsSetValue(tlsKeys()[m_index], data); | 219 TlsSetValue(tlsKeys()[m_index], data); |
219 } | 220 } |
220 | 221 |
221 #else | 222 #else |
222 #error ThreadSpecific is not implemented for this platform. | 223 #error ThreadSpecific is not implemented for this platform. |
223 #endif | 224 #endif |
224 | 225 |
225 template <typename T> | 226 template <typename T> |
226 inline void ThreadSpecific<T>::destroy(void* ptr) { | 227 inline void ThreadSpecific<T>::destroy(void* ptr) { |
227 // Never call destructors on the main thread. | |
228 // This is fine because Blink no longer has a graceful shutdown sequence. | |
229 if (isMainThread()) | |
230 return; | |
231 | |
232 Data* data = static_cast<Data*>(ptr); | 228 Data* data = static_cast<Data*>(ptr); |
233 | 229 |
234 #if OS(POSIX) | 230 #if OS(POSIX) |
235 // We want get() to keep working while data destructor works, because it can | 231 // We want get() to keep working while data destructor works, because it can |
236 // be called indirectly by the destructor. Some pthreads implementations | 232 // be called indirectly by the destructor. Some pthreads implementations |
237 // zero out the pointer before calling destroy(), so we temporarily reset it. | 233 // zero out the pointer before calling destroy(), so we temporarily reset it. |
238 pthread_setspecific(data->owner->m_key, ptr); | 234 pthread_setspecific(data->owner->m_key, ptr); |
239 #endif | 235 #endif |
240 | 236 |
237 // Never call destructors on the main thread. This is fine because Blink no | |
238 // longer has a graceful shutdown sequence. Be careful to call this function | |
239 // (which can be re-entrant) while the pointer is still set, to avoid lazily | |
240 // allocating WTFThreadData after it is destroyed. | |
241 if (isMainThread()) | |
242 return; | |
243 | |
241 data->value->~T(); | 244 data->value->~T(); |
242 Partitions::fastFree(data->value); | 245 Partitions::fastFree(data->value); |
243 | 246 |
244 #if OS(POSIX) | 247 #if OS(POSIX) |
245 pthread_setspecific(data->owner->m_key, 0); | 248 pthread_setspecific(data->owner->m_key, 0); |
246 #elif OS(WIN) | 249 #elif OS(WIN) |
247 TlsSetValue(tlsKeys()[data->owner->m_index], 0); | 250 TlsSetValue(tlsKeys()[data->owner->m_index], 0); |
248 #else | 251 #else |
249 #error ThreadSpecific is not implemented for this platform. | 252 #error ThreadSpecific is not implemented for this platform. |
250 #endif | 253 #endif |
(...skipping 29 matching lines...) Expand all Loading... | |
280 template <typename T> | 283 template <typename T> |
281 inline T& ThreadSpecific<T>::operator*() { | 284 inline T& ThreadSpecific<T>::operator*() { |
282 return *operator T*(); | 285 return *operator T*(); |
283 } | 286 } |
284 | 287 |
285 } // namespace WTF | 288 } // namespace WTF |
286 | 289 |
287 using WTF::ThreadSpecific; | 290 using WTF::ThreadSpecific; |
288 | 291 |
289 #endif // WTF_ThreadSpecific_h | 292 #endif // WTF_ThreadSpecific_h |
OLD | NEW |