Ignore:
Timestamp:
Sep 16, 2009, 6:18:55 AM (16 years ago)
Author:
[email protected]
Message:

2009-09-16 Zoltan Herczeg <[email protected]>

Reviewed by Simon Hausmann.

[Qt] Fix wtf/ThreadSpecific.h under Qt to free thread local objects.
https://bugs.webkit.org/show_bug.cgi?id=29295

This is an important fix when JavaScript workers are in use, since
unfreed ThreadGlobalDatas leak a big amount of memory (50-100k each).
QThreadStorage calls the destructor of a given object, which is the
ThreadSpecific::Data. Unlike pthread, Qt is object oriented, and does
not support the calling of a static utility function when the thread
is about to close. In this patch we call the ThreadSpecific::destroy()
utility function from the destructor of ThreadSpecific::Data. Moreover,
since Qt resets all thread local values to 0 before the calling of the
appropriate destructors, we set back the pointer to its original value.
This is necessary because the get() method of the ThreadSpecific
object may be called during the exuction of the destructor.

  • wtf/ThreadSpecific.h: (WTF::ThreadSpecific::Data::~Data): (WTF::::~ThreadSpecific): (WTF::::set): (WTF::::destroy):
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/wtf/ThreadSpecific.h

    r45891 r48412  
    8080    struct Data : Noncopyable {
    8181        Data(T* value, ThreadSpecific<T>* owner) : value(value), owner(owner) {}
     82#if PLATFORM(QT)
     83        ~Data() { owner->destroy(this); }
     84#endif
    8285
    8386        T* value;
    8487        ThreadSpecific<T>* owner;
    85 #if !USE(PTHREADS)
     88#if !USE(PTHREADS) && !PLATFORM(QT)
    8689        void (*destructor)(void*);
    8790#endif
     
    137140inline ThreadSpecific<T>::~ThreadSpecific()
    138141{
    139     Data* data = static_cast<Data*>(m_key.localData());
    140     if (data)
    141         data->destructor(data);
     142    // Does not invoke destructor functions. QThreadStorage will do it
    142143}
    143144
     
    154155    ASSERT(!get());
    155156    Data* data = new Data(ptr, this);
    156     data->destructor = &ThreadSpecific<T>::destroy;
    157157    m_key.setLocalData(data);
    158158}
     
    219219    pthread_setspecific(data->owner->m_key, ptr);
    220220#endif
    221    
     221#if PLATFORM(QT)
     222    // See comment as above
     223    data->owner->m_key.setLocalData(data);
     224#endif
     225
    222226    data->value->~T();
    223227    fastFree(data->value);
     
    226230    pthread_setspecific(data->owner->m_key, 0);
    227231#elif PLATFORM(QT)
    228     data->owner->m_key.setLocalData(0);
     232    // Do nothing here
    229233#elif PLATFORM(WIN_OS)
    230234    TlsSetValue(tlsKeys()[data->owner->m_index], 0);
     
    233237#endif
    234238
     239#if !PLATFORM(QT)
    235240    delete data;
     241#endif
    236242}
    237243
Note: See TracChangeset for help on using the changeset viewer.