<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[199729] trunk</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/199729">199729</a></dd>
<dt>Author</dt> <dd>commit-queue@webkit.org</dd>
<dt>Date</dt> <dd>2016-04-19 09:29:54 -0700 (Tue, 19 Apr 2016)</dd>
</dl>
<h3>Log Message</h3>
<pre>Unreviewed, rolling out <a href="http://trac.webkit.org/projects/webkit/changeset/199726">r199726</a>.
https://bugs.webkit.org/show_bug.cgi?id=156748
WebKit tests crash on Windows 32 (Requested by msaboff on
#webkit).
Reverted changeset:
"iTunes crashing JavaScriptCore.dll"
https://bugs.webkit.org/show_bug.cgi?id=156647
http://trac.webkit.org/changeset/199726</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkLayoutTestsplatformwinTestExpectations">trunk/LayoutTests/platform/win/TestExpectations</a></li>
<li><a href="#trunkSourceJavaScriptCoreChangeLog">trunk/Source/JavaScriptCore/ChangeLog</a></li>
<li><a href="#trunkSourceJavaScriptCoreheapMachineStackMarkercpp">trunk/Source/JavaScriptCore/heap/MachineStackMarker.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoreheapMachineStackMarkerh">trunk/Source/JavaScriptCore/heap/MachineStackMarker.h</a></li>
<li><a href="#trunkSourceWTFChangeLog">trunk/Source/WTF/ChangeLog</a></li>
<li><a href="#trunkSourceWTFwtfThreadSpecifich">trunk/Source/WTF/wtf/ThreadSpecific.h</a></li>
<li><a href="#trunkSourceWTFwtfThreadSpecificWincpp">trunk/Source/WTF/wtf/ThreadSpecificWin.cpp</a></li>
<li><a href="#trunkSourceWTFwtfThreadingWincpp">trunk/Source/WTF/wtf/ThreadingWin.cpp</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (199728 => 199729)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2016-04-19 15:48:00 UTC (rev 199728)
+++ trunk/LayoutTests/ChangeLog        2016-04-19 16:29:54 UTC (rev 199729)
</span><span class="lines">@@ -1,3 +1,17 @@
</span><ins>+2016-04-19 Commit Queue <commit-queue@webkit.org>
+
+ Unreviewed, rolling out r199726.
+ https://bugs.webkit.org/show_bug.cgi?id=156748
+
+ WebKit tests crash on Windows 32 (Requested by msaboff on
+ #webkit).
+
+ Reverted changeset:
+
+ "iTunes crashing JavaScriptCore.dll"
+ https://bugs.webkit.org/show_bug.cgi?id=156647
+ http://trac.webkit.org/changeset/199726
+
</ins><span class="cx"> 2016-04-19 Sergio Villar Senin <svillar@igalia.com>
</span><span class="cx">
</span><span class="cx"> [css-grid] Use the margin box for non-auto minimum sizes
</span></span></pre></div>
<a id="trunkLayoutTestsplatformwinTestExpectations"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/platform/win/TestExpectations (199728 => 199729)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/platform/win/TestExpectations        2016-04-19 15:48:00 UTC (rev 199728)
+++ trunk/LayoutTests/platform/win/TestExpectations        2016-04-19 16:29:54 UTC (rev 199729)
</span><span class="lines">@@ -437,10 +437,6 @@
</span><span class="cx"> storage/storagequota-request-quota.html [ Skip ]
</span><span class="cx"> fast/workers/worker-storagequota-query-usage.html [ Skip ]
</span><span class="cx">
</span><del>-# The number of workers in this test exceeds the number of
-# ThreadSpecificValues we have on Windows.
-fast/workers/dedicated-worker-lifecycle.html [ Skip ]
-
</del><span class="cx"> # Tests that require ENABLE(DOWNLOAD_ATTRIBUTE).
</span><span class="cx"> fast/dom/HTMLAnchorElement/anchor-nodownload.html [ Skip ]
</span><span class="cx"> fast/dom/HTMLAnchorElement/anchor-download.html [ Skip ]
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ChangeLog (199728 => 199729)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ChangeLog        2016-04-19 15:48:00 UTC (rev 199728)
+++ trunk/Source/JavaScriptCore/ChangeLog        2016-04-19 16:29:54 UTC (rev 199729)
</span><span class="lines">@@ -1,3 +1,17 @@
</span><ins>+2016-04-19 Commit Queue <commit-queue@webkit.org>
+
+ Unreviewed, rolling out r199726.
+ https://bugs.webkit.org/show_bug.cgi?id=156748
+
+ WebKit tests crash on Windows 32 (Requested by msaboff on
+ #webkit).
+
+ Reverted changeset:
+
+ "iTunes crashing JavaScriptCore.dll"
+ https://bugs.webkit.org/show_bug.cgi?id=156647
+ http://trac.webkit.org/changeset/199726
+
</ins><span class="cx"> 2016-04-19 Michael Saboff <msaboff@apple.com>
</span><span class="cx">
</span><span class="cx"> iTunes crashing JavaScriptCore.dll
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreheapMachineStackMarkercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/heap/MachineStackMarker.cpp (199728 => 199729)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/heap/MachineStackMarker.cpp        2016-04-19 15:48:00 UTC (rev 199728)
+++ trunk/Source/JavaScriptCore/heap/MachineStackMarker.cpp        2016-04-19 16:29:54 UTC (rev 199729)
</span><span class="lines">@@ -192,12 +192,14 @@
</span><span class="cx"> MachineThreads::MachineThreads(Heap* heap)
</span><span class="cx"> : m_registeredThreads(0)
</span><span class="cx"> , m_threadSpecificForMachineThreads(0)
</span><ins>+ , m_threadSpecificForThread(0)
</ins><span class="cx"> #if !ASSERT_DISABLED
</span><span class="cx"> , m_heap(heap)
</span><span class="cx"> #endif
</span><span class="cx"> {
</span><span class="cx"> UNUSED_PARAM(heap);
</span><span class="cx"> threadSpecificKeyCreate(&m_threadSpecificForMachineThreads, removeThread);
</span><ins>+ threadSpecificKeyCreate(&m_threadSpecificForThread, nullptr);
</ins><span class="cx"> activeMachineThreadsManager().add(this);
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -205,6 +207,7 @@
</span><span class="cx"> {
</span><span class="cx"> activeMachineThreadsManager().remove(this);
</span><span class="cx"> threadSpecificKeyDelete(m_threadSpecificForMachineThreads);
</span><ins>+ threadSpecificKeyDelete(m_threadSpecificForThread);
</ins><span class="cx">
</span><span class="cx"> LockHolder registeredThreadsLock(m_registeredThreadsMutex);
</span><span class="cx"> for (Thread* t = m_registeredThreads; t;) {
</span><span class="lines">@@ -231,6 +234,18 @@
</span><span class="cx"> #endif
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+#ifndef NDEBUG
+static bool isThreadInList(Thread* listHead, Thread* target)
+{
+ for (Thread* thread = listHead; thread; thread = thread->next) {
+ if (thread == target)
+ return true;
+ }
+
+ return false;
+}
+#endif
+
</ins><span class="cx"> void MachineThreads::addCurrentThread()
</span><span class="cx"> {
</span><span class="cx"> ASSERT(!m_heap->vm()->hasExclusiveThread() || m_heap->vm()->exclusiveThread() == std::this_thread::get_id());
</span><span class="lines">@@ -239,12 +254,15 @@
</span><span class="cx"> #ifndef NDEBUG
</span><span class="cx"> LockHolder lock(m_registeredThreadsMutex);
</span><span class="cx"> ASSERT(threadSpecificGet(m_threadSpecificForMachineThreads) == this);
</span><ins>+ ASSERT(threadSpecificGet(m_threadSpecificForThread));
+ ASSERT(isThreadInList(m_registeredThreads, static_cast<Thread*>(threadSpecificGet(m_threadSpecificForThread))));
</ins><span class="cx"> #endif
</span><span class="cx"> return;
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> Thread* thread = Thread::createForCurrentThread();
</span><span class="cx"> threadSpecificSet(m_threadSpecificForMachineThreads, this);
</span><ins>+ threadSpecificSet(m_threadSpecificForThread, thread);
</ins><span class="cx">
</span><span class="cx"> LockHolder lock(m_registeredThreadsMutex);
</span><span class="cx">
</span><span class="lines">@@ -254,15 +272,14 @@
</span><span class="cx">
</span><span class="cx"> Thread* MachineThreads::machineThreadForCurrentThread()
</span><span class="cx"> {
</span><ins>+ Thread* result = static_cast<Thread*>(threadSpecificGet(m_threadSpecificForThread));
+ RELEASE_ASSERT(result);
+#ifndef NDEBUG
</ins><span class="cx"> LockHolder lock(m_registeredThreadsMutex);
</span><del>- PlatformThread platformThread = getCurrentPlatformThread();
- for (Thread* thread = m_registeredThreads; thread; thread = thread->next) {
- if (*thread == platformThread)
- return thread;
- }
</del><ins>+ ASSERT(isThreadInList(m_registeredThreads, result));
+#endif
</ins><span class="cx">
</span><del>- RELEASE_ASSERT_NOT_REACHED();
- return nullptr;
</del><ins>+ return result;
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> void MachineThreads::removeThread(void* p)
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreheapMachineStackMarkerh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/heap/MachineStackMarker.h (199728 => 199729)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/heap/MachineStackMarker.h        2016-04-19 15:48:00 UTC (rev 199728)
+++ trunk/Source/JavaScriptCore/heap/MachineStackMarker.h        2016-04-19 16:29:54 UTC (rev 199729)
</span><span class="lines">@@ -159,6 +159,7 @@
</span><span class="cx"> Lock m_registeredThreadsMutex;
</span><span class="cx"> Thread* m_registeredThreads;
</span><span class="cx"> WTF::ThreadSpecificKey m_threadSpecificForMachineThreads;
</span><ins>+ WTF::ThreadSpecificKey m_threadSpecificForThread;
</ins><span class="cx"> #if !ASSERT_DISABLED
</span><span class="cx"> Heap* m_heap;
</span><span class="cx"> #endif
</span></span></pre></div>
<a id="trunkSourceWTFChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/ChangeLog (199728 => 199729)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/ChangeLog        2016-04-19 15:48:00 UTC (rev 199728)
+++ trunk/Source/WTF/ChangeLog        2016-04-19 16:29:54 UTC (rev 199729)
</span><span class="lines">@@ -1,3 +1,17 @@
</span><ins>+2016-04-19 Commit Queue <commit-queue@webkit.org>
+
+ Unreviewed, rolling out r199726.
+ https://bugs.webkit.org/show_bug.cgi?id=156748
+
+ WebKit tests crash on Windows 32 (Requested by msaboff on
+ #webkit).
+
+ Reverted changeset:
+
+ "iTunes crashing JavaScriptCore.dll"
+ https://bugs.webkit.org/show_bug.cgi?id=156647
+ http://trac.webkit.org/changeset/199726
+
</ins><span class="cx"> 2016-04-19 Michael Saboff <msaboff@apple.com>
</span><span class="cx">
</span><span class="cx"> iTunes crashing JavaScriptCore.dll
</span></span></pre></div>
<a id="trunkSourceWTFwtfThreadSpecifich"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/wtf/ThreadSpecific.h (199728 => 199729)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/wtf/ThreadSpecific.h        2016-04-19 15:48:00 UTC (rev 199728)
+++ trunk/Source/WTF/wtf/ThreadSpecific.h        2016-04-19 16:29:54 UTC (rev 199729)
</span><span class="lines">@@ -94,6 +94,9 @@
</span><span class="cx">
</span><span class="cx"> T* value;
</span><span class="cx"> ThreadSpecific<T>* owner;
</span><ins>+#if OS(WINDOWS)
+ void (*destructor)(void*);
+#endif
</ins><span class="cx"> };
</span><span class="cx">
</span><span class="cx"> #if USE(PTHREADS)
</span><span class="lines">@@ -155,64 +158,47 @@
</span><span class="cx">
</span><span class="cx"> #elif OS(WINDOWS)
</span><span class="cx">
</span><del>-// The maximum number of FLS keys that can be created. For simplification, we assume that:
</del><ins>+// The maximum number of TLS keys that can be created. For simplification, we assume that:
</ins><span class="cx"> // 1) Once the instance of ThreadSpecific<> is created, it will not be destructed until the program dies.
</span><span class="cx"> // 2) We do not need to hold many instances of ThreadSpecific<> data. This fixed number should be far enough.
</span><del>-const int kMaxFlsKeySize = 128;
</del><ins>+const int kMaxTlsKeySize = 256;
</ins><span class="cx">
</span><del>-WTF_EXPORT_PRIVATE long& flsKeyCount();
-WTF_EXPORT_PRIVATE DWORD* flsKeys();
</del><ins>+WTF_EXPORT_PRIVATE long& tlsKeyCount();
+WTF_EXPORT_PRIVATE DWORD* tlsKeys();
</ins><span class="cx">
</span><del>-typedef DWORD ThreadSpecificKey;
</del><ins>+class PlatformThreadSpecificKey;
+typedef PlatformThreadSpecificKey* ThreadSpecificKey;
</ins><span class="cx">
</span><del>-inline void threadSpecificKeyCreate(ThreadSpecificKey* key, void (*destructor)(void *))
-{
- DWORD flsKey = FlsAlloc(reinterpret_cast<PFLS_CALLBACK_FUNCTION>(destructor));
- if (flsKey == FLS_OUT_OF_INDEXES)
- CRASH();
</del><ins>+WTF_EXPORT_PRIVATE void threadSpecificKeyCreate(ThreadSpecificKey*, void (*)(void *));
+WTF_EXPORT_PRIVATE void threadSpecificKeyDelete(ThreadSpecificKey);
+WTF_EXPORT_PRIVATE void threadSpecificSet(ThreadSpecificKey, void*);
+WTF_EXPORT_PRIVATE void* threadSpecificGet(ThreadSpecificKey);
</ins><span class="cx">
</span><del>- *key = flsKey;
-}
-
-inline void threadSpecificKeyDelete(ThreadSpecificKey key)
-{
- FlsFree(key);
-}
-
-inline void threadSpecificSet(ThreadSpecificKey key, void* data)
-{
- FlsSetValue(key, data);
-}
-
-inline void* threadSpecificGet(ThreadSpecificKey key)
-{
- return FlsGetValue(key);
-}
-
</del><span class="cx"> template<typename T>
</span><span class="cx"> inline ThreadSpecific<T>::ThreadSpecific()
</span><span class="cx"> : m_index(-1)
</span><span class="cx"> {
</span><del>- DWORD flsKey = FlsAlloc(reinterpret_cast<PFLS_CALLBACK_FUNCTION>(destroy));
- if (flsKey == FLS_OUT_OF_INDEXES)
</del><ins>+ DWORD tlsKey = TlsAlloc();
+ if (tlsKey == TLS_OUT_OF_INDEXES)
</ins><span class="cx"> CRASH();
</span><span class="cx">
</span><del>- m_index = InterlockedIncrement(&flsKeyCount()) - 1;
- if (m_index >= kMaxFlsKeySize)
</del><ins>+ m_index = InterlockedIncrement(&tlsKeyCount()) - 1;
+ if (m_index >= kMaxTlsKeySize)
</ins><span class="cx"> CRASH();
</span><del>- flsKeys()[m_index] = flsKey;
</del><ins>+ tlsKeys()[m_index] = tlsKey;
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> template<typename T>
</span><span class="cx"> inline ThreadSpecific<T>::~ThreadSpecific()
</span><span class="cx"> {
</span><del>- FlsFree(flsKeys()[m_index]);
</del><ins>+ // Does not invoke destructor functions. They will be called from ThreadSpecificThreadExit when the thread is detached.
+ TlsFree(tlsKeys()[m_index]);
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> template<typename T>
</span><span class="cx"> inline T* ThreadSpecific<T>::get()
</span><span class="cx"> {
</span><del>- Data* data = static_cast<Data*>(FlsGetValue(flsKeys()[m_index]));
</del><ins>+ Data* data = static_cast<Data*>(TlsGetValue(tlsKeys()[m_index]));
</ins><span class="cx"> return data ? data->value : 0;
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -221,7 +207,8 @@
</span><span class="cx"> {
</span><span class="cx"> ASSERT(!get());
</span><span class="cx"> Data* data = new Data(ptr, this);
</span><del>- FlsSetValue(flsKeys()[m_index], data);
</del><ins>+ data->destructor = &ThreadSpecific<T>::destroy;
+ TlsSetValue(tlsKeys()[m_index], data);
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> #else
</span><span class="lines">@@ -245,7 +232,7 @@
</span><span class="cx"> #if USE(PTHREADS)
</span><span class="cx"> pthread_setspecific(data->owner->m_key, 0);
</span><span class="cx"> #elif OS(WINDOWS)
</span><del>- FlsSetValue(flsKeys()[data->owner->m_index], 0);
</del><ins>+ TlsSetValue(tlsKeys()[data->owner->m_index], 0);
</ins><span class="cx"> #else
</span><span class="cx"> #error ThreadSpecific is not implemented for this platform.
</span><span class="cx"> #endif
</span></span></pre></div>
<a id="trunkSourceWTFwtfThreadSpecificWincpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/wtf/ThreadSpecificWin.cpp (199728 => 199729)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/wtf/ThreadSpecificWin.cpp        2016-04-19 15:48:00 UTC (rev 199728)
+++ trunk/Source/WTF/wtf/ThreadSpecificWin.cpp        2016-04-19 16:29:54 UTC (rev 199729)
</span><span class="lines">@@ -24,22 +24,117 @@
</span><span class="cx">
</span><span class="cx"> #if OS(WINDOWS)
</span><span class="cx">
</span><ins>+#include "StdLibExtras.h"
+#include "ThreadingPrimitives.h"
+#include <wtf/DoublyLinkedList.h>
+
</ins><span class="cx"> #if !USE(PTHREADS)
</span><span class="cx">
</span><span class="cx"> namespace WTF {
</span><span class="cx">
</span><del>-long& flsKeyCount()
</del><ins>+static DoublyLinkedList<PlatformThreadSpecificKey>& destructorsList()
</ins><span class="cx"> {
</span><ins>+ static DoublyLinkedList<PlatformThreadSpecificKey> staticList;
+ return staticList;
+}
+
+static Mutex& destructorsMutex()
+{
+ static Mutex staticMutex;
+ return staticMutex;
+}
+
+class PlatformThreadSpecificKey : public DoublyLinkedListNode<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()
+{
</ins><span class="cx"> static long count;
</span><span class="cx"> return count;
</span><span class="cx"> }
</span><span class="cx">
</span><del>-DWORD* flsKeys()
</del><ins>+DWORD* tlsKeys()
</ins><span class="cx"> {
</span><del>- static DWORD keys[kMaxFlsKeySize];
</del><ins>+ static DWORD keys[kMaxTlsKeySize];
</ins><span class="cx"> return keys;
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+void threadSpecificKeyCreate(ThreadSpecificKey* key, void (*destructor)(void *))
+{
+ // Use the original malloc() instead of fastMalloc() to use this function in FastMalloc code.
+ *key = static_cast<PlatformThreadSpecificKey*>(::malloc(sizeof(PlatformThreadSpecificKey)));
+ new (*key) PlatformThreadSpecificKey(destructor);
+
+ MutexLocker locker(destructorsMutex());
+ destructorsList().push(*key);
+}
+
+void threadSpecificKeyDelete(ThreadSpecificKey key)
+{
+ MutexLocker locker(destructorsMutex());
+ destructorsList().remove(key);
+ key->~PlatformThreadSpecificKey();
+ ::free(key);
+}
+
+void threadSpecificSet(ThreadSpecificKey key, void* data)
+{
+ key->setValue(data);
+}
+
+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;
+ }
+}
+
</ins><span class="cx"> } // namespace WTF
</span><span class="cx">
</span><span class="cx"> #endif // !USE(PTHREADS)
</span></span></pre></div>
<a id="trunkSourceWTFwtfThreadingWincpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/wtf/ThreadingWin.cpp (199728 => 199729)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/wtf/ThreadingWin.cpp        2016-04-19 15:48:00 UTC (rev 199728)
+++ trunk/Source/WTF/wtf/ThreadingWin.cpp        2016-04-19 16:29:54 UTC (rev 199729)
</span><span class="lines">@@ -102,6 +102,10 @@
</span><span class="cx"> #include <wtf/RandomNumberSeed.h>
</span><span class="cx"> #include <wtf/WTFThreadData.h>
</span><span class="cx">
</span><ins>+#if !USE(PTHREADS) && OS(WINDOWS)
+#include "ThreadSpecific.h"
+#endif
+
</ins><span class="cx"> #if HAVE(ERRNO_H)
</span><span class="cx"> #include <errno.h>
</span><span class="cx"> #endif
</span><span class="lines">@@ -195,6 +199,11 @@
</span><span class="cx"> std::unique_ptr<ThreadFunctionInvocation> invocation(static_cast<ThreadFunctionInvocation*>(param));
</span><span class="cx"> invocation->function(invocation->data);
</span><span class="cx">
</span><ins>+#if !USE(PTHREADS) && OS(WINDOWS)
+ // Do the TLS cleanup.
+ ThreadSpecificThreadExit();
+#endif
+
</ins><span class="cx"> return 0;
</span><span class="cx"> }
</span><span class="cx">
</span></span></pre>
</div>
</div>
</body>
</html>