Changeset 76214 in webkit for trunk/Source/JavaScriptCore


Ignore:
Timestamp:
Jan 20, 2011, 12:49:00 AM (14 years ago)
Author:
[email protected]
Message:

Follow-up to r75766 / <rdar://problem/5469576>.

Reviewed by Maciej Stachowiak.

We were failing to initialize the key, causing all sorts of unexpected behavior.

  • wtf/FastMalloc.cpp:

(WTF::setThreadHeap):
(WTF::TCMalloc_ThreadCache::GetThreadHeap):
(WTF::TCMalloc_ThreadCache::InitTSD): Ensure that the key is initialized.

Location:
trunk/Source/JavaScriptCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r76193 r76214  
     12011-01-20  Mark Rowe  <[email protected]>
     2
     3        Reviewed by Maciej Stachowiak.
     4
     5        Follow-up to r75766 / <rdar://problem/5469576>.
     6
     7        We were failing to initialize the key, causing all sorts of unexpected behavior.
     8
     9        * wtf/FastMalloc.cpp:
     10        (WTF::setThreadHeap):
     11        (WTF::TCMalloc_ThreadCache::GetThreadHeap):
     12        (WTF::TCMalloc_ThreadCache::InitTSD): Ensure that the key is initialized.
     13
    1142011-01-18  Geoffrey Garen  <[email protected]>
    215
  • trunk/Source/JavaScriptCore/wtf/FastMalloc.cpp

    r75839 r76214  
    454454#if HAVE(PTHREAD_MACHDEP_H)
    455455#include <System/pthread_machdep.h>
     456
     457#if defined(__PTK_FRAMEWORK_JAVASCRIPTCORE_KEY0)
     458#define WTF_USE_PTHREAD_GETSPECIFIC_DIRECT 1
     459#endif
    456460#endif
    457461
     
    464468// use a function pointer. But that's not necessarily faster on other platforms, and we had
    465469// problems with this technique on Windows, so we'll do this only on Mac OS X.
    466 #if OS(DARWIN) && !defined(__PTK_FRAMEWORK_JAVASCRIPTCORE_KEY0)
     470#if OS(DARWIN)
     471#if !USE(PTHREAD_GETSPECIFIC_DIRECT)
    467472static void* (*pthread_getspecific_function_pointer)(pthread_key_t) = pthread_getspecific;
    468473#define pthread_getspecific(key) pthread_getspecific_function_pointer(key)
     474#else
     475#define pthread_getspecific(key) _pthread_getspecific_direct(key)
     476#define pthread_setspecific(key, val) _pthread_setspecific_direct(key, (val))
     477#endif
    469478#endif
    470479
     
    25202529// Until then, we use a slow path to get the heap object.
    25212530static bool tsd_inited = false;
     2531#if USE(PTHREAD_GETSPECIFIC_DIRECT)
     2532static const pthread_key_t heap_key = __PTK_FRAMEWORK_JAVASCRIPTCORE_KEY0;
     2533#else
    25222534static pthread_key_t heap_key;
     2535#endif
    25232536#if OS(WINDOWS)
    25242537DWORD tlsIndex = TLS_OUT_OF_INDEXES;
     
    25272540static ALWAYS_INLINE void setThreadHeap(TCMalloc_ThreadCache* heap)
    25282541{
     2542#if USE(PTHREAD_GETSPECIFIC_DIRECT)
     2543    // Can't have two libraries both doing this in the same process,
     2544    // so check and make this crash right away.
     2545    if (pthread_getspecific(heap_key))
     2546        CRASH();
     2547#endif
     2548
    25292549    // Still do pthread_setspecific even if there's an alternate form
    25302550    // of thread-local storage in use, to benefit from the delete callback.
     
    25332553#if OS(WINDOWS)
    25342554    TlsSetValue(tlsIndex, heap);
    2535 #elif defined(__PTK_FRAMEWORK_JAVASCRIPTCORE_KEY0)
    2536     // Can't have two libraries both doing this in the same process,
    2537     // so check and make this crash right away.
    2538     if (_pthread_getspecific_direct(__PTK_FRAMEWORK_JAVASCRIPTCORE_KEY0))
    2539         CRASH();
    2540     _pthread_setspecific_direct(__PTK_FRAMEWORK_JAVASCRIPTCORE_KEY0, heap);
    25412555#endif
    25422556}
     
    30503064#elif OS(WINDOWS)
    30513065    return static_cast<TCMalloc_ThreadCache*>(TlsGetValue(tlsIndex));
    3052 #elif defined(__PTK_FRAMEWORK_JAVASCRIPTCORE_KEY0)
    3053     return static_cast<TCMalloc_ThreadCache*>(_pthread_getspecific_direct(__PTK_FRAMEWORK_JAVASCRIPTCORE_KEY0));
    30543066#else
    30553067    return static_cast<TCMalloc_ThreadCache*>(pthread_getspecific(heap_key));
     
    30793091void TCMalloc_ThreadCache::InitTSD() {
    30803092  ASSERT(!tsd_inited);
     3093#if USE(PTHREAD_GETSPECIFIC_DIRECT)
     3094  pthread_key_init_np(heap_key, DestroyThreadCache);
     3095#else
    30813096  pthread_key_create(&heap_key, DestroyThreadCache);
     3097#endif
    30823098#if OS(WINDOWS)
    30833099  tlsIndex = TlsAlloc();
Note: See TracChangeset for help on using the changeset viewer.