Changeset 41594 in webkit for trunk/JavaScriptCore


Ignore:
Timestamp:
Mar 11, 2009, 1:39:21 PM (16 years ago)
Author:
Adam Roben
Message:

Change the Windows implementation of ThreadSpecific to use functions instead of extern globals

This will make it easier to export ThreadSpecific from WebKit.

Reviewed by John Sullivan.

  • API/JSBase.cpp: (JSEvaluateScript): Touched this file to force ThreadSpecific.h to be copied into $WebKitOutputDir.
  • wtf/ThreadSpecific.h: Replaced g_tls_key_count with tlsKeyCount() and g_tls_keys with tlsKeys().

(WTF::::ThreadSpecific):
(WTF::::~ThreadSpecific):
(WTF::::get):
(WTF::::set):
(WTF::::destroy):
Updated to use the new functions.

  • wtf/ThreadSpecificWin.cpp: (WTF::tlsKeyCount): (WTF::tlsKeys): Added.

(WTF::ThreadSpecificThreadExit): Changed to use the new functions.

Location:
trunk/JavaScriptCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/API/JSBase.cpp

    r38528 r41594  
    5959        return 0;
    6060    }
    61    
     61
    6262    if (completion.value())
    6363        return toRef(completion.value());
  • trunk/JavaScriptCore/ChangeLog

    r41565 r41594  
     12009-03-11  Adam Roben  <[email protected]>
     2
     3        Change the Windows implementation of ThreadSpecific to use functions
     4        instead of extern globals
     5
     6        This will make it easier to export ThreadSpecific from WebKit.
     7
     8        Reviewed by John Sullivan.
     9
     10        * API/JSBase.cpp:
     11        (JSEvaluateScript):
     12        Touched this file to force ThreadSpecific.h to be copied into
     13        $WebKitOutputDir.
     14
     15        * wtf/ThreadSpecific.h: Replaced g_tls_key_count with tlsKeyCount()
     16        and g_tls_keys with tlsKeys().
     17
     18        (WTF::::ThreadSpecific):
     19        (WTF::::~ThreadSpecific):
     20        (WTF::::get):
     21        (WTF::::set):
     22        (WTF::::destroy):
     23        Updated to use the new functions.
     24
     25        * wtf/ThreadSpecificWin.cpp:
     26        (WTF::tlsKeyCount):
     27        (WTF::tlsKeys):
     28        Added.
     29
     30        (WTF::ThreadSpecificThreadExit): Changed to use the new functions.
     31
    1322009-03-10  Cameron Zwarich  <[email protected]>
    233
  • trunk/JavaScriptCore/wtf/ThreadSpecific.h

    r39708 r41594  
    130130const int kMaxTlsKeySize = 256;
    131131
    132 extern long g_tls_key_count;
    133 extern DWORD g_tls_keys[kMaxTlsKeySize];
     132long& tlsKeyCount();
     133DWORD* tlsKeys();
    134134
    135135template<typename T>
     
    141141        CRASH();
    142142
    143     m_index = InterlockedIncrement(&g_tls_key_count) - 1;
     143    m_index = InterlockedIncrement(&tlsKeyCount()) - 1;
    144144    if (m_index >= kMaxTlsKeySize)
    145145        CRASH();
    146     g_tls_keys[m_index] = tls_key;
     146    tlsKeys()[m_index] = tls_key;
    147147}
    148148
     
    151151{
    152152    // Does not invoke destructor functions. They will be called from ThreadSpecificThreadExit when the thread is detached.
    153     TlsFree(g_tls_keys[m_index]);
     153    TlsFree(tlsKeys()[m_index]);
    154154}
    155155
     
    157157inline T* ThreadSpecific<T>::get()
    158158{
    159     Data* data = static_cast<Data*>(TlsGetValue(g_tls_keys[m_index]));
     159    Data* data = static_cast<Data*>(TlsGetValue(tlsKeys()[m_index]));
    160160    return data ? data->value : 0;
    161161}
     
    167167    Data* data = new Data(ptr, this);
    168168    data->destructor = &ThreadSpecific<T>::destroy;
    169     TlsSetValue(g_tls_keys[m_index], data);
     169    TlsSetValue(tlsKeys()[m_index], data);
    170170}
    171171
     
    191191    pthread_setspecific(data->owner->m_key, 0);
    192192#elif PLATFORM(WIN_OS)
    193     TlsSetValue(g_tls_keys[data->owner->m_index], 0);
     193    TlsSetValue(tlsKeys()[data->owner->m_index], 0);
    194194#else
    195195#error ThreadSpecific is not implemented for this platform.
  • trunk/JavaScriptCore/wtf/ThreadSpecificWin.cpp

    r39708 r41594  
    3030namespace WTF {
    3131
    32 long g_tls_key_count = 0;
    33 DWORD g_tls_keys[kMaxTlsKeySize];
     32long& tlsKeyCount()
     33{
     34    static long count;
     35    return count;
     36}
     37
     38DWORD* tlsKeys()
     39{
     40    static DWORD keys[kMaxTlsKeySize];
     41    return keys;
     42}
    3443
    3544void ThreadSpecificThreadExit()
    3645{
    37     for (long i = 0; i < g_tls_key_count; i++) {
     46    for (long i = 0; i < tlsKeyCount(); i++) {
    3847        // 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.
    39         ThreadSpecific<int>::Data* data = static_cast<ThreadSpecific<int>::Data*>(TlsGetValue(g_tls_keys[i]));
     48        ThreadSpecific<int>::Data* data = static_cast<ThreadSpecific<int>::Data*>(TlsGetValue(tlsKeys()[i]));
    4049        if (data)
    4150            data->destructor(data);
Note: See TracChangeset for help on using the changeset viewer.