From ec0fdafcde3d7d0e041a0eb14fd296d86a2197db Mon Sep 17 00:00:00 2001 From: "ap@webkit.org" Date: Sat, 23 Feb 2008 19:50:04 +0000 Subject: [PATCH] 2008-02-23 Alexey Proskuryakov Reviewed by Darin. Move basic threading support from WebCore to WTF. git-svn-id: http://svn.webkit.org/repository/webkit/trunk@30522 268f45cc-cd09-0410-ab3c-d52691b4dbfc --- JavaScriptCore/ChangeLog | 31 +++++++ JavaScriptCore/GNUmakefile.am | 1 + JavaScriptCore/JavaScriptCore.exp | 14 +++ JavaScriptCore/JavaScriptCore.pri | 9 ++ .../JavaScriptCore.vcproj/WTF/WTF.vcproj | 16 ++++ .../JavaScriptCore.xcodeproj/project.pbxproj | 16 ++++ JavaScriptCore/JavaScriptCoreSources.bkl | 1 + .../platform => JavaScriptCore/wtf}/Locker.h | 4 +- .../wtf}/MessageQueue.h | 17 +++- .../wtf}/Threading.h | 25 +++-- .../wtf}/ThreadingGtk.cpp | 24 ----- .../wtf}/ThreadingNone.cpp | 0 .../wtf}/ThreadingPthreads.cpp | 6 +- .../wtf/ThreadingWin.cpp | 92 +++++++++++++++++- WebCore/ChangeLog | 62 +++++++++++++ WebCore/ForwardingHeaders/wtf/Locker.h | 1 + WebCore/ForwardingHeaders/wtf/MessageQueue.h | 1 + WebCore/ForwardingHeaders/wtf/Threading.h | 1 + WebCore/GNUmakefile.am | 2 +- WebCore/WebCore.pro | 5 +- WebCore/WebCore.vcproj/WebCore.vcproj | 14 +-- WebCore/WebCore.xcodeproj/project.pbxproj | 32 ++----- WebCore/WebCoreSources.bkl | 1 - .../js/JSCustomSQLTransactionCallback.cpp | 1 + WebCore/dom/XMLTokenizer.cpp | 2 +- WebCore/loader/icon/IconDatabase.cpp | 3 +- WebCore/loader/icon/IconDatabase.h | 6 +- WebCore/platform/MainThread.h | 53 +++++++++++ WebCore/platform/SecurityOrigin.h | 2 +- WebCore/platform/gtk/MainThreadGtk.cpp | 60 ++++++++++++ .../mac/{Threading.mm => MainThreadMac.mm} | 2 +- .../qt/{ThreadingQt.cpp => MainThreadQt.cpp} | 4 +- WebCore/platform/sql/SQLValue.h | 2 +- WebCore/platform/sql/SQLiteAuthorizer.h | 2 +- WebCore/platform/sql/SQLiteDatabase.h | 2 +- .../{ThreadingWin.cpp => MainThreadWin.cpp} | 93 ++----------------- .../wx/{ThreadingWx.cpp => MainThreadWx.cpp} | 2 +- WebCore/storage/Database.cpp | 3 +- WebCore/storage/Database.h | 2 +- WebCore/storage/DatabaseTask.h | 2 +- WebCore/storage/DatabaseThread.h | 2 +- WebCore/storage/DatabaseTracker.cpp | 1 + WebCore/storage/OriginQuotaManager.h | 2 +- WebCore/storage/SQLError.h | 2 +- WebCore/storage/SQLResultSet.h | 2 +- WebCore/storage/SQLStatement.h | 8 +- WebCore/storage/SQLStatementCallback.h | 2 +- WebCore/storage/SQLStatementErrorCallback.h | 2 +- WebCore/storage/SQLTransaction.h | 2 +- WebCore/storage/SQLTransactionCallback.h | 2 +- WebCore/storage/SQLTransactionErrorCallback.h | 2 +- WebCore/webcore-wx.bkl | 2 +- WebKit/mac/ChangeLog | 9 ++ WebKit/mac/ForwardingHeaders/wtf/Locker.h | 1 + WebKit/mac/ForwardingHeaders/wtf/Threading.h | 1 + 55 files changed, 455 insertions(+), 201 deletions(-) rename {WebCore/platform => JavaScriptCore/wtf}/Locker.h (98%) rename {WebCore/platform => JavaScriptCore/wtf}/MessageQueue.h (92%) rename {WebCore/platform => JavaScriptCore/wtf}/Threading.h (95%) rename {WebCore/platform/gtk => JavaScriptCore/wtf}/ThreadingGtk.cpp (85%) rename {WebCore/platform => JavaScriptCore/wtf}/ThreadingNone.cpp (100%) rename {WebCore/platform/pthreads => JavaScriptCore/wtf}/ThreadingPthreads.cpp (97%) rename WebCore/platform/win/MutexWin.cpp => JavaScriptCore/wtf/ThreadingWin.cpp (55%) create mode 100644 WebCore/ForwardingHeaders/wtf/Locker.h create mode 100644 WebCore/ForwardingHeaders/wtf/MessageQueue.h create mode 100644 WebCore/ForwardingHeaders/wtf/Threading.h create mode 100644 WebCore/platform/MainThread.h create mode 100644 WebCore/platform/gtk/MainThreadGtk.cpp rename WebCore/platform/mac/{Threading.mm => MainThreadMac.mm} (99%) rename WebCore/platform/qt/{ThreadingQt.cpp => MainThreadQt.cpp} (98%) rename WebCore/platform/win/{ThreadingWin.cpp => MainThreadWin.cpp} (63%) rename WebCore/platform/wx/{ThreadingWx.cpp => MainThreadWx.cpp} (98%) create mode 100644 WebKit/mac/ForwardingHeaders/wtf/Locker.h create mode 100644 WebKit/mac/ForwardingHeaders/wtf/Threading.h diff --git a/JavaScriptCore/ChangeLog b/JavaScriptCore/ChangeLog index 27b7a82e587..1632292c380 100644 --- a/JavaScriptCore/ChangeLog +++ b/JavaScriptCore/ChangeLog @@ -1,3 +1,34 @@ +2008-02-23 Alexey Proskuryakov + + Reviewed by Darin. + + Move basic threading support from WebCore to WTF. + + Added mutex protection to MessageQueue::killed() for paranoia sake. + + * GNUmakefile.am: + * JavaScriptCore.exp: + * JavaScriptCore.pri: + * JavaScriptCore.vcproj/WTF/WTF.vcproj: + * JavaScriptCore.xcodeproj/project.pbxproj: + * JavaScriptCoreSources.bkl: + * wtf/Locker.h: Copied from WebCore/platform/Locker.h. + * wtf/MessageQueue.h: Copied from WebCore/platform/MessageQueue.h. + (WTF::::killed): + * wtf/Threading.h: Copied from WebCore/platform/Threading.h. + * wtf/ThreadingGtk.cpp: Copied from WebCore/platform/gtk/ThreadingGtk.cpp. + (WebCore::createThread): + * wtf/ThreadingNone.cpp: Copied from WebCore/platform/ThreadingNone.cpp. + * wtf/ThreadingPthreads.cpp: Copied from WebCore/platform/pthreads/ThreadingPthreads.cpp. + (WTF::createThread): + * wtf/ThreadingWin.cpp: Copied from WebCore/platform/win/ThreadingWin.cpp. + (WTF::createThread): + (WTF::Mutex::Mutex): + (WTF::Mutex::~Mutex): + (WTF::Mutex::lock): + (WTF::Mutex::tryLock): + (WTF::Mutex::unlock): + 2008-02-22 Geoffrey Garen Reviewed by Sam Weinig. diff --git a/JavaScriptCore/GNUmakefile.am b/JavaScriptCore/GNUmakefile.am index b1f0274694b..7e11e843b76 100644 --- a/JavaScriptCore/GNUmakefile.am +++ b/JavaScriptCore/GNUmakefile.am @@ -60,6 +60,7 @@ javascriptcore_sources += \ JavaScriptCore/pcre/pcre_xclass.cpp \ JavaScriptCore/wtf/Assertions.cpp \ JavaScriptCore/wtf/HashTable.cpp \ + JavaScriptCore/wtf/ThreadingGtk.cpp \ JavaScriptCore/wtf/unicode/UTF8.cpp # Debug build diff --git a/JavaScriptCore/JavaScriptCore.exp b/JavaScriptCore/JavaScriptCore.exp index 3e43074f0d9..ab313c78c6b 100644 --- a/JavaScriptCore/JavaScriptCore.exp +++ b/JavaScriptCore/JavaScriptCore.exp @@ -298,3 +298,17 @@ _jscore_collector_introspection _jscore_fastmalloc_introspection _kJSClassDefinitionEmpty _kjs_strtod +__ZN3WTF5MutexC1Ev +__ZN3WTF5MutexD1Ev +__ZN3WTF15ThreadCondition4waitERNS_5MutexE +__ZN3WTF5Mutex7tryLockEv +__ZN3WTF12detachThreadEj +__ZN3WTF13currentThreadEv +__ZN3WTF5Mutex4lockEv +__ZN3WTF23waitForThreadCompletionEjPPv +__ZN3WTF15ThreadConditionC1Ev +__ZN3WTF15ThreadConditionD1Ev +__ZN3WTF5Mutex6unlockEv +__ZN3WTF12createThreadEPFPvS0_ES0_ +__ZN3WTF15ThreadCondition9broadcastEv +__ZN3WTF15ThreadCondition6signalEv diff --git a/JavaScriptCore/JavaScriptCore.pri b/JavaScriptCore/JavaScriptCore.pri index d7cbc6a3d99..d5a8d7ba20e 100644 --- a/JavaScriptCore/JavaScriptCore.pri +++ b/JavaScriptCore/JavaScriptCore.pri @@ -113,10 +113,19 @@ SOURCES += \ } qt-port:SOURCES += \ + wtf/ThreadingPthreads.cpp \ bindings/qt/qt_class.cpp \ bindings/qt/qt_instance.cpp \ bindings/qt/qt_runtime.cpp +gtk-port:SOURCES += \ + wtf/ThreadingGtk.cpp +} + +!gtk-port:SOURCES += \ + wtf/ThreadingNone.cpp +} + !CONFIG(QTDIR_build) { defineTest(addExtraCompiler) { QMAKE_EXTRA_COMPILERS += $$1 diff --git a/JavaScriptCore/JavaScriptCore.vcproj/WTF/WTF.vcproj b/JavaScriptCore/JavaScriptCore.vcproj/WTF/WTF.vcproj index befffdd2f96..19609751448 100644 --- a/JavaScriptCore/JavaScriptCore.vcproj/WTF/WTF.vcproj +++ b/JavaScriptCore/JavaScriptCore.vcproj/WTF/WTF.vcproj @@ -273,10 +273,18 @@ RelativePath="..\..\wtf\ListRefPtr.h" > + + + + @@ -341,6 +349,14 @@ RelativePath="..\..\wtf\TCSystemAlloc.h" > + + + + diff --git a/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj b/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj index c53f2367278..b1981d0edd2 100644 --- a/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj +++ b/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj @@ -237,6 +237,10 @@ E11D51760B2E798D0056C188 /* StringExtras.h in Headers */ = {isa = PBXBuildFile; fileRef = E11D51750B2E798D0056C188 /* StringExtras.h */; settings = {ATTRIBUTES = (Private, ); }; }; E195679609E7CF1200B89D13 /* UnicodeIcu.h in Headers */ = {isa = PBXBuildFile; fileRef = E195678F09E7CF1200B89D13 /* UnicodeIcu.h */; settings = {ATTRIBUTES = (Private, ); }; }; E195679809E7CF1200B89D13 /* Unicode.h in Headers */ = {isa = PBXBuildFile; fileRef = E195679409E7CF1200B89D13 /* Unicode.h */; settings = {ATTRIBUTES = (Private, ); }; }; + E1EE79230D6C95CD00FEA3BA /* Threading.h in Headers */ = {isa = PBXBuildFile; fileRef = E1EE79220D6C95CD00FEA3BA /* Threading.h */; settings = {ATTRIBUTES = (Private, ); }; }; + E1EE79280D6C964500FEA3BA /* Locker.h in Headers */ = {isa = PBXBuildFile; fileRef = E1EE79270D6C964500FEA3BA /* Locker.h */; settings = {ATTRIBUTES = (Private, ); }; }; + E1EE793D0D6C9B9200FEA3BA /* ThreadingPthreads.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E1EE793C0D6C9B9200FEA3BA /* ThreadingPthreads.cpp */; }; + E1EE798C0D6CA53D00FEA3BA /* MessageQueue.h in Headers */ = {isa = PBXBuildFile; fileRef = E1EE798B0D6CA53D00FEA3BA /* MessageQueue.h */; settings = {ATTRIBUTES = (Private, ); }; }; E1EF79AA0CE97BA60088D500 /* UTF8.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E1EF79A80CE97BA60088D500 /* UTF8.cpp */; }; E1EF79AB0CE97BA60088D500 /* UTF8.h in Headers */ = {isa = PBXBuildFile; fileRef = E1EF79A90CE97BA60088D500 /* UTF8.h */; }; /* End PBXBuildFile section */ @@ -576,6 +580,10 @@ E11D51750B2E798D0056C188 /* StringExtras.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StringExtras.h; sourceTree = ""; }; E195678F09E7CF1200B89D13 /* UnicodeIcu.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UnicodeIcu.h; sourceTree = ""; }; E195679409E7CF1200B89D13 /* Unicode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Unicode.h; sourceTree = ""; }; + E1EE79220D6C95CD00FEA3BA /* Threading.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Threading.h; sourceTree = ""; }; + E1EE79270D6C964500FEA3BA /* Locker.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Locker.h; sourceTree = ""; }; + E1EE793C0D6C9B9200FEA3BA /* ThreadingPthreads.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ThreadingPthreads.cpp; sourceTree = ""; }; + E1EE798B0D6CA53D00FEA3BA /* MessageQueue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MessageQueue.h; sourceTree = ""; }; E1EF79A80CE97BA60088D500 /* UTF8.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = UTF8.cpp; sourceTree = ""; }; E1EF79A90CE97BA60088D500 /* UTF8.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UTF8.h; sourceTree = ""; }; F5BB2BC5030F772101FCFE1D /* completion.h */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = completion.h; sourceTree = ""; tabWidth = 8; }; @@ -899,8 +907,10 @@ 65DFC92F08EA173A00F7300B /* HashTraits.h */, 657EB7450B708F540063461B /* ListHashSet.h */, 148A1626095D16BB00666D0D /* ListRefPtr.h */, + E1EE79270D6C964500FEA3BA /* Locker.h */, 5DBD18AF0C5401A700C15EAE /* MallocZoneSupport.h */, BCF6553B0A2048DE0038A194 /* MathExtras.h */, + E1EE798B0D6CA53D00FEA3BA /* MessageQueue.h */, 9303F5690991190000AD71B8 /* Noncopyable.h */, 9303F5A409911A5800AD71B8 /* OwnArrayPtr.h */, 9303F567099118FA00AD71B8 /* OwnPtr.h */, @@ -916,6 +926,8 @@ 6541BD6F08E80A17002CBEE7 /* TCSpinLock.h */, 6541BD7008E80A17002CBEE7 /* TCSystemAlloc.cpp */, 6541BD7108E80A17002CBEE7 /* TCSystemAlloc.h */, + E1EE79220D6C95CD00FEA3BA /* Threading.h */, + E1EE793C0D6C9B9200FEA3BA /* ThreadingPthreads.cpp */, E195678D09E7CF1200B89D13 /* unicode */, 935AF46B09E9D9DB00ACD1D8 /* UnusedParam.h */, 6592C316098B7DE10003D4F6 /* Vector.h */, @@ -1145,6 +1157,7 @@ 65F340940CD6C1C000C0CA8B /* LocalStorage.h in Headers */, 5DBD18B00C5401A700C15EAE /* MallocZoneSupport.h in Headers */, BCF655590A2049710038A194 /* MathExtras.h in Headers */, + E1EE798C0D6CA53D00FEA3BA /* MessageQueue.h in Headers */, 932F5B840822A1C700736975 /* NP_jsobject.h in Headers */, 9303F56A0991190000AD71B8 /* Noncopyable.h in Headers */, 9303F5A509911A5800AD71B8 /* OwnArrayPtr.h in Headers */, @@ -1164,6 +1177,7 @@ 6541BD7208E80A17002CBEE7 /* TCPageMap.h in Headers */, 6541BD7308E80A17002CBEE7 /* TCSpinLock.h in Headers */, 6541BD7508E80A17002CBEE7 /* TCSystemAlloc.h in Headers */, + E1EE79230D6C95CD00FEA3BA /* Threading.h in Headers */, E1EF79AB0CE97BA60088D500 /* UTF8.h in Headers */, E195679809E7CF1200B89D13 /* Unicode.h in Headers */, E195679609E7CF1200B89D13 /* UnicodeIcu.h in Headers */, @@ -1241,6 +1255,7 @@ 93E26BFE08B151D400F85226 /* ucpinternal.h in Headers */, 932F5B5C0822A1C700736975 /* ustring.h in Headers */, 14ABB36F099C076400E2A24F /* value.h in Headers */, + E1EE79280D6C964500FEA3BA /* Locker.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1511,6 +1526,7 @@ 932F5BBD0822A1C700736975 /* runtime_method.cpp in Sources */, 932F5BBA0822A1C700736975 /* runtime_object.cpp in Sources */, 932F5BC50822A1C700736975 /* runtime_root.cpp in Sources */, + E1EE793D0D6C9B9200FEA3BA /* ThreadingPthreads.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/JavaScriptCore/JavaScriptCoreSources.bkl b/JavaScriptCore/JavaScriptCoreSources.bkl index 2a1312b9097..17c8d14a402 100644 --- a/JavaScriptCore/JavaScriptCoreSources.bkl +++ b/JavaScriptCore/JavaScriptCoreSources.bkl @@ -113,6 +113,7 @@ Source files for JSCore. wtf/FastMalloc.cpp wtf/HashTable.cpp wtf/TCSystemAlloc.cpp + wtf/ThreadingNone.cpp wtf/unicode/UTF8.cpp diff --git a/WebCore/platform/Locker.h b/JavaScriptCore/wtf/Locker.h similarity index 98% rename from WebCore/platform/Locker.h rename to JavaScriptCore/wtf/Locker.h index 7217bf1c898..9feec1f3f7e 100644 --- a/WebCore/platform/Locker.h +++ b/JavaScriptCore/wtf/Locker.h @@ -30,7 +30,7 @@ #include -namespace WebCore { +namespace WTF { template class Locker : Noncopyable { public: @@ -42,4 +42,6 @@ private: } +using WTF::Locker; + #endif diff --git a/WebCore/platform/MessageQueue.h b/JavaScriptCore/wtf/MessageQueue.h similarity index 92% rename from WebCore/platform/MessageQueue.h rename to JavaScriptCore/wtf/MessageQueue.h index dd354493034..c13b590ff2c 100644 --- a/WebCore/platform/MessageQueue.h +++ b/JavaScriptCore/wtf/MessageQueue.h @@ -29,12 +29,12 @@ #ifndef MessageQueue_h #define MessageQueue_h -#include "Threading.h" #include #include #include +#include -namespace WebCore { +namespace WTF { template class MessageQueue : Noncopyable { @@ -46,10 +46,10 @@ namespace WebCore { bool waitForMessage(DataType&); bool tryGetMessage(DataType&); void kill(); - bool killed() const { return m_killed; } + bool killed() const; private: - Mutex m_mutex; + mutable Mutex m_mutex; ThreadCondition m_condition; Deque m_queue; bool m_killed; @@ -110,6 +110,15 @@ namespace WebCore { m_killed = true; m_condition.broadcast(); } + + template + inline bool MessageQueue::killed() const + { + MutexLocker lock(m_mutex); + return m_killed; + } } +using WTF::MessageQueue; + #endif // MessageQueue_h diff --git a/WebCore/platform/Threading.h b/JavaScriptCore/wtf/Threading.h similarity index 95% rename from WebCore/platform/Threading.h rename to JavaScriptCore/wtf/Threading.h index 759351e5de9..1cb52729a40 100644 --- a/WebCore/platform/Threading.h +++ b/JavaScriptCore/wtf/Threading.h @@ -59,9 +59,8 @@ #ifndef Threading_h #define Threading_h -#include "Locker.h" - #include +#include #include #if PLATFORM(WIN_OS) @@ -92,7 +91,7 @@ class QWaitCondition; #include -namespace WebCore { +namespace WTF { typedef uint32_t ThreadIdentifier; typedef void* (*ThreadFunction)(void* argument); @@ -231,18 +230,26 @@ private: #endif }; -typedef void MainThreadFunction(void*); - -void callOnMainThread(MainThreadFunction*, void* context); - void initializeThreading(); -#if !PLATFORM(WIN) && !PLATFORM(GTK) +#if !PLATFORM(GTK) inline void initializeThreading() { } #endif -} // namespace WebCore +} // namespace WTF + +using WTF::Mutex; +using WTF::MutexLocker; +using WTF::ThreadCondition; +using WTF::ThreadIdentifier; +using WTF::ThreadSafeShared; + +using WTF::createThread; +using WTF::currentThread; +using WTF::detachThread; +using WTF::initializeThreading; +using WTF::waitForThreadCompletion; #endif // Threading_h diff --git a/WebCore/platform/gtk/ThreadingGtk.cpp b/JavaScriptCore/wtf/ThreadingGtk.cpp similarity index 85% rename from WebCore/platform/gtk/ThreadingGtk.cpp rename to JavaScriptCore/wtf/ThreadingGtk.cpp index 5ce6ba2ea7a..43c60c14bcf 100644 --- a/WebCore/platform/gtk/ThreadingGtk.cpp +++ b/JavaScriptCore/wtf/ThreadingGtk.cpp @@ -31,34 +31,11 @@ #include "Threading.h" #include "HashMap.h" -#include "Logging.h" #include namespace WebCore { -struct FunctionWithContext { - MainThreadFunction* function; - void* context; -}; - -static gboolean callFunctionOnMainThread(gpointer data) -{ - FunctionWithContext* functionWithContext = static_cast(data); - functionWithContext->function(functionWithContext->context); - delete functionWithContext; - return FALSE; -} - -void callOnMainThread(MainThreadFunction* function, void* context) -{ - ASSERT(function); - FunctionWithContext* functionWithContext = new FunctionWithContext; - functionWithContext->function = function; - functionWithContext->context = context; - g_timeout_add(0, callFunctionOnMainThread, functionWithContext); -} - void initializeThreading() { if (!g_thread_supported()) @@ -127,7 +104,6 @@ ThreadIdentifier createThread(ThreadFunction entryPoint, void* data) } ThreadIdentifier threadID = establishIdentifierForThread(thread); - LOG(Threading, "Created thread with thread id %u", threadID); return threadID; } diff --git a/WebCore/platform/ThreadingNone.cpp b/JavaScriptCore/wtf/ThreadingNone.cpp similarity index 100% rename from WebCore/platform/ThreadingNone.cpp rename to JavaScriptCore/wtf/ThreadingNone.cpp diff --git a/WebCore/platform/pthreads/ThreadingPthreads.cpp b/JavaScriptCore/wtf/ThreadingPthreads.cpp similarity index 97% rename from WebCore/platform/pthreads/ThreadingPthreads.cpp rename to JavaScriptCore/wtf/ThreadingPthreads.cpp index c12fd924f2e..2fea5ba7df3 100644 --- a/WebCore/platform/pthreads/ThreadingPthreads.cpp +++ b/JavaScriptCore/wtf/ThreadingPthreads.cpp @@ -29,12 +29,11 @@ #include "config.h" #include "Threading.h" -#include "Logging.h" #include #include -namespace WebCore { +namespace WTF { static Mutex& threadMapMutex() { @@ -97,7 +96,6 @@ ThreadIdentifier createThread(ThreadFunction entryPoint, void* data) } ThreadIdentifier threadID = establishIdentifierForPthreadHandle(threadHandle); - LOG(Threading, "Created thread with thread id %u", threadID); return threadID; } @@ -197,4 +195,4 @@ void ThreadCondition::broadcast() ASSERT(false); } -} // namespace WebCore +} // namespace WTF diff --git a/WebCore/platform/win/MutexWin.cpp b/JavaScriptCore/wtf/ThreadingWin.cpp similarity index 55% rename from WebCore/platform/win/MutexWin.cpp rename to JavaScriptCore/wtf/ThreadingWin.cpp index 41d7fe45cb9..46dff939cf8 100644 --- a/WebCore/platform/win/MutexWin.cpp +++ b/JavaScriptCore/wtf/ThreadingWin.cpp @@ -1,6 +1,5 @@ /* - * Copyright (C) 2007 Apple Inc. All rights reserved. - * Copyright (C) 2007 Brent Fulgham + * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -26,10 +25,95 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ + #include "config.h" #include "Threading.h" -namespace WebCore { +#include +#include + +namespace WTF { + +static Mutex& threadMapMutex() +{ + static Mutex mutex; + return mutex; +} + +static HashMap& threadMap() +{ + static HashMap map; + return map; +} + +static void storeThreadHandleByIdentifier(DWORD threadID, HANDLE threadHandle) +{ + MutexLocker locker(threadMapMutex()); + threadMap().add(threadID, threadHandle); +} + +static HANDLE threadHandleForIdentifier(ThreadIdentifier id) +{ + MutexLocker locker(threadMapMutex()); + return threadMap().get(id); +} + +static void clearThreadHandleForIdentifier(ThreadIdentifier id) +{ + MutexLocker locker(threadMapMutex()); + ASSERT(threadMap().contains(id)); + threadMap().remove(id); +} + +ThreadIdentifier createThread(ThreadFunction entryPoint, void* data) +{ + DWORD threadIdentifier = 0; + ThreadIdentifier threadID = 0; + HANDLE hEvent = ::CreateEvent(0, FALSE, FALSE, 0); + HANDLE threadHandle = ::CreateThread(0, 0, (LPTHREAD_START_ROUTINE)entryPoint, data, 0, &threadIdentifier); + if (!threadHandle) { + LOG_ERROR("Failed to create thread at entry point %p with data %p", entryPoint, data); + return 0; + } + + threadID = static_cast(threadIdentifier); + storeThreadHandleByIdentifier(threadIdentifier, threadHandle); + + return threadID; +} + +int waitForThreadCompletion(ThreadIdentifier threadID, void** result) +{ + ASSERT(threadID); + + HANDLE threadHandle = threadHandleForIdentifier(threadID); + if (!threadHandle) + LOG_ERROR("ThreadIdentifier %u did not correspond to an active thread when trying to quit", threadID); + + DWORD joinResult = ::WaitForSingleObject(threadHandle, INFINITE); + if (joinResult == WAIT_FAILED) + LOG_ERROR("ThreadIdentifier %u was found to be deadlocked trying to quit", threadID); + + ::CloseHandle(threadHandle); + clearThreadHandleForIdentifier(threadID); + + return joinResult; +} + +void detachThread(ThreadIdentifier threadID) +{ + ASSERT(threadID); + + HANDLE threadHandle = threadHandleForIdentifier(threadID); + if (threadHandle) + ::CloseHandle(threadHandle); + clearThreadHandleForIdentifier(threadID); +} + +ThreadIdentifier currentThread() +{ + return static_cast(::GetCurrentThreadId()); +} Mutex::Mutex() { @@ -80,4 +164,4 @@ void Mutex::unlock() ::LeaveCriticalSection(&m_mutex.m_internalMutex); } -} // namespace WebCore +} // namespace WTF diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog index af81f67393b..561ffeaee42 100644 --- a/WebCore/ChangeLog +++ b/WebCore/ChangeLog @@ -1,3 +1,65 @@ +2008-02-23 Alexey Proskuryakov + + Reviewed by Darin. + + Move basic threading support from WebCore to WTF. + + One call that remains in WebCore is callOnMainThread(), and it has its own header now. + + * ForwardingHeaders/wtf/Locker.h: Added. + * ForwardingHeaders/wtf/MessageQueue.h: Added. + * ForwardingHeaders/wtf/Threading.h: Added. + * GNUmakefile.am: + * WebCore.pro: + * WebCore.vcproj/WebCore.vcproj: + * WebCore.xcodeproj/project.pbxproj: + * WebCoreSources.bkl: + * bindings/js/JSCustomSQLTransactionCallback.cpp: + * dom/XMLTokenizer.cpp: + * loader/icon/IconDatabase.cpp: + (WebCore::iconDatabase): + * loader/icon/IconDatabase.h: + * platform/Locker.h: Removed. + * platform/MainThread.h: Copied from WebCore/platform/Threading.h. + (WebCore::initializeThreadingAndMainThread): + * platform/MessageQueue.h: Removed. + * platform/SecurityOrigin.h: + * platform/Threading.h: Removed. + * platform/ThreadingNone.cpp: Removed. + * platform/gtk/MainThreadGtk.cpp: Copied from WebCore/platform/gtk/ThreadingGtk.cpp. + * platform/gtk/ThreadingGtk.cpp: Removed. + * platform/mac/MainThreadMac.mm: Copied from WebCore/platform/mac/Threading.mm. + * platform/mac/Threading.mm: Removed. + * platform/pthreads: Removed. + * platform/pthreads/ThreadingPthreads.cpp: Removed. + * platform/qt/MainThreadQt.cpp: Copied from WebCore/platform/qt/ThreadingQt.cpp. + * platform/qt/ThreadingQt.cpp: Removed. + * platform/sql/SQLValue.h: + * platform/sql/SQLiteAuthorizer.h: + * platform/sql/SQLiteDatabase.h: + * platform/win/MainThreadWin.cpp: Copied from WebCore/platform/win/ThreadingWin.cpp. + (WebCore::initializeThreadingAndMainThread): + * platform/win/MutexWin.cpp: Removed. + * platform/win/ThreadingWin.cpp: Removed. + * platform/wx/MainThreadWx.cpp: Copied from WebCore/platform/wx/ThreadingWx.cpp. + * platform/wx/ThreadingWx.cpp: Removed. + * storage/Database.cpp: + (WebCore::Database::Database): + * storage/Database.h: + * storage/DatabaseTask.h: + * storage/DatabaseThread.h: + * storage/DatabaseTracker.cpp: + * storage/OriginQuotaManager.h: + * storage/SQLError.h: + * storage/SQLResultSet.h: + * storage/SQLStatement.h: + * storage/SQLStatementCallback.h: + * storage/SQLStatementErrorCallback.h: + * storage/SQLTransaction.h: + * storage/SQLTransactionCallback.h: + * storage/SQLTransactionErrorCallback.h: + * webcore-wx.bkl: + 2008-02-23 David Kilzer Please clarify licensing for some files diff --git a/WebCore/ForwardingHeaders/wtf/Locker.h b/WebCore/ForwardingHeaders/wtf/Locker.h new file mode 100644 index 00000000000..75b0acd594e --- /dev/null +++ b/WebCore/ForwardingHeaders/wtf/Locker.h @@ -0,0 +1 @@ +#include diff --git a/WebCore/ForwardingHeaders/wtf/MessageQueue.h b/WebCore/ForwardingHeaders/wtf/MessageQueue.h new file mode 100644 index 00000000000..986cca5fdaa --- /dev/null +++ b/WebCore/ForwardingHeaders/wtf/MessageQueue.h @@ -0,0 +1 @@ +#include diff --git a/WebCore/ForwardingHeaders/wtf/Threading.h b/WebCore/ForwardingHeaders/wtf/Threading.h new file mode 100644 index 00000000000..17359e5d29d --- /dev/null +++ b/WebCore/ForwardingHeaders/wtf/Threading.h @@ -0,0 +1 @@ +#include diff --git a/WebCore/GNUmakefile.am b/WebCore/GNUmakefile.am index 7a44aaae23a..c63c7b8faa2 100644 --- a/WebCore/GNUmakefile.am +++ b/WebCore/GNUmakefile.am @@ -948,6 +948,7 @@ webkitgtk_sources += \ WebCore/platform/gtk/Language.cpp \ WebCore/platform/gtk/LocalizedStringsGtk.cpp \ WebCore/platform/gtk/LoggingGtk.cpp \ + WebCore/platform/gtk/MainThreadGtk.cpp \ WebCore/platform/gtk/MIMETypeRegistryGtk.cpp \ WebCore/platform/gtk/MouseEventGtk.cpp \ WebCore/platform/gtk/PasteboardGtk.cpp \ @@ -962,7 +963,6 @@ webkitgtk_sources += \ WebCore/platform/gtk/SystemTimeGtk.cpp \ WebCore/platform/gtk/TemporaryLinkStubs.cpp \ WebCore/platform/text/gtk/TextBreakIteratorInternalICUGtk.cpp \ - WebCore/platform/gtk/ThreadingGtk.cpp \ WebCore/platform/gtk/WheelEventGtk.cpp \ WebCore/platform/gtk/WidgetGtk.cpp \ WebCore/platform/gtk/gtk2drawing.c \ diff --git a/WebCore/WebCore.pro b/WebCore/WebCore.pro index 9dff26c71c4..c72cfd59de8 100644 --- a/WebCore/WebCore.pro +++ b/WebCore/WebCore.pro @@ -932,6 +932,7 @@ qt-port { platform/graphics/qt/SimpleFontDataQt.cpp \ platform/qt/KURLQt.cpp \ platform/qt/Localizations.cpp \ + platform/qt/MainThreadQt.cpp \ platform/qt/MIMETypeRegistryQt.cpp \ platform/qt/PasteboardQt.cpp \ platform/qt/PlatformKeyboardEventQt.cpp \ @@ -951,7 +952,6 @@ qt-port { platform/text/qt/TextBoundaries.cpp \ platform/text/qt/TextBreakIteratorQt.cpp \ platform/text/qt/TextCodecQt.cpp \ - platform/qt/ThreadingQt.cpp \ platform/qt/WheelEventQt.cpp \ platform/qt/WidgetQt.cpp \ ../WebKit/qt/WebCoreSupport/ChromeClientQt.cpp \ @@ -967,7 +967,6 @@ qt-port { ../WebKit/qt/Api/qwebhistory.cpp \ ../WebKit/qt/Api/qwebsettings.cpp \ ../WebKit/qt/Api/qwebhistoryinterface.cpp \ - platform/ThreadingNone.cpp unix: SOURCES += platform/qt/SystemTimeQt.cpp else: SOURCES += platform/win/SystemTimeWin.cpp @@ -1038,6 +1037,7 @@ gtk-port { platform/gtk/Language.cpp \ platform/gtk/LocalizedStringsGtk.cpp \ platform/gtk/LoggingGtk.cpp \ + platform/gtk/MainThreadGtk.cpp \ platform/gtk/MIMETypeRegistryGtk.cpp \ platform/gtk/MouseEventGtk.cpp \ platform/gtk/PasteboardGtk.cpp \ @@ -1052,7 +1052,6 @@ gtk-port { platform/gtk/SystemTimeGtk.cpp \ platform/gtk/TemporaryLinkStubs.cpp \ platform/text/gtk/TextBreakIteratorInternalICUGtk.cpp \ - platform/gtk/ThreadingGtk.cpp \ platform/gtk/WheelEventGtk.cpp \ platform/gtk/WidgetGtk.cpp \ platform/gtk/gtk2drawing.c \ diff --git a/WebCore/WebCore.vcproj/WebCore.vcproj b/WebCore/WebCore.vcproj/WebCore.vcproj index c808aabf914..899d0fefea8 100644 --- a/WebCore/WebCore.vcproj/WebCore.vcproj +++ b/WebCore/WebCore.vcproj/WebCore.vcproj @@ -3239,7 +3239,7 @@ > - - @@ -3457,6 +3453,10 @@ RelativePath="..\platform\win\Language.cpp" > + + @@ -3525,10 +3525,6 @@ RelativePath="..\platform\win\ThreadConditionWin.cpp" > - - diff --git a/WebCore/WebCore.xcodeproj/project.pbxproj b/WebCore/WebCore.xcodeproj/project.pbxproj index 19e159f1882..4f6a6182ce9 100644 --- a/WebCore/WebCore.xcodeproj/project.pbxproj +++ b/WebCore/WebCore.xcodeproj/project.pbxproj @@ -93,7 +93,6 @@ 1A2E6E5A0CC55213004A2062 /* SQLValue.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A2E6E580CC55213004A2062 /* SQLValue.h */; }; 1A2E6E7A0CC556D5004A2062 /* SQLiteAuthorizer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A2E6E780CC556D5004A2062 /* SQLiteAuthorizer.cpp */; }; 1A2E6E7B0CC556D5004A2062 /* SQLiteAuthorizer.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A2E6E790CC556D5004A2062 /* SQLiteAuthorizer.h */; }; - 1A2E6FA40CC5795D004A2062 /* ThreadingPthreads.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A2E6FA30CC5795D004A2062 /* ThreadingPthreads.cpp */; }; 1A3178930B20A81600316987 /* SubresourceLoaderClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A3178920B20A81600316987 /* SubresourceLoaderClient.h */; settings = {ATTRIBUTES = (Private, ); }; }; 1A3417C90CECFF250049CBDE /* JSCustomVoidCallback.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A3417C70CECFF250049CBDE /* JSCustomVoidCallback.h */; }; 1A3417CA0CECFF250049CBDE /* JSCustomVoidCallback.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A3417C80CECFF250049CBDE /* JSCustomVoidCallback.cpp */; }; @@ -397,7 +396,6 @@ 514C767D0CE923A1007EF3CD /* ResourceRequestBase.h in Headers */ = {isa = PBXBuildFile; fileRef = 514C76680CE923A1007EF3CD /* ResourceRequestBase.h */; settings = {ATTRIBUTES = (Private, ); }; }; 514C767E0CE923A1007EF3CD /* ResourceResponseBase.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 514C76690CE923A1007EF3CD /* ResourceResponseBase.cpp */; }; 514C767F0CE923A1007EF3CD /* ResourceResponseBase.h in Headers */ = {isa = PBXBuildFile; fileRef = 514C766A0CE923A1007EF3CD /* ResourceResponseBase.h */; settings = {ATTRIBUTES = (Private, ); }; }; - 515378030D52D0630063A78B /* Locker.h in Headers */ = {isa = PBXBuildFile; fileRef = 515378020D52D0630063A78B /* Locker.h */; settings = {ATTRIBUTES = (Private, ); }; }; 515B03990CD1642A00B7EA9C /* SQLStatement.h in Headers */ = {isa = PBXBuildFile; fileRef = 515B03970CD1642A00B7EA9C /* SQLStatement.h */; }; 515B039A0CD1642A00B7EA9C /* SQLStatement.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 515B03980CD1642A00B7EA9C /* SQLStatement.cpp */; }; 5160300B0CC4251200C8AC25 /* FileSystemPOSIX.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5160300A0CC4251200C8AC25 /* FileSystemPOSIX.cpp */; }; @@ -431,9 +429,7 @@ 51DF6D7E0B92A16D00C2DC85 /* ThreadCheck.h in Headers */ = {isa = PBXBuildFile; fileRef = 51DF6D7D0B92A16D00C2DC85 /* ThreadCheck.h */; settings = {ATTRIBUTES = (Private, ); }; }; 51DF6D800B92A18E00C2DC85 /* ThreadCheck.mm in Sources */ = {isa = PBXBuildFile; fileRef = 51DF6D7F0B92A18E00C2DC85 /* ThreadCheck.mm */; }; 51E1ECAF0C91C54600DC255B /* AutodrainedPool.mm in Sources */ = {isa = PBXBuildFile; fileRef = 51E1ECAD0C91C54600DC255B /* AutodrainedPool.mm */; }; - 51E1ECB00C91C54600DC255B /* Threading.mm in Sources */ = {isa = PBXBuildFile; fileRef = 51E1ECAE0C91C54600DC255B /* Threading.mm */; }; 51E1ECB30C91C55600DC255B /* AutodrainedPool.h in Headers */ = {isa = PBXBuildFile; fileRef = 51E1ECB10C91C55600DC255B /* AutodrainedPool.h */; }; - 51E1ECB40C91C55600DC255B /* Threading.h in Headers */ = {isa = PBXBuildFile; fileRef = 51E1ECB20C91C55600DC255B /* Threading.h */; settings = {ATTRIBUTES = (Private, ); }; }; 51E1ECBE0C91C90400DC255B /* IconDatabaseClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 51E1ECB80C91C90400DC255B /* IconDatabaseClient.h */; settings = {ATTRIBUTES = (Private, ); }; }; 51E1ECC00C91C90400DC255B /* IconRecord.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51E1ECBA0C91C90400DC255B /* IconRecord.cpp */; }; 51E1ECC10C91C90400DC255B /* IconRecord.h in Headers */ = {isa = PBXBuildFile; fileRef = 51E1ECBB0C91C90400DC255B /* IconRecord.h */; }; @@ -3738,6 +3734,8 @@ E1EC299F0BB04C6B00EA187B /* XPathNodeSet.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E1EC299D0BB04C6B00EA187B /* XPathNodeSet.cpp */; }; E1EC29A00BB04C6B00EA187B /* XPathNodeSet.h in Headers */ = {isa = PBXBuildFile; fileRef = E1EC299E0BB04C6B00EA187B /* XPathNodeSet.h */; }; E1ED8AC30CC49BE000BFC557 /* CSSPrimitiveValueMappings.h in Headers */ = {isa = PBXBuildFile; fileRef = E1ED8AC20CC49BE000BFC557 /* CSSPrimitiveValueMappings.h */; }; + E1EE79370D6C97DE00FEA3BA /* MainThread.h in Headers */ = {isa = PBXBuildFile; fileRef = E1EE79360D6C97DE00FEA3BA /* MainThread.h */; }; + E1EE793A0D6C9B2700FEA3BA /* MainThreadMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = E1EE79390D6C9B2700FEA3BA /* MainThreadMac.mm */; }; E1F1E82F0C3C2BB9006DB391 /* XSLTExtensions.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E1F1E82D0C3C2BB9006DB391 /* XSLTExtensions.cpp */; }; E1F1E8300C3C2BB9006DB391 /* XSLTExtensions.h in Headers */ = {isa = PBXBuildFile; fileRef = E1F1E82E0C3C2BB9006DB391 /* XSLTExtensions.h */; }; E44613A10CD6331000FADA75 /* HTMLAudioElement.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E446138F0CD6331000FADA75 /* HTMLAudioElement.cpp */; }; @@ -4335,7 +4333,6 @@ 1A2E6E580CC55213004A2062 /* SQLValue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SQLValue.h; path = sql/SQLValue.h; sourceTree = ""; }; 1A2E6E780CC556D5004A2062 /* SQLiteAuthorizer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SQLiteAuthorizer.cpp; path = sql/SQLiteAuthorizer.cpp; sourceTree = ""; }; 1A2E6E790CC556D5004A2062 /* SQLiteAuthorizer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SQLiteAuthorizer.h; path = sql/SQLiteAuthorizer.h; sourceTree = ""; }; - 1A2E6FA30CC5795D004A2062 /* ThreadingPthreads.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ThreadingPthreads.cpp; path = pthreads/ThreadingPthreads.cpp; sourceTree = ""; }; 1A3178920B20A81600316987 /* SubresourceLoaderClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SubresourceLoaderClient.h; sourceTree = ""; }; 1A3417C70CECFF250049CBDE /* JSCustomVoidCallback.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSCustomVoidCallback.h; sourceTree = ""; }; 1A3417C80CECFF250049CBDE /* JSCustomVoidCallback.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSCustomVoidCallback.cpp; sourceTree = ""; }; @@ -4673,7 +4670,6 @@ 514C766A0CE923A1007EF3CD /* ResourceResponseBase.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ResourceResponseBase.h; sourceTree = ""; }; 5150C2A10702629000AF642C /* WebDashboardRegion.h */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = WebDashboardRegion.h; sourceTree = ""; tabWidth = 8; usesTabs = 0; }; 5150C2A50702629800AF642C /* WebDashboardRegion.m */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.c.objc; path = WebDashboardRegion.m; sourceTree = ""; tabWidth = 8; usesTabs = 0; }; - 515378020D52D0630063A78B /* Locker.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Locker.h; sourceTree = ""; }; 515B03970CD1642A00B7EA9C /* SQLStatement.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SQLStatement.h; sourceTree = ""; }; 515B03980CD1642A00B7EA9C /* SQLStatement.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SQLStatement.cpp; sourceTree = ""; }; 5160300A0CC4251200C8AC25 /* FileSystemPOSIX.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FileSystemPOSIX.cpp; sourceTree = ""; }; @@ -4709,9 +4705,7 @@ 51DF6D7D0B92A16D00C2DC85 /* ThreadCheck.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ThreadCheck.h; sourceTree = ""; }; 51DF6D7F0B92A18E00C2DC85 /* ThreadCheck.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ThreadCheck.mm; sourceTree = ""; }; 51E1ECAD0C91C54600DC255B /* AutodrainedPool.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = AutodrainedPool.mm; sourceTree = ""; }; - 51E1ECAE0C91C54600DC255B /* Threading.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = Threading.mm; sourceTree = ""; }; 51E1ECB10C91C55600DC255B /* AutodrainedPool.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AutodrainedPool.h; sourceTree = ""; }; - 51E1ECB20C91C55600DC255B /* Threading.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Threading.h; sourceTree = ""; }; 51E1ECB80C91C90400DC255B /* IconDatabaseClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IconDatabaseClient.h; sourceTree = ""; }; 51E1ECBA0C91C90400DC255B /* IconRecord.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = IconRecord.cpp; sourceTree = ""; }; 51E1ECBB0C91C90400DC255B /* IconRecord.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IconRecord.h; sourceTree = ""; }; @@ -7852,6 +7846,8 @@ E1EC299D0BB04C6B00EA187B /* XPathNodeSet.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = XPathNodeSet.cpp; sourceTree = ""; }; E1EC299E0BB04C6B00EA187B /* XPathNodeSet.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XPathNodeSet.h; sourceTree = ""; }; E1ED8AC20CC49BE000BFC557 /* CSSPrimitiveValueMappings.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CSSPrimitiveValueMappings.h; sourceTree = ""; }; + E1EE79360D6C97DE00FEA3BA /* MainThread.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MainThread.h; sourceTree = ""; }; + E1EE79390D6C9B2700FEA3BA /* MainThreadMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MainThreadMac.mm; sourceTree = ""; }; E1F1E82D0C3C2BB9006DB391 /* XSLTExtensions.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = XSLTExtensions.cpp; sourceTree = ""; }; E1F1E82E0C3C2BB9006DB391 /* XSLTExtensions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XSLTExtensions.h; sourceTree = ""; }; E446138F0CD6331000FADA75 /* HTMLAudioElement.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = HTMLAudioElement.cpp; sourceTree = ""; }; @@ -8189,14 +8185,6 @@ path = icon; sourceTree = ""; }; - 5154498E0CAA35F600194B2D /* pthreads */ = { - isa = PBXGroup; - children = ( - 1A2E6FA30CC5795D004A2062 /* ThreadingPthreads.cpp */, - ); - name = pthreads; - sourceTree = ""; - }; 516030090CC4245400C8AC25 /* posix */ = { isa = PBXGroup; children = ( @@ -8355,6 +8343,7 @@ 06E81EEB0AB5DA9700C87837 /* LocalCurrentGraphicsContext.mm */, 935207BF09BD412000F2038D /* LocalizedStringsMac.mm */, 1402645D0AFDC19B005919E2 /* LoggingMac.mm */, + E1EE79390D6C9B2700FEA3BA /* MainThreadMac.mm */, BC772C5D0C4EB3440083285F /* MIMETypeRegistryMac.mm */, A7D3C5230B576B4B002CA450 /* PasteboardHelper.h */, 4B2709810AF2E5E00065127F /* PasteboardMac.mm */, @@ -8374,7 +8363,6 @@ 84B2B24F056BF15F00D2B771 /* SSLKeyGeneratorMac.mm */, 6582A15509999D6D00BEEB6D /* SystemTimeMac.cpp */, 51DF6D7F0B92A18E00C2DC85 /* ThreadCheck.mm */, - 51E1ECAE0C91C54600DC255B /* Threading.mm */, F5517DC2031AB56301A80180 /* WebCoreHistory.h */, F5517DC3031AB56301A80180 /* WebCoreHistory.m */, 84B2B1F7056BEF3A00D2B771 /* WebCoreKeyGenerator.h */, @@ -11733,7 +11721,6 @@ 6582A14809999D6C00BEEB6D /* mac */, 656B84D70AEA1CE900A095B4 /* network */, 516030090CC4245400C8AC25 /* posix */, - 5154498E0CAA35F600194B2D /* pthreads */, 1A2E6E560CC551E0004A2062 /* sql */, B2C3D9EC0D006C1D00EF6F26 /* text */, BCFB2F74097A2E1A00BA703D /* Arena.cpp */, @@ -11769,9 +11756,9 @@ 6593923609AE4346002C531F /* KURL.h */, 85EC9AF90A71A2C600EEEAED /* Language.h */, 935207BD09BD410A00F2038D /* LocalizedStrings.h */, - 515378020D52D0630063A78B /* Locker.h */, A8239DFE09B3CF8A00B60641 /* Logging.cpp */, A8239DFF09B3CF8A00B60641 /* Logging.h */, + E1EE79360D6C97DE00FEA3BA /* MainThread.h */, E1DE1C070D5CE4CF0034C38F /* MessageQueue.h */, BC772C4C0C4EB3040083285F /* MIMETypeRegistry.cpp */, BC772C4D0C4EB3040083285F /* MIMETypeRegistry.h */, @@ -11798,7 +11785,6 @@ 9352071709BD3BA500F2038D /* StaticConstructors.h */, 93E62D990985F41600E1B5E3 /* SystemTime.h */, 51DF6D7D0B92A16D00C2DC85 /* ThreadCheck.h */, - 51E1ECB20C91C55600DC255B /* Threading.h */, 93309EA1099EB78C0056E581 /* Timer.cpp */, 9305B24C098F1B6B00C28855 /* Timer.h */, 1419D2C40CEA6F6100FF507A /* TreeShared.h */, @@ -14123,7 +14109,6 @@ 93F198F608245E59001E9ABC /* TextResourceDecoder.h in Headers */, B2C3DA4B0D006C1D00EF6F26 /* TextStream.h in Headers */, 51DF6D7E0B92A16D00C2DC85 /* ThreadCheck.h in Headers */, - 51E1ECB40C91C55600DC255B /* Threading.h in Headers */, E44613B00CD6331000FADA75 /* TimeRanges.h in Headers */, B28C6A2E0D00C44800334AA4 /* TimeScheduler.h in Headers */, 9305B24D098F1B6B00C28855 /* Timer.h in Headers */, @@ -14261,7 +14246,6 @@ B237C8A80D344D110013F707 /* SVGFontData.h in Headers */, E4EEFFC90D34550C00469A58 /* JSAudioConstructor.h in Headers */, 939B3E4E0D3C1E8400B4A92B /* StringBuffer.h in Headers */, - 515378030D52D0630063A78B /* Locker.h in Headers */, 514075C60D53ECFE00BC2D85 /* SecurityOriginHash.h in Headers */, 51A9267D0D53F0570063ECC2 /* OriginQuotaManager.h in Headers */, 51A9267F0D53F0570063ECC2 /* OriginUsageRecord.h in Headers */, @@ -14272,6 +14256,7 @@ BCC573350D695BBE006EF517 /* DOMProgressEvent.h in Headers */, BCC573380D695BD7006EF517 /* DOMProgressEventInternal.h in Headers */, BCC5733A0D695BF1006EF517 /* DOMTextPrivate.h in Headers */, + E1EE79370D6C97DE00FEA3BA /* MainThread.h in Headers */, A77979170D6B9D0C003851B9 /* CanvasPixelArray.h in Headers */, A779791A0D6B9D0C003851B9 /* ImageData.h in Headers */, A77979270D6B9E64003851B9 /* JSCanvasPixelArray.h in Headers */, @@ -15744,8 +15729,6 @@ 93F19A9D08245E59001E9ABC /* TextResourceDecoder.cpp in Sources */, B2C3DA4A0D006C1D00EF6F26 /* TextStream.cpp in Sources */, 51DF6D800B92A18E00C2DC85 /* ThreadCheck.mm in Sources */, - 51E1ECB00C91C54600DC255B /* Threading.mm in Sources */, - 1A2E6FA40CC5795D004A2062 /* ThreadingPthreads.cpp in Sources */, E44613AF0CD6331000FADA75 /* TimeRanges.cpp in Sources */, B28C6A2D0D00C44800334AA4 /* TimeScheduler.cpp in Sources */, 93309EA4099EB78C0056E581 /* Timer.cpp in Sources */, @@ -15869,6 +15852,7 @@ C0294DF30D5A6FD800CC7D6B /* UserStyleSheetLoader.cpp in Sources */, 37F818FE0D657606005E1F05 /* WebCoreURLResponse.mm in Sources */, BCC573360D695BBE006EF517 /* DOMProgressEvent.mm in Sources */, + E1EE793A0D6C9B2700FEA3BA /* MainThreadMac.mm in Sources */, A77979160D6B9D0C003851B9 /* CanvasPixelArray.cpp in Sources */, A77979190D6B9D0C003851B9 /* ImageData.cpp in Sources */, A77979260D6B9E64003851B9 /* JSCanvasPixelArray.cpp in Sources */, diff --git a/WebCore/WebCoreSources.bkl b/WebCore/WebCoreSources.bkl index a2ffafa899b..a0de7e6b731 100644 --- a/WebCore/WebCoreSources.bkl +++ b/WebCore/WebCoreSources.bkl @@ -602,7 +602,6 @@ This file contains the list of files needed to build WebCore. platform/text/TextEncoding.cpp platform/text/TextEncodingRegistry.cpp platform/text/TextStream.cpp - platform/ThreadingNone.cpp platform/Timer.cpp platform/Widget.cpp platform/graphics/AffineTransform.cpp diff --git a/WebCore/bindings/js/JSCustomSQLTransactionCallback.cpp b/WebCore/bindings/js/JSCustomSQLTransactionCallback.cpp index b63144c7529..cd50ebd4b69 100644 --- a/WebCore/bindings/js/JSCustomSQLTransactionCallback.cpp +++ b/WebCore/bindings/js/JSCustomSQLTransactionCallback.cpp @@ -32,6 +32,7 @@ #include "CString.h" #include "Frame.h" #include "Logging.h" +#include "MainThread.h" #include "kjs_proxy.h" #include "JSSQLTransaction.h" #include "Page.h" diff --git a/WebCore/dom/XMLTokenizer.cpp b/WebCore/dom/XMLTokenizer.cpp index 504063e11b6..de9df0f2192 100644 --- a/WebCore/dom/XMLTokenizer.cpp +++ b/WebCore/dom/XMLTokenizer.cpp @@ -45,7 +45,6 @@ #include "ResourceHandle.h" #include "ResourceRequest.h" #include "ResourceResponse.h" -#include "Threading.h" #ifndef USE_QXMLSTREAM #include #include @@ -54,6 +53,7 @@ #endif #include #include +#include #include #if ENABLE(XSLT) diff --git a/WebCore/loader/icon/IconDatabase.cpp b/WebCore/loader/icon/IconDatabase.cpp index 190f3eec0d1..a5dfb2596ce 100644 --- a/WebCore/loader/icon/IconDatabase.cpp +++ b/WebCore/loader/icon/IconDatabase.cpp @@ -37,6 +37,7 @@ #include "IntSize.h" #include "KURL.h" #include "Logging.h" +#include "MainThread.h" #include "PageURLRecord.h" #include "SQLiteStatement.h" #include "SQLiteTransaction.h" @@ -101,7 +102,7 @@ static IconDatabaseClient* defaultClient() IconDatabase* iconDatabase() { if (!sharedIconDatabase) { - initializeThreading(); + initializeThreadingAndMainThread(); sharedIconDatabase = new IconDatabase; } return sharedIconDatabase; diff --git a/WebCore/loader/icon/IconDatabase.h b/WebCore/loader/icon/IconDatabase.h index ea48c16bfd9..bdd24557db1 100644 --- a/WebCore/loader/icon/IconDatabase.h +++ b/WebCore/loader/icon/IconDatabase.h @@ -32,13 +32,13 @@ #endif #include "StringHash.h" -#if ENABLE(ICONDATABASE) -#include "Threading.h" -#endif #include "Timer.h" #include #include #include +#if ENABLE(ICONDATABASE) +#include +#endif namespace WebCore { diff --git a/WebCore/platform/MainThread.h b/WebCore/platform/MainThread.h new file mode 100644 index 00000000000..55758eaaa81 --- /dev/null +++ b/WebCore/platform/MainThread.h @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. + * Copyright (C) 2007 Justin Haygood (jhaygood@reaktix.com) + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef MainThread_h +#define MainThread_h + +#include + +namespace WebCore { + +typedef void MainThreadFunction(void*); + +void callOnMainThread(MainThreadFunction*, void* context); + +void initializeThreadingAndMainThread(); + +#if !PLATFORM(WIN) +inline void initializeThreadingAndMainThread() +{ + WTF::initializeThreading(); +} +#endif + + +} // namespace WebCore + +#endif // MainThread_h diff --git a/WebCore/platform/SecurityOrigin.h b/WebCore/platform/SecurityOrigin.h index bb9ae1247e2..6f7e6f5b9d3 100644 --- a/WebCore/platform/SecurityOrigin.h +++ b/WebCore/platform/SecurityOrigin.h @@ -31,9 +31,9 @@ #include #include +#include #include "PlatformString.h" -#include "Threading.h" namespace WebCore { diff --git a/WebCore/platform/gtk/MainThreadGtk.cpp b/WebCore/platform/gtk/MainThreadGtk.cpp new file mode 100644 index 00000000000..db3a583479d --- /dev/null +++ b/WebCore/platform/gtk/MainThreadGtk.cpp @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. + * Copyright (C) 2007 Justin Haygood (jhaygood@reaktix.com) + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Apple Inc. ("Apple") nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "MainThread.h" + +#include + +namespace WebCore { + +struct FunctionWithContext { + MainThreadFunction* function; + void* context; +}; + +static gboolean callFunctionOnMainThread(gpointer data) +{ + FunctionWithContext* functionWithContext = static_cast(data); + functionWithContext->function(functionWithContext->context); + delete functionWithContext; + return FALSE; +} + +void callOnMainThread(MainThreadFunction* function, void* context) +{ + ASSERT(function); + FunctionWithContext* functionWithContext = new FunctionWithContext; + functionWithContext->function = function; + functionWithContext->context = context; + g_timeout_add(0, callFunctionOnMainThread, functionWithContext); +} + + +} diff --git a/WebCore/platform/mac/Threading.mm b/WebCore/platform/mac/MainThreadMac.mm similarity index 99% rename from WebCore/platform/mac/Threading.mm rename to WebCore/platform/mac/MainThreadMac.mm index 02d39a36ed8..47329ef4a80 100644 --- a/WebCore/platform/mac/Threading.mm +++ b/WebCore/platform/mac/MainThreadMac.mm @@ -27,7 +27,7 @@ */ #import "config.h" -#import "Threading.h" +#import "MainThread.h" @interface WebCoreFunctionWrapper : NSObject { WebCore::MainThreadFunction* m_function; diff --git a/WebCore/platform/qt/ThreadingQt.cpp b/WebCore/platform/qt/MainThreadQt.cpp similarity index 98% rename from WebCore/platform/qt/ThreadingQt.cpp rename to WebCore/platform/qt/MainThreadQt.cpp index 71cd17e3e74..ab19bf7269d 100644 --- a/WebCore/platform/qt/ThreadingQt.cpp +++ b/WebCore/platform/qt/MainThreadQt.cpp @@ -29,7 +29,7 @@ */ #include "config.h" -#include "Threading.h" +#include "MainThread.h" #include #include @@ -94,4 +94,4 @@ void callOnMainThread(MainThreadFunction* function, void* context) } -#include "ThreadingQt.moc" +#include "MainThreadQt.moc" diff --git a/WebCore/platform/sql/SQLValue.h b/WebCore/platform/sql/SQLValue.h index ae2432dab53..7d85051a3c6 100644 --- a/WebCore/platform/sql/SQLValue.h +++ b/WebCore/platform/sql/SQLValue.h @@ -30,7 +30,7 @@ #define SQLValue_h #include "PlatformString.h" -#include "Threading.h" +#include namespace WebCore { diff --git a/WebCore/platform/sql/SQLiteAuthorizer.h b/WebCore/platform/sql/SQLiteAuthorizer.h index 4c0e8eebbed..0bb0fb340ba 100644 --- a/WebCore/platform/sql/SQLiteAuthorizer.h +++ b/WebCore/platform/sql/SQLiteAuthorizer.h @@ -28,7 +28,7 @@ #ifndef SQLiteAuthorizer_h #define SQLiteAuthorizer_h -#include "Threading.h" +#include namespace WebCore { diff --git a/WebCore/platform/sql/SQLiteDatabase.h b/WebCore/platform/sql/SQLiteDatabase.h index 5e6ab46e251..20f461db711 100644 --- a/WebCore/platform/sql/SQLiteDatabase.h +++ b/WebCore/platform/sql/SQLiteDatabase.h @@ -28,7 +28,7 @@ #define SQLDatabase_h #include "PlatformString.h" -#include "Threading.h" +#include #if COMPILER(MSVC) #pragma warning(disable: 4800) diff --git a/WebCore/platform/win/ThreadingWin.cpp b/WebCore/platform/win/MainThreadWin.cpp similarity index 63% rename from WebCore/platform/win/ThreadingWin.cpp rename to WebCore/platform/win/MainThreadWin.cpp index 0da3d1784b7..6d3493cff5b 100644 --- a/WebCore/platform/win/ThreadingWin.cpp +++ b/WebCore/platform/win/MainThreadWin.cpp @@ -27,12 +27,11 @@ */ #include "config.h" +#include "MainThread.h" + #include "Logging.h" #include "Page.h" -#include "Threading.h" -#include #include -#include namespace WebCore { @@ -49,88 +48,6 @@ static UINT threadingFiredMessage = 0; const LPCWSTR kThreadingWindowClassName = L"ThreadingWindowClass"; static bool processingCustomThreadingMessage = false; -static Mutex& threadMapMutex() -{ - static Mutex mutex; - return mutex; -} - -static HashMap& threadMap() -{ - static HashMap map; - return map; -} - -static void storeThreadHandleByIdentifier(DWORD threadID, HANDLE threadHandle) -{ - MutexLocker locker(threadMapMutex()); - threadMap().add(threadID, threadHandle); -} - -static HANDLE threadHandleForIdentifier(ThreadIdentifier id) -{ - MutexLocker locker(threadMapMutex()); - return threadMap().get(id); -} - -static void clearThreadHandleForIdentifier(ThreadIdentifier id) -{ - MutexLocker locker(threadMapMutex()); - ASSERT(threadMap().contains(id)); - threadMap().remove(id); -} - -ThreadIdentifier createThread(ThreadFunction entryPoint, void* data) -{ - DWORD threadIdentifier = 0; - ThreadIdentifier threadID = 0; - HANDLE hEvent = ::CreateEvent(0, FALSE, FALSE, 0); - HANDLE threadHandle = ::CreateThread(0, 0, (LPTHREAD_START_ROUTINE)entryPoint, data, 0, &threadIdentifier); - if (!threadHandle) { - LOG_ERROR("Failed to create thread at entry point %p with data %p", entryPoint, data); - return 0; - } - - threadID = static_cast(threadIdentifier); - storeThreadHandleByIdentifier(threadIdentifier, threadHandle); - - LOG(Threading, "Created thread with thread id %u", threadID); - return threadID; -} - -int waitForThreadCompletion(ThreadIdentifier threadID, void** result) -{ - ASSERT(threadID); - - HANDLE threadHandle = threadHandleForIdentifier(threadID); - if (!threadHandle) - LOG_ERROR("ThreadIdentifier %u did not correspond to an active thread when trying to quit", threadID); - - DWORD joinResult = ::WaitForSingleObject(threadHandle, INFINITE); - if (joinResult == WAIT_FAILED) - LOG_ERROR("ThreadIdentifier %u was found to be deadlocked trying to quit", threadID); - - ::CloseHandle(threadHandle); - clearThreadHandleForIdentifier(threadID); - - return joinResult; -} - -void detachThread(ThreadIdentifier threadID) -{ - ASSERT(threadID); - - HANDLE threadHandle = threadHandleForIdentifier(threadID); - if (threadHandle) - ::CloseHandle(threadHandle); - clearThreadHandleForIdentifier(threadID); -} - -ThreadIdentifier currentThread() -{ - return static_cast(::GetCurrentThreadId()); -} - static Mutex& functionQueueMutex() { static Mutex staticFunctionQueueMutex; @@ -167,11 +84,13 @@ LRESULT CALLBACK ThreadingWindowWndProc(HWND hWnd, UINT message, WPARAM wParam, return 0; } -void initializeThreading() +void initializeThreadingAndMainThread() { if (threadingWindowHandle) return; - + + WTF::initializeThreading(); + WNDCLASSEX wcex; memset(&wcex, 0, sizeof(WNDCLASSEX)); wcex.cbSize = sizeof(WNDCLASSEX); diff --git a/WebCore/platform/wx/ThreadingWx.cpp b/WebCore/platform/wx/MainThreadWx.cpp similarity index 98% rename from WebCore/platform/wx/ThreadingWx.cpp rename to WebCore/platform/wx/MainThreadWx.cpp index 7cb90ff2e80..b49cb62e03f 100644 --- a/WebCore/platform/wx/ThreadingWx.cpp +++ b/WebCore/platform/wx/MainThreadWx.cpp @@ -28,7 +28,7 @@ #include "config.h" #include "NotImplemented.h" -#include "Threading.h" +#include "MainThread.h" namespace WebCore { diff --git a/WebCore/storage/Database.cpp b/WebCore/storage/Database.cpp index efe3f25b7b6..927d1990bbd 100644 --- a/WebCore/storage/Database.cpp +++ b/WebCore/storage/Database.cpp @@ -41,6 +41,7 @@ #include "Frame.h" #include "InspectorController.h" #include "Logging.h" +#include "MainThread.h" #include "NotImplemented.h" #include "Page.h" #include "OriginQuotaManager.h" @@ -123,7 +124,7 @@ Database::Database(Document* document, const String& name, const String& expecte if (m_name.isNull()) m_name = ""; - initializeThreading(); + initializeThreadingAndMainThread(); m_guid = guidForOriginAndName(m_securityOrigin->toString(), name); diff --git a/WebCore/storage/Database.h b/WebCore/storage/Database.h index 99be3703417..955f0235f32 100644 --- a/WebCore/storage/Database.h +++ b/WebCore/storage/Database.h @@ -29,7 +29,7 @@ #ifndef Database_h #define Database_h -#include "MessageQueue.h" +#include #include "PlatformString.h" #include "SecurityOrigin.h" #include "SQLiteDatabase.h" diff --git a/WebCore/storage/DatabaseTask.h b/WebCore/storage/DatabaseTask.h index 135438a17ad..d43090ddbab 100644 --- a/WebCore/storage/DatabaseTask.h +++ b/WebCore/storage/DatabaseTask.h @@ -30,9 +30,9 @@ #include "ExceptionCode.h" #include "PlatformString.h" -#include "Threading.h" #include #include +#include #include namespace WebCore { diff --git a/WebCore/storage/DatabaseThread.h b/WebCore/storage/DatabaseThread.h index a95ca37b1d0..e6124150116 100644 --- a/WebCore/storage/DatabaseThread.h +++ b/WebCore/storage/DatabaseThread.h @@ -28,7 +28,7 @@ #ifndef DatabaseThread_h #define DatabaseThread_h -#include "MessageQueue.h" +#include #include #include diff --git a/WebCore/storage/DatabaseTracker.cpp b/WebCore/storage/DatabaseTracker.cpp index c4595e948d2..ffdd5898b3b 100644 --- a/WebCore/storage/DatabaseTracker.cpp +++ b/WebCore/storage/DatabaseTracker.cpp @@ -35,6 +35,7 @@ #include "Document.h" #include "FileSystem.h" #include "Logging.h" +#include "MainThread.h" #include "OriginQuotaManager.h" #include "Page.h" #include "SecurityOrigin.h" diff --git a/WebCore/storage/OriginQuotaManager.h b/WebCore/storage/OriginQuotaManager.h index 874b3f3532e..3191a581b0c 100644 --- a/WebCore/storage/OriginQuotaManager.h +++ b/WebCore/storage/OriginQuotaManager.h @@ -31,8 +31,8 @@ #include "PlatformString.h" #include "StringHash.h" #include "SecurityOriginHash.h" -#include "Threading.h" #include +#include namespace WebCore { diff --git a/WebCore/storage/SQLError.h b/WebCore/storage/SQLError.h index ddeebc525bc..5e952e900e5 100644 --- a/WebCore/storage/SQLError.h +++ b/WebCore/storage/SQLError.h @@ -30,7 +30,7 @@ #define SQLError_h #include "PlatformString.h" -#include "Threading.h" +#include namespace WebCore { diff --git a/WebCore/storage/SQLResultSet.h b/WebCore/storage/SQLResultSet.h index de7a2be7685..e10befe1970 100644 --- a/WebCore/storage/SQLResultSet.h +++ b/WebCore/storage/SQLResultSet.h @@ -30,7 +30,7 @@ #define SQLResultSet_h #include "SQLResultSetRowList.h" -#include "Threading.h" +#include namespace WebCore { diff --git a/WebCore/storage/SQLStatement.h b/WebCore/storage/SQLStatement.h index 538f645db16..f2fe36f7945 100644 --- a/WebCore/storage/SQLStatement.h +++ b/WebCore/storage/SQLStatement.h @@ -25,11 +25,10 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef SQLStatment_h -#define SQLStatment_h +#ifndef SQLStatement_h +#define SQLStatement_h #include "PlatformString.h" -#include "Threading.h" #include "SQLError.h" #include "SQLResultSet.h" @@ -39,6 +38,7 @@ #include #include +#include #include namespace WebCore { @@ -78,4 +78,4 @@ private: } // namespace WebCore -#endif // SQLStatment_h +#endif // SQLStatement_h diff --git a/WebCore/storage/SQLStatementCallback.h b/WebCore/storage/SQLStatementCallback.h index 9a4b0599585..58a94364ae6 100644 --- a/WebCore/storage/SQLStatementCallback.h +++ b/WebCore/storage/SQLStatementCallback.h @@ -28,7 +28,7 @@ #ifndef SQLStatementCallback_h #define SQLStatementCallback_h -#include "Threading.h" +#include namespace WebCore { diff --git a/WebCore/storage/SQLStatementErrorCallback.h b/WebCore/storage/SQLStatementErrorCallback.h index 37ad2317b45..5dc3f5a67bb 100644 --- a/WebCore/storage/SQLStatementErrorCallback.h +++ b/WebCore/storage/SQLStatementErrorCallback.h @@ -29,7 +29,7 @@ #ifndef SQLStatementErrorCallback_h #define SQLStatementErrorCallback_h -#include "Threading.h" +#include namespace WebCore { diff --git a/WebCore/storage/SQLTransaction.h b/WebCore/storage/SQLTransaction.h index 50dc0d28862..2d83cc84d91 100644 --- a/WebCore/storage/SQLTransaction.h +++ b/WebCore/storage/SQLTransaction.h @@ -28,7 +28,7 @@ #ifndef SQLTransaction_h #define SQLTransaction_h -#include "Threading.h" +#include #include "SQLiteTransaction.h" #include "SQLStatement.h" diff --git a/WebCore/storage/SQLTransactionCallback.h b/WebCore/storage/SQLTransactionCallback.h index 0affd1b41fa..bbe62a5314e 100644 --- a/WebCore/storage/SQLTransactionCallback.h +++ b/WebCore/storage/SQLTransactionCallback.h @@ -29,7 +29,7 @@ #ifndef SQLTransactionCallback_h #define SQLTransactionCallback_h -#include "Threading.h" +#include namespace WebCore { diff --git a/WebCore/storage/SQLTransactionErrorCallback.h b/WebCore/storage/SQLTransactionErrorCallback.h index 73be74d084a..2890556a711 100644 --- a/WebCore/storage/SQLTransactionErrorCallback.h +++ b/WebCore/storage/SQLTransactionErrorCallback.h @@ -29,7 +29,7 @@ #ifndef SQLTransactionErrorCallback_h #define SQLTransactionErrorCallback_h -#include "Threading.h" +#include namespace WebCore { diff --git a/WebCore/webcore-wx.bkl b/WebCore/webcore-wx.bkl index 6f5044ad590..af732c7d568 100644 --- a/WebCore/webcore-wx.bkl +++ b/WebCore/webcore-wx.bkl @@ -79,6 +79,7 @@ wxWebCore port Bakefile project file. platform/wx/LocalizedStringsWx.cpp platform/wx/LoggingWx.cpp platform/wx/MimeTypeRegistryWx.cpp + platform/wx/MainThreadWx.cpp platform/wx/MouseEventWx.cpp platform/wx/MouseWheelEventWx.cpp platform/wx/PasteboardWx.cpp @@ -88,7 +89,6 @@ wxWebCore port Bakefile project file. platform/wx/SoundWx.cpp platform/text/wx/StringWx.cpp platform/wx/SystemTimeWx.cpp - platform/wx/ThreadingWx.cpp platform/wx/WidgetWx.cpp diff --git a/WebKit/mac/ChangeLog b/WebKit/mac/ChangeLog index c9189ef9cd4..576b3b9faa8 100644 --- a/WebKit/mac/ChangeLog +++ b/WebKit/mac/ChangeLog @@ -1,3 +1,12 @@ +2008-02-23 Alexey Proskuryakov + + Reviewed by Darin. + + Move basic threading support from WebCore to WTF. + + * ForwardingHeaders/wtf/Threading.h: Added. + * ForwardingHeaders/wtf/Locker.h: Added. + 2008-02-23 David Kilzer Please clarify licensing for some files diff --git a/WebKit/mac/ForwardingHeaders/wtf/Locker.h b/WebKit/mac/ForwardingHeaders/wtf/Locker.h new file mode 100644 index 00000000000..7718305b72e --- /dev/null +++ b/WebKit/mac/ForwardingHeaders/wtf/Locker.h @@ -0,0 +1 @@ +#import diff --git a/WebKit/mac/ForwardingHeaders/wtf/Threading.h b/WebKit/mac/ForwardingHeaders/wtf/Threading.h new file mode 100644 index 00000000000..771edd12644 --- /dev/null +++ b/WebKit/mac/ForwardingHeaders/wtf/Threading.h @@ -0,0 +1 @@ +#import -- GitLab