Changeset 26864 in webkit


Ignore:
Timestamp:
Oct 21, 2007 11:26:41 PM (17 years ago)
Author:
bdash
Message:

2007-10-21 Mark Rowe <mrowe@apple.com>

Reviewed by Alp.

http://bugs.webkit.org/show_bug.cgi?id=15575
Bug 15575: [GTK] Implement threading using GThread

  • wtf/Platform.h: Do not enable pthreads for Gtk.

2007-10-21 Mark Rowe <mrowe@apple.com>

Reviewed by Alp.

http://bugs.webkit.org/show_bug.cgi?id=15575
Bug 15575: [GTK] Implement threading using GThread

  • WebCore.pro: Remove ThreadingPthreads.cpp from the Gtk build and link against libgthreads.
  • loader/icon/IconDatabase.cpp: Initialize threading before the mutex is created to be compatible with gthreads. (WebCore::iconDatabase): (WebCore::IconDatabase::open):
  • platform/Threading.h:
  • platform/gtk/ThreadingGtk.cpp: Threading implementation in terms of GThread, based heavily on the pthreads implementation. (WebCore::initializeThreading): (WebCore::threadMapMutex): (WebCore::threadMap): (WebCore::establishIdentifierForThread): (WebCore::threadForIdentifier): (WebCore::clearThreadForIdentifier): (WebCore::createThread): (WebCore::waitForThreadCompletion): (WebCore::detachThread): (WebCore::Mutex::Mutex): (WebCore::Mutex::~Mutex): (WebCore::Mutex::lock): (WebCore::Mutex::tryLock): (WebCore::Mutex::unlock): (WebCore::ThreadCondition::ThreadCondition): (WebCore::ThreadCondition::~ThreadCondition): (WebCore::ThreadCondition::wait): (WebCore::ThreadCondition::signal): (WebCore::ThreadCondition::broadcast):
  • storage/Database.cpp: (WebCore::Database::Database): Initialize threading when Database is used so that it will be initialized even if the icon database is compiled out
Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/ChangeLog

    r26862 r26864  
     12007-10-21  Mark Rowe  <mrowe@apple.com>
     2
     3        Reviewed by Alp.
     4
     5        http://bugs.webkit.org/show_bug.cgi?id=15575
     6        Bug 15575: [GTK] Implement threading using GThread
     7
     8        * wtf/Platform.h: Do not enable pthreads for Gtk.
     9
    1102007-10-21  Mark Rowe  <mrowe@apple.com>
    211
  • trunk/JavaScriptCore/wtf/Platform.h

    r26824 r26864  
    215215#if PLATFORM(GTK)
    216216#define WTF_USE_CURL 1
    217 #define WTF_USE_PTHREADS 1
    218217#endif
    219218
  • trunk/WebCore/ChangeLog

    r26857 r26864  
     12007-10-21  Mark Rowe  <mrowe@apple.com>
     2
     3        Reviewed by Alp.
     4
     5        http://bugs.webkit.org/show_bug.cgi?id=15575
     6        Bug 15575: [GTK] Implement threading using GThread
     7
     8        * WebCore.pro: Remove ThreadingPthreads.cpp from the Gtk build and link against libgthreads.
     9        * loader/icon/IconDatabase.cpp: Initialize threading before the mutex is created to be compatible with gthreads.
     10        (WebCore::iconDatabase):
     11        (WebCore::IconDatabase::open):
     12        * platform/Threading.h:
     13        * platform/gtk/ThreadingGtk.cpp: Threading implementation in terms of GThread, based heavily on the pthreads implementation.
     14        (WebCore::initializeThreading):
     15        (WebCore::threadMapMutex):
     16        (WebCore::threadMap):
     17        (WebCore::establishIdentifierForThread):
     18        (WebCore::threadForIdentifier):
     19        (WebCore::clearThreadForIdentifier):
     20        (WebCore::createThread):
     21        (WebCore::waitForThreadCompletion):
     22        (WebCore::detachThread):
     23        (WebCore::Mutex::Mutex):
     24        (WebCore::Mutex::~Mutex):
     25        (WebCore::Mutex::lock):
     26        (WebCore::Mutex::tryLock):
     27        (WebCore::Mutex::unlock):
     28        (WebCore::ThreadCondition::ThreadCondition):
     29        (WebCore::ThreadCondition::~ThreadCondition):
     30        (WebCore::ThreadCondition::wait):
     31        (WebCore::ThreadCondition::signal):
     32        (WebCore::ThreadCondition::broadcast):
     33        * storage/Database.cpp:
     34        (WebCore::Database::Database): Initialize threading when Database is used so that it will be initialized even
     35        if the icon database is compiled out
     36
    1372007-10-21  Mark Rowe  <mrowe@apple.com>
    238
  • trunk/WebCore/WebCore.pro

    r26831 r26864  
    5050    QMAKE_LIBDIR_POST += $$split(TMPPATH,";")
    5151}
     52
     53gtk-port: PKGCONFIG += gthread-2.0
    5254
    5355# Optional components (look for defs in config.h and included files!)
     
    950952        platform/image-decoders/ico/ICOImageDecoder.cpp \
    951953        platform/image-decoders/xbm/XBMImageDecoder.cpp \
    952         platform/pthreads/ThreadingPthreads.cpp \
    953954        ../WebKit/gtk/Api/webkitgtkframe.cpp \
    954955        ../WebKit/gtk/Api/webkitgtkglobal.cpp \
  • trunk/WebCore/loader/icon/IconDatabase.cpp

    r26787 r26864  
    9696IconDatabase* iconDatabase()
    9797{
    98     if (!sharedIconDatabase)
     98    if (!sharedIconDatabase) {
     99        initializeThreading();
    99100        sharedIconDatabase = new IconDatabase;
     101    }
    100102    return sharedIconDatabase;
    101103}
     
    134136    // Formulate the full path for the database file
    135137    m_completeDatabasePath = pathByAppendingComponent(m_databaseDirectory, defaultDatabaseFilename());
    136 
    137     initializeThreading();
    138138
    139139    // Lock here as well as first thing in the thread so the tread doesn't actually commence until the pthread_create() call
  • trunk/WebCore/platform/Threading.h

    r26772 r26864  
    3737#endif
    3838
     39#if PLATFORM(GTK)
     40typedef struct _GMutex GMutex;
     41typedef struct _GCond GCond;
     42#endif
     43
    3944#include <stdint.h>
    4045
     
    4853int waitForThreadCompletion(ThreadIdentifier, void**);
    4954void detachThread(ThreadIdentifier);
     55
     56#if USE(PTHREADS)
     57typedef pthread_mutex_t PlatformMutex;
     58typedef pthread_cond_t PlatformCondition;
     59#elif PLATFORM(GTK)
     60typedef GMutex* PlatformMutex;
     61typedef GCond* PlatformCondition;
     62#else
     63typedef void* PlatformMutex;
     64typedef void* PlatformCondition;
     65#endif
    5066   
    5167class Mutex : Noncopyable {
     
    5773    bool tryLock();
    5874    void unlock();
    59    
    60 #if USE(PTHREADS)
     75
    6176public:
    62     pthread_mutex_t& impl() { return m_mutex; }
     77    PlatformMutex& impl() { return m_mutex; }
    6378private:
    64     pthread_mutex_t m_mutex;
    65 #endif
     79    PlatformMutex m_mutex;
    6680};
    6781
     
    8599   
    86100private:
    87 #if USE(PTHREADS)
    88     pthread_cond_t m_condition;
    89 #endif
     101    PlatformCondition m_condition;
    90102};
    91103   
     
    150162void initializeThreading();
    151163
    152 #if !PLATFORM(WIN)
     164#if !PLATFORM(WIN) && !PLATFORM(GTK)
    153165inline void initializeThreading()
    154166{
  • trunk/WebCore/platform/gtk/ThreadingGtk.cpp

    r26823 r26864  
    3030#include "Threading.h"
    3131
     32#include "HashMap.h"
    3233#include "Logging.h"
    33 #include "Vector.h"
    3434
    3535#include <glib.h>
     
    5050}
    5151
     52void initializeThreading()
     53{
     54    if (!g_thread_supported())
     55        g_thread_init(NULL);
     56    ASSERT(g_thread_supported());
    5257}
     58
     59static Mutex& threadMapMutex()
     60{
     61    static Mutex mutex;
     62    return mutex;
     63}
     64
     65static HashMap<ThreadIdentifier, GThread*>& threadMap()
     66{
     67    static HashMap<ThreadIdentifier, GThread*> map;
     68    return map;
     69}
     70
     71static ThreadIdentifier establishIdentifierForThread(GThread*& thread)
     72{
     73    MutexLocker locker(threadMapMutex());
     74
     75    static ThreadIdentifier identifierCount = 1;
     76
     77    threadMap().add(identifierCount, thread);
     78   
     79    return identifierCount++;
     80}
     81
     82static GThread* threadForIdentifier(ThreadIdentifier id)
     83{
     84    MutexLocker locker(threadMapMutex());
     85   
     86    return threadMap().get(id);
     87}
     88
     89static void clearThreadForIdentifier(ThreadIdentifier id)
     90{
     91    MutexLocker locker(threadMapMutex());
     92
     93    ASSERT(threadMap().contains(id));
     94   
     95    threadMap().remove(id);
     96}
     97
     98ThreadIdentifier createThread(ThreadFunction entryPoint, void* data)
     99{
     100    GThread* thread;
     101    if (!(thread = g_thread_create(entryPoint, data, TRUE, 0))) {
     102        LOG_ERROR("Failed to create thread at entry point %p with data %p", entryPoint, data);
     103        return 0;
     104    }
     105
     106    ThreadIdentifier threadID = establishIdentifierForThread(thread);
     107    LOG(Threading, "Created thread with thread id %u", threadID);
     108    return threadID;
     109}
     110
     111int waitForThreadCompletion(ThreadIdentifier threadID, void** result)
     112{
     113    ASSERT(threadID);
     114
     115    GThread* thread = threadForIdentifier(threadID);
     116
     117    *result = g_thread_join(thread);
     118
     119    clearThreadForIdentifier(threadID);
     120    return 0;
     121}
     122
     123void detachThread(ThreadIdentifier)
     124{
     125}
     126
     127Mutex::Mutex()
     128    : m_mutex(g_mutex_new())
     129{
     130}
     131
     132Mutex::~Mutex()
     133{
     134    g_mutex_free(m_mutex);
     135}
     136
     137void Mutex::lock()
     138{
     139    g_mutex_lock(m_mutex);
     140}
     141   
     142bool Mutex::tryLock()
     143{
     144    return g_mutex_trylock(m_mutex);
     145}
     146
     147void Mutex::unlock()
     148{
     149    g_mutex_unlock(m_mutex);
     150}
     151
     152ThreadCondition::ThreadCondition()
     153    : m_condition(g_cond_new())
     154{
     155}
     156
     157ThreadCondition::~ThreadCondition()
     158{
     159    g_cond_free(m_condition);
     160}
     161
     162void ThreadCondition::wait(Mutex& mutex)
     163{
     164    g_cond_wait(m_condition, mutex.impl());
     165}
     166
     167void ThreadCondition::signal()
     168{
     169    g_cond_signal(m_condition);
     170}
     171
     172void ThreadCondition::broadcast()
     173{
     174    g_cond_broadcast(m_condition);
     175}
     176
     177
     178}
  • trunk/WebCore/storage/Database.cpp

    r26797 r26864  
    126126        m_name = "";
    127127
     128    initializeThreading();
     129
    128130    m_guid = guidForOriginAndName(m_securityOrigin.toString(), name);
    129131
Note: See TracChangeset for help on using the changeset viewer.