| 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 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 data->destructor = &ThreadSpecific<T>::destroy; | 217 data->destructor = &ThreadSpecific<T>::destroy; |
| 218 TlsSetValue(tlsKeys()[m_index], data); | 218 TlsSetValue(tlsKeys()[m_index], data); |
| 219 } | 219 } |
| 220 | 220 |
| 221 #else | 221 #else |
| 222 #error ThreadSpecific is not implemented for this platform. | 222 #error ThreadSpecific is not implemented for this platform. |
| 223 #endif | 223 #endif |
| 224 | 224 |
| 225 template <typename T> | 225 template <typename T> |
| 226 inline void ThreadSpecific<T>::destroy(void* ptr) { | 226 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); | 227 Data* data = static_cast<Data*>(ptr); |
| 233 | 228 |
| 234 #if OS(POSIX) | 229 #if OS(POSIX) |
| 235 // We want get() to keep working while data destructor works, because it can | 230 // We want get() to keep working while data destructor works, because it can |
| 236 // be called indirectly by the destructor. Some pthreads implementations | 231 // be called indirectly by the destructor. Some pthreads implementations |
| 237 // zero out the pointer before calling destroy(), so we temporarily reset it. | 232 // zero out the pointer before calling destroy(), so we temporarily reset it. |
| 238 pthread_setspecific(data->owner->m_key, ptr); | 233 pthread_setspecific(data->owner->m_key, ptr); |
| 239 #endif | 234 #endif |
| 240 | 235 |
| 236 // Never call destructors on the main thread. This is fine because Blink no |
| 237 // longer has a graceful shutdown sequence. Be careful to call this function |
| 238 // (which can be re-entrant) while the pointer is still set, to avoid lazily |
| 239 // allocating WTFThreadData after it is destroyed. |
| 240 if (isMainThread()) |
| 241 return; |
| 242 |
| 241 data->value->~T(); | 243 data->value->~T(); |
| 242 Partitions::fastFree(data->value); | 244 Partitions::fastFree(data->value); |
| 243 | 245 |
| 244 #if OS(POSIX) | 246 #if OS(POSIX) |
| 245 pthread_setspecific(data->owner->m_key, 0); | 247 pthread_setspecific(data->owner->m_key, 0); |
| 246 #elif OS(WIN) | 248 #elif OS(WIN) |
| 247 TlsSetValue(tlsKeys()[data->owner->m_index], 0); | 249 TlsSetValue(tlsKeys()[data->owner->m_index], 0); |
| 248 #else | 250 #else |
| 249 #error ThreadSpecific is not implemented for this platform. | 251 #error ThreadSpecific is not implemented for this platform. |
| 250 #endif | 252 #endif |
| (...skipping 29 matching lines...) Expand all Loading... |
| 280 template <typename T> | 282 template <typename T> |
| 281 inline T& ThreadSpecific<T>::operator*() { | 283 inline T& ThreadSpecific<T>::operator*() { |
| 282 return *operator T*(); | 284 return *operator T*(); |
| 283 } | 285 } |
| 284 | 286 |
| 285 } // namespace WTF | 287 } // namespace WTF |
| 286 | 288 |
| 287 using WTF::ThreadSpecific; | 289 using WTF::ThreadSpecific; |
| 288 | 290 |
| 289 #endif // WTF_ThreadSpecific_h | 291 #endif // WTF_ThreadSpecific_h |
| OLD | NEW |