| Index: third_party/WebKit/Source/wtf/ThreadSpecificWin.cpp
|
| diff --git a/third_party/WebKit/Source/wtf/ThreadSpecificWin.cpp b/third_party/WebKit/Source/wtf/ThreadSpecificWin.cpp
|
| index da2e0d4a2cde126e880edd1718ae293f6ad7a855..61e0b50103ab7f7ac6f11850980943599bfb4a6f 100644
|
| --- a/third_party/WebKit/Source/wtf/ThreadSpecificWin.cpp
|
| +++ b/third_party/WebKit/Source/wtf/ThreadSpecificWin.cpp
|
| @@ -30,108 +30,99 @@
|
|
|
| namespace WTF {
|
|
|
| -static DoublyLinkedList<PlatformThreadSpecificKey>& destructorsList()
|
| -{
|
| - DEFINE_STATIC_LOCAL(DoublyLinkedList<PlatformThreadSpecificKey>, staticList, ());
|
| - return staticList;
|
| +static DoublyLinkedList<PlatformThreadSpecificKey>& destructorsList() {
|
| + DEFINE_STATIC_LOCAL(DoublyLinkedList<PlatformThreadSpecificKey>, staticList,
|
| + ());
|
| + return staticList;
|
| }
|
|
|
| -static Mutex& destructorsMutex()
|
| -{
|
| - DEFINE_STATIC_LOCAL(Mutex, staticMutex, ());
|
| - return staticMutex;
|
| +static Mutex& destructorsMutex() {
|
| + DEFINE_STATIC_LOCAL(Mutex, staticMutex, ());
|
| + return staticMutex;
|
| }
|
|
|
| -class PlatformThreadSpecificKey : public DoublyLinkedListNode<PlatformThreadSpecificKey> {
|
| - USING_FAST_MALLOC(PlatformThreadSpecificKey);
|
| - WTF_MAKE_NONCOPYABLE(PlatformThreadSpecificKey);
|
| -public:
|
| - friend class DoublyLinkedListNode<PlatformThreadSpecificKey>;
|
| -
|
| - PlatformThreadSpecificKey(void (*destructor)(void *))
|
| - : m_destructor(destructor)
|
| - {
|
| - m_tlsKey = TlsAlloc();
|
| - if (m_tlsKey == TLS_OUT_OF_INDEXES)
|
| - CRASH();
|
| - }
|
| -
|
| - ~PlatformThreadSpecificKey()
|
| - {
|
| - TlsFree(m_tlsKey);
|
| - }
|
| -
|
| - void setValue(void* data) { TlsSetValue(m_tlsKey, data); }
|
| - void* value() { return TlsGetValue(m_tlsKey); }
|
| -
|
| - void callDestructor()
|
| - {
|
| - if (void* data = value())
|
| - m_destructor(data);
|
| - }
|
| -
|
| -private:
|
| - void (*m_destructor)(void *);
|
| - DWORD m_tlsKey;
|
| - PlatformThreadSpecificKey* m_prev;
|
| - PlatformThreadSpecificKey* m_next;
|
| +class PlatformThreadSpecificKey
|
| + : public DoublyLinkedListNode<PlatformThreadSpecificKey> {
|
| + USING_FAST_MALLOC(PlatformThreadSpecificKey);
|
| + WTF_MAKE_NONCOPYABLE(PlatformThreadSpecificKey);
|
| +
|
| + public:
|
| + friend class DoublyLinkedListNode<PlatformThreadSpecificKey>;
|
| +
|
| + PlatformThreadSpecificKey(void (*destructor)(void*))
|
| + : m_destructor(destructor) {
|
| + m_tlsKey = TlsAlloc();
|
| + if (m_tlsKey == TLS_OUT_OF_INDEXES)
|
| + CRASH();
|
| + }
|
| +
|
| + ~PlatformThreadSpecificKey() { TlsFree(m_tlsKey); }
|
| +
|
| + void setValue(void* data) { TlsSetValue(m_tlsKey, data); }
|
| + void* value() { return TlsGetValue(m_tlsKey); }
|
| +
|
| + void callDestructor() {
|
| + if (void* data = value())
|
| + m_destructor(data);
|
| + }
|
| +
|
| + private:
|
| + void (*m_destructor)(void*);
|
| + DWORD m_tlsKey;
|
| + PlatformThreadSpecificKey* m_prev;
|
| + PlatformThreadSpecificKey* m_next;
|
| };
|
|
|
| -long& tlsKeyCount()
|
| -{
|
| - static long count;
|
| - return count;
|
| +long& tlsKeyCount() {
|
| + static long count;
|
| + return count;
|
| }
|
|
|
| -DWORD* tlsKeys()
|
| -{
|
| - static DWORD keys[kMaxTlsKeySize];
|
| - return keys;
|
| +DWORD* tlsKeys() {
|
| + static DWORD keys[kMaxTlsKeySize];
|
| + return keys;
|
| }
|
|
|
| -void threadSpecificKeyCreate(ThreadSpecificKey* key, void (*destructor)(void *))
|
| -{
|
| - *key = new PlatformThreadSpecificKey(destructor);
|
| +void threadSpecificKeyCreate(ThreadSpecificKey* key,
|
| + void (*destructor)(void*)) {
|
| + *key = new PlatformThreadSpecificKey(destructor);
|
|
|
| - MutexLocker locker(destructorsMutex());
|
| - destructorsList().push(*key);
|
| + MutexLocker locker(destructorsMutex());
|
| + destructorsList().push(*key);
|
| }
|
|
|
| -void threadSpecificKeyDelete(ThreadSpecificKey key)
|
| -{
|
| - MutexLocker locker(destructorsMutex());
|
| - destructorsList().remove(key);
|
| - delete key;
|
| +void threadSpecificKeyDelete(ThreadSpecificKey key) {
|
| + MutexLocker locker(destructorsMutex());
|
| + destructorsList().remove(key);
|
| + delete key;
|
| }
|
|
|
| -void threadSpecificSet(ThreadSpecificKey key, void* data)
|
| -{
|
| - key->setValue(data);
|
| +void threadSpecificSet(ThreadSpecificKey key, void* data) {
|
| + key->setValue(data);
|
| }
|
|
|
| -void* threadSpecificGet(ThreadSpecificKey key)
|
| -{
|
| - return key->value();
|
| +void* threadSpecificGet(ThreadSpecificKey key) {
|
| + return key->value();
|
| }
|
|
|
| -void ThreadSpecificThreadExit()
|
| -{
|
| - for (long i = 0; i < tlsKeyCount(); i++) {
|
| - // The layout of ThreadSpecific<T>::Data does not depend on T. So we are safe to do the static cast to ThreadSpecific<int> in order to access its data member.
|
| - ThreadSpecific<int>::Data* data = static_cast<ThreadSpecific<int>::Data*>(TlsGetValue(tlsKeys()[i]));
|
| - if (data)
|
| - data->destructor(data);
|
| - }
|
| -
|
| - MutexLocker locker(destructorsMutex());
|
| - PlatformThreadSpecificKey* key = destructorsList().head();
|
| - while (key) {
|
| - PlatformThreadSpecificKey* nextKey = key->next();
|
| - key->callDestructor();
|
| - key = nextKey;
|
| - }
|
| +void ThreadSpecificThreadExit() {
|
| + for (long i = 0; i < tlsKeyCount(); i++) {
|
| + // The layout of ThreadSpecific<T>::Data does not depend on T. So we are safe to do the static cast to ThreadSpecific<int> in order to access its data member.
|
| + ThreadSpecific<int>::Data* data =
|
| + static_cast<ThreadSpecific<int>::Data*>(TlsGetValue(tlsKeys()[i]));
|
| + if (data)
|
| + data->destructor(data);
|
| + }
|
| +
|
| + MutexLocker locker(destructorsMutex());
|
| + PlatformThreadSpecificKey* key = destructorsList().head();
|
| + while (key) {
|
| + PlatformThreadSpecificKey* nextKey = key->next();
|
| + key->callDestructor();
|
| + key = nextKey;
|
| + }
|
| }
|
|
|
| -} // namespace WTF
|
| +} // namespace WTF
|
|
|
| -#endif // OS(WIN)
|
| +#endif // OS(WIN)
|
|
|