Ignore:
Timestamp:
Jun 23, 2010, 3:27:59 PM (15 years ago)
Author:
[email protected]
Message:

2010-06-23 Kwang Yul Seo <[email protected]>

Reviewed by Oliver Hunt.

[GTK] Implement ThreadSpecific with glib
https://bugs.webkit.org/show_bug.cgi?id=39829

Implement ThreadSpecific with glib's GStaticPrivate.
This patch makes it possible to build GTK port without pthread.

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

Legend:

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

    r54123 r61712  
    4848#elif PLATFORM(QT)
    4949#include <QThreadStorage>
     50#elif PLATFORM(GTK)
     51#include <glib.h>
    5052#elif OS(WINDOWS)
    5153#include <windows.h>
     
    5456namespace WTF {
    5557
    56 #if !USE(PTHREADS) && !PLATFORM(QT) && OS(WINDOWS)
     58#if !USE(PTHREADS) && !PLATFORM(QT) && !PLATFORM(GTK) && OS(WINDOWS)
    5759// ThreadSpecificThreadExit should be called each time when a thread is detached.
    5860// This is done automatically for threads created with WTF::createThread.
     
    6971
    7072private:
    71 #if !USE(PTHREADS) && !PLATFORM(QT) && OS(WINDOWS)
     73#if !USE(PTHREADS) && !PLATFORM(QT) && !PLATFORM(GTK) && OS(WINDOWS)
    7274    friend void ThreadSpecificThreadExit();
    7375#endif
     
    7779    void static destroy(void* ptr);
    7880
    79 #if USE(PTHREADS) || PLATFORM(QT) || OS(WINDOWS)
     81#if USE(PTHREADS) || PLATFORM(QT) || PLATFORM(GTK) || OS(WINDOWS)
    8082    struct Data : Noncopyable {
    8183        Data(T* value, ThreadSpecific<T>* owner) : value(value), owner(owner) {}
     
    8688        T* value;
    8789        ThreadSpecific<T>* owner;
    88 #if !USE(PTHREADS) && !PLATFORM(QT)
     90#if !USE(PTHREADS) && !PLATFORM(QT) && !PLATFORM(GTK)
    8991        void (*destructor)(void*);
    9092#endif
     
    99101#elif PLATFORM(QT)
    100102    QThreadStorage<Data*> m_key;
     103#elif PLATFORM(GTK)
     104    GStaticPrivate m_key;
    101105#elif OS(WINDOWS)
    102106    int m_index;
     
    185189    Data* data = new Data(ptr, this);
    186190    m_key.setLocalData(data);
     191}
     192
     193#elif PLATFORM(GTK)
     194
     195template<typename T>
     196inline ThreadSpecific<T>::ThreadSpecific()
     197{
     198    g_static_private_init(&m_key);
     199}
     200
     201template<typename T>
     202inline ThreadSpecific<T>::~ThreadSpecific()
     203{
     204    g_static_private_free(&m_key);
     205}
     206
     207template<typename T>
     208inline T* ThreadSpecific<T>::get()
     209{
     210    Data* data = static_cast<Data*>(g_static_private_get(&m_key));
     211    return data ? data->value : 0;
     212}
     213
     214template<typename T>
     215inline void ThreadSpecific<T>::set(T* ptr)
     216{
     217    ASSERT(!get());
     218    Data* data = new Data(ptr, this);
     219    g_static_private_set(&m_key, data, destroy);
    187220}
    188221
     
    254287    // Some pthreads implementations zero out the pointer before calling destroy(), so we temporarily reset it.
    255288    pthread_setspecific(data->owner->m_key, ptr);
     289#elif PLATFORM(GTK)
     290    // See comment as above
     291    g_static_private_set(&data->owner->m_key, data, 0);
    256292#endif
    257293#if PLATFORM(QT)
     
    267303#elif PLATFORM(QT)
    268304    // Do nothing here
     305#elif PLATFORM(GTK)
     306    g_static_private_set(&data->owner->m_key, 0, 0);
    269307#elif OS(WINDOWS)
    270308    TlsSetValue(tlsKeys()[data->owner->m_index], 0);
Note: See TracChangeset for help on using the changeset viewer.