Ignore:
Timestamp:
Apr 2, 2009, 3:29:24 AM (16 years ago)
Author:
Simon Hausmann
Message:

JavaScriptCore:

2009-04-02 Yael Aharon <[email protected]>

Reviewed by Simon Hausmann

https://bugs.webkit.org/show_bug.cgi?id=24490

Implement WTF::ThreadSpecific in the Qt build using
QThreadStorage.

WebCore:

2009-04-02 Yael Aharon <[email protected]>

Reviewed by Simon Hausmann.

https://bugs.webkit.org/show_bug.cgi?id=24490

Enable web workers in Qt.

File:
1 edited

Legend:

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

    r41594 r42167  
    4646#if USE(PTHREADS)
    4747#include <pthread.h>
     48#elif PLATFORM(QT)
     49#include <QThreadStorage>
    4850#elif PLATFORM(WIN_OS)
    4951#include <windows.h>
     
    5254namespace WTF {
    5355
    54 #if !USE(PTHREADS) && PLATFORM(WIN_OS)
     56#if !USE(PTHREADS) && !PLATFORM(QT) && PLATFORM(WIN_OS)
    5557// ThreadSpecificThreadExit should be called each time when a thread is detached.
    5658// This is done automatically for threads created with WTF::createThread.
     
    6769
    6870private:
    69 #if !USE(PTHREADS) && PLATFORM(WIN_OS)
     71#if !USE(PTHREADS) && !PLATFORM(QT) && PLATFORM(WIN_OS)
    7072    friend void ThreadSpecificThreadExit();
    7173#endif
     
    7577    void static destroy(void* ptr);
    7678
    77 #if USE(PTHREADS) || PLATFORM(WIN_OS)
     79#if USE(PTHREADS) || PLATFORM(QT) || PLATFORM(WIN_OS)
    7880    struct Data : Noncopyable {
    7981        Data(T* value, ThreadSpecific<T>* owner) : value(value), owner(owner) {}
     
    8991#if USE(PTHREADS)
    9092    pthread_key_t m_key;
     93#elif PLATFORM(QT)
     94    QThreadStorage<Data*> m_key;
    9195#elif PLATFORM(WIN_OS)
    9296    int m_index;
     
    121125    ASSERT(!get());
    122126    pthread_setspecific(m_key, new Data(ptr, this));
     127}
     128
     129#elif PLATFORM(QT)
     130
     131template<typename T>
     132inline ThreadSpecific<T>::ThreadSpecific()
     133{
     134}
     135
     136template<typename T>
     137inline ThreadSpecific<T>::~ThreadSpecific()
     138{
     139    Data* data = static_cast<Data*>(m_key.localData());
     140    if (data)
     141        data->destructor(data);
     142}
     143
     144template<typename T>
     145inline T* ThreadSpecific<T>::get()
     146{
     147    Data* data = static_cast<Data*>(m_key.localData());
     148    return data ? data->value : 0;
     149}
     150
     151template<typename T>
     152inline void ThreadSpecific<T>::set(T* ptr)
     153{
     154    ASSERT(!get());
     155    Data* data = new Data(ptr, this);
     156    data->destructor = &ThreadSpecific<T>::destroy;
     157    m_key.setLocalData(data);
    123158}
    124159
     
    190225#if USE(PTHREADS)
    191226    pthread_setspecific(data->owner->m_key, 0);
     227#elif PLATFORM(QT)
     228    data->owner->m_key.setLocalData(0);
    192229#elif PLATFORM(WIN_OS)
    193230    TlsSetValue(tlsKeys()[data->owner->m_index], 0);
Note: See TracChangeset for help on using the changeset viewer.