Commit ec0fdafc authored by ap@webkit.org's avatar ap@webkit.org

2008-02-23 Alexey Proskuryakov <ap@webkit.org>

        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
parent 6823545b
2008-02-23 Alexey Proskuryakov <ap@webkit.org>
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 <ggaren@apple.com> 2008-02-22 Geoffrey Garen <ggaren@apple.com>
Reviewed by Sam Weinig. Reviewed by Sam Weinig.
......
...@@ -60,6 +60,7 @@ javascriptcore_sources += \ ...@@ -60,6 +60,7 @@ javascriptcore_sources += \
JavaScriptCore/pcre/pcre_xclass.cpp \ JavaScriptCore/pcre/pcre_xclass.cpp \
JavaScriptCore/wtf/Assertions.cpp \ JavaScriptCore/wtf/Assertions.cpp \
JavaScriptCore/wtf/HashTable.cpp \ JavaScriptCore/wtf/HashTable.cpp \
JavaScriptCore/wtf/ThreadingGtk.cpp \
JavaScriptCore/wtf/unicode/UTF8.cpp JavaScriptCore/wtf/unicode/UTF8.cpp
# Debug build # Debug build
......
...@@ -298,3 +298,17 @@ _jscore_collector_introspection ...@@ -298,3 +298,17 @@ _jscore_collector_introspection
_jscore_fastmalloc_introspection _jscore_fastmalloc_introspection
_kJSClassDefinitionEmpty _kJSClassDefinitionEmpty
_kjs_strtod _kjs_strtod
__ZN3WTF5MutexC1Ev
__ZN3WTF5MutexD1Ev
__ZN3WTF15ThreadCondition4waitERNS_5MutexE
__ZN3WTF5Mutex7tryLockEv
__ZN3WTF12detachThreadEj
__ZN3WTF13currentThreadEv
__ZN3WTF5Mutex4lockEv
__ZN3WTF23waitForThreadCompletionEjPPv
__ZN3WTF15ThreadConditionC1Ev
__ZN3WTF15ThreadConditionD1Ev
__ZN3WTF5Mutex6unlockEv
__ZN3WTF12createThreadEPFPvS0_ES0_
__ZN3WTF15ThreadCondition9broadcastEv
__ZN3WTF15ThreadCondition6signalEv
...@@ -113,10 +113,19 @@ SOURCES += \ ...@@ -113,10 +113,19 @@ SOURCES += \
} }
qt-port:SOURCES += \ qt-port:SOURCES += \
wtf/ThreadingPthreads.cpp \
bindings/qt/qt_class.cpp \ bindings/qt/qt_class.cpp \
bindings/qt/qt_instance.cpp \ bindings/qt/qt_instance.cpp \
bindings/qt/qt_runtime.cpp bindings/qt/qt_runtime.cpp
gtk-port:SOURCES += \
wtf/ThreadingGtk.cpp
}
!gtk-port:SOURCES += \
wtf/ThreadingNone.cpp
}
!CONFIG(QTDIR_build) { !CONFIG(QTDIR_build) {
defineTest(addExtraCompiler) { defineTest(addExtraCompiler) {
QMAKE_EXTRA_COMPILERS += $$1 QMAKE_EXTRA_COMPILERS += $$1
......
...@@ -273,10 +273,18 @@ ...@@ -273,10 +273,18 @@
RelativePath="..\..\wtf\ListRefPtr.h" RelativePath="..\..\wtf\ListRefPtr.h"
> >
</File> </File>
<File
RelativePath="..\..\wtf\Locker.h"
>
</File>
<File <File
RelativePath="..\..\wtf\MathExtras.h" RelativePath="..\..\wtf\MathExtras.h"
> >
</File> </File>
<File
RelativePath="..\..\wtf\MessageQueue.h"
>
</File>
<File <File
RelativePath="..\..\wtf\Noncopyable.h" RelativePath="..\..\wtf\Noncopyable.h"
> >
...@@ -341,6 +349,14 @@ ...@@ -341,6 +349,14 @@
RelativePath="..\..\wtf\TCSystemAlloc.h" RelativePath="..\..\wtf\TCSystemAlloc.h"
> >
</File> </File>
<File
RelativePath="..\..\wtf\Threading.h"
>
</File>
<File
RelativePath="..\..\wtf\ThreadingWin.cpp"
>
</File>
<File <File
RelativePath="..\..\wtf\unicode\Unicode.h" RelativePath="..\..\wtf\unicode\Unicode.h"
> >
......
...@@ -237,6 +237,10 @@ ...@@ -237,6 +237,10 @@
E11D51760B2E798D0056C188 /* StringExtras.h in Headers */ = {isa = PBXBuildFile; fileRef = E11D51750B2E798D0056C188 /* StringExtras.h */; settings = {ATTRIBUTES = (Private, ); }; }; 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, ); }; }; 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, ); }; }; 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 */; }; E1EF79AA0CE97BA60088D500 /* UTF8.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E1EF79A80CE97BA60088D500 /* UTF8.cpp */; };
E1EF79AB0CE97BA60088D500 /* UTF8.h in Headers */ = {isa = PBXBuildFile; fileRef = E1EF79A90CE97BA60088D500 /* UTF8.h */; }; E1EF79AB0CE97BA60088D500 /* UTF8.h in Headers */ = {isa = PBXBuildFile; fileRef = E1EF79A90CE97BA60088D500 /* UTF8.h */; };
/* End PBXBuildFile section */ /* End PBXBuildFile section */
...@@ -576,6 +580,10 @@ ...@@ -576,6 +580,10 @@
E11D51750B2E798D0056C188 /* StringExtras.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StringExtras.h; sourceTree = "<group>"; }; E11D51750B2E798D0056C188 /* StringExtras.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StringExtras.h; sourceTree = "<group>"; };
E195678F09E7CF1200B89D13 /* UnicodeIcu.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UnicodeIcu.h; sourceTree = "<group>"; }; E195678F09E7CF1200B89D13 /* UnicodeIcu.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UnicodeIcu.h; sourceTree = "<group>"; };
E195679409E7CF1200B89D13 /* Unicode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Unicode.h; sourceTree = "<group>"; }; E195679409E7CF1200B89D13 /* Unicode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Unicode.h; sourceTree = "<group>"; };
E1EE79220D6C95CD00FEA3BA /* Threading.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Threading.h; sourceTree = "<group>"; };
E1EE79270D6C964500FEA3BA /* Locker.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Locker.h; sourceTree = "<group>"; };
E1EE793C0D6C9B9200FEA3BA /* ThreadingPthreads.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ThreadingPthreads.cpp; sourceTree = "<group>"; };
E1EE798B0D6CA53D00FEA3BA /* MessageQueue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MessageQueue.h; sourceTree = "<group>"; };
E1EF79A80CE97BA60088D500 /* UTF8.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = UTF8.cpp; sourceTree = "<group>"; }; E1EF79A80CE97BA60088D500 /* UTF8.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = UTF8.cpp; sourceTree = "<group>"; };
E1EF79A90CE97BA60088D500 /* UTF8.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UTF8.h; sourceTree = "<group>"; }; E1EF79A90CE97BA60088D500 /* UTF8.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UTF8.h; sourceTree = "<group>"; };
F5BB2BC5030F772101FCFE1D /* completion.h */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = completion.h; sourceTree = "<group>"; tabWidth = 8; }; F5BB2BC5030F772101FCFE1D /* completion.h */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = completion.h; sourceTree = "<group>"; tabWidth = 8; };
...@@ -899,8 +907,10 @@ ...@@ -899,8 +907,10 @@
65DFC92F08EA173A00F7300B /* HashTraits.h */, 65DFC92F08EA173A00F7300B /* HashTraits.h */,
657EB7450B708F540063461B /* ListHashSet.h */, 657EB7450B708F540063461B /* ListHashSet.h */,
148A1626095D16BB00666D0D /* ListRefPtr.h */, 148A1626095D16BB00666D0D /* ListRefPtr.h */,
E1EE79270D6C964500FEA3BA /* Locker.h */,
5DBD18AF0C5401A700C15EAE /* MallocZoneSupport.h */, 5DBD18AF0C5401A700C15EAE /* MallocZoneSupport.h */,
BCF6553B0A2048DE0038A194 /* MathExtras.h */, BCF6553B0A2048DE0038A194 /* MathExtras.h */,
E1EE798B0D6CA53D00FEA3BA /* MessageQueue.h */,
9303F5690991190000AD71B8 /* Noncopyable.h */, 9303F5690991190000AD71B8 /* Noncopyable.h */,
9303F5A409911A5800AD71B8 /* OwnArrayPtr.h */, 9303F5A409911A5800AD71B8 /* OwnArrayPtr.h */,
9303F567099118FA00AD71B8 /* OwnPtr.h */, 9303F567099118FA00AD71B8 /* OwnPtr.h */,
...@@ -916,6 +926,8 @@ ...@@ -916,6 +926,8 @@
6541BD6F08E80A17002CBEE7 /* TCSpinLock.h */, 6541BD6F08E80A17002CBEE7 /* TCSpinLock.h */,
6541BD7008E80A17002CBEE7 /* TCSystemAlloc.cpp */, 6541BD7008E80A17002CBEE7 /* TCSystemAlloc.cpp */,
6541BD7108E80A17002CBEE7 /* TCSystemAlloc.h */, 6541BD7108E80A17002CBEE7 /* TCSystemAlloc.h */,
E1EE79220D6C95CD00FEA3BA /* Threading.h */,
E1EE793C0D6C9B9200FEA3BA /* ThreadingPthreads.cpp */,
E195678D09E7CF1200B89D13 /* unicode */, E195678D09E7CF1200B89D13 /* unicode */,
935AF46B09E9D9DB00ACD1D8 /* UnusedParam.h */, 935AF46B09E9D9DB00ACD1D8 /* UnusedParam.h */,
6592C316098B7DE10003D4F6 /* Vector.h */, 6592C316098B7DE10003D4F6 /* Vector.h */,
...@@ -1145,6 +1157,7 @@ ...@@ -1145,6 +1157,7 @@
65F340940CD6C1C000C0CA8B /* LocalStorage.h in Headers */, 65F340940CD6C1C000C0CA8B /* LocalStorage.h in Headers */,
5DBD18B00C5401A700C15EAE /* MallocZoneSupport.h in Headers */, 5DBD18B00C5401A700C15EAE /* MallocZoneSupport.h in Headers */,
BCF655590A2049710038A194 /* MathExtras.h in Headers */, BCF655590A2049710038A194 /* MathExtras.h in Headers */,
E1EE798C0D6CA53D00FEA3BA /* MessageQueue.h in Headers */,
932F5B840822A1C700736975 /* NP_jsobject.h in Headers */, 932F5B840822A1C700736975 /* NP_jsobject.h in Headers */,
9303F56A0991190000AD71B8 /* Noncopyable.h in Headers */, 9303F56A0991190000AD71B8 /* Noncopyable.h in Headers */,
9303F5A509911A5800AD71B8 /* OwnArrayPtr.h in Headers */, 9303F5A509911A5800AD71B8 /* OwnArrayPtr.h in Headers */,
...@@ -1164,6 +1177,7 @@ ...@@ -1164,6 +1177,7 @@
6541BD7208E80A17002CBEE7 /* TCPageMap.h in Headers */, 6541BD7208E80A17002CBEE7 /* TCPageMap.h in Headers */,
6541BD7308E80A17002CBEE7 /* TCSpinLock.h in Headers */, 6541BD7308E80A17002CBEE7 /* TCSpinLock.h in Headers */,
6541BD7508E80A17002CBEE7 /* TCSystemAlloc.h in Headers */, 6541BD7508E80A17002CBEE7 /* TCSystemAlloc.h in Headers */,
E1EE79230D6C95CD00FEA3BA /* Threading.h in Headers */,
E1EF79AB0CE97BA60088D500 /* UTF8.h in Headers */, E1EF79AB0CE97BA60088D500 /* UTF8.h in Headers */,
E195679809E7CF1200B89D13 /* Unicode.h in Headers */, E195679809E7CF1200B89D13 /* Unicode.h in Headers */,
E195679609E7CF1200B89D13 /* UnicodeIcu.h in Headers */, E195679609E7CF1200B89D13 /* UnicodeIcu.h in Headers */,
...@@ -1241,6 +1255,7 @@ ...@@ -1241,6 +1255,7 @@
93E26BFE08B151D400F85226 /* ucpinternal.h in Headers */, 93E26BFE08B151D400F85226 /* ucpinternal.h in Headers */,
932F5B5C0822A1C700736975 /* ustring.h in Headers */, 932F5B5C0822A1C700736975 /* ustring.h in Headers */,
14ABB36F099C076400E2A24F /* value.h in Headers */, 14ABB36F099C076400E2A24F /* value.h in Headers */,
E1EE79280D6C964500FEA3BA /* Locker.h in Headers */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };
...@@ -1511,6 +1526,7 @@ ...@@ -1511,6 +1526,7 @@
932F5BBD0822A1C700736975 /* runtime_method.cpp in Sources */, 932F5BBD0822A1C700736975 /* runtime_method.cpp in Sources */,
932F5BBA0822A1C700736975 /* runtime_object.cpp in Sources */, 932F5BBA0822A1C700736975 /* runtime_object.cpp in Sources */,
932F5BC50822A1C700736975 /* runtime_root.cpp in Sources */, 932F5BC50822A1C700736975 /* runtime_root.cpp in Sources */,
E1EE793D0D6C9B9200FEA3BA /* ThreadingPthreads.cpp in Sources */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };
......
...@@ -113,6 +113,7 @@ Source files for JSCore. ...@@ -113,6 +113,7 @@ Source files for JSCore.
wtf/FastMalloc.cpp wtf/FastMalloc.cpp
wtf/HashTable.cpp wtf/HashTable.cpp
wtf/TCSystemAlloc.cpp wtf/TCSystemAlloc.cpp
wtf/ThreadingNone.cpp
wtf/unicode/UTF8.cpp wtf/unicode/UTF8.cpp
</set> </set>
......
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
#include <wtf/Noncopyable.h> #include <wtf/Noncopyable.h>
namespace WebCore { namespace WTF {
template <typename T> class Locker : Noncopyable { template <typename T> class Locker : Noncopyable {
public: public:
...@@ -42,4 +42,6 @@ private: ...@@ -42,4 +42,6 @@ private:
} }
using WTF::Locker;
#endif #endif
...@@ -29,12 +29,12 @@ ...@@ -29,12 +29,12 @@
#ifndef MessageQueue_h #ifndef MessageQueue_h
#define MessageQueue_h #define MessageQueue_h
#include "Threading.h"
#include <wtf/Assertions.h> #include <wtf/Assertions.h>
#include <wtf/Deque.h> #include <wtf/Deque.h>
#include <wtf/Noncopyable.h> #include <wtf/Noncopyable.h>
#include <wtf/Threading.h>
namespace WebCore { namespace WTF {
template<typename DataType> template<typename DataType>
class MessageQueue : Noncopyable { class MessageQueue : Noncopyable {
...@@ -46,10 +46,10 @@ namespace WebCore { ...@@ -46,10 +46,10 @@ namespace WebCore {
bool waitForMessage(DataType&); bool waitForMessage(DataType&);
bool tryGetMessage(DataType&); bool tryGetMessage(DataType&);
void kill(); void kill();
bool killed() const { return m_killed; } bool killed() const;
private: private:
Mutex m_mutex; mutable Mutex m_mutex;
ThreadCondition m_condition; ThreadCondition m_condition;
Deque<DataType> m_queue; Deque<DataType> m_queue;
bool m_killed; bool m_killed;
...@@ -110,6 +110,15 @@ namespace WebCore { ...@@ -110,6 +110,15 @@ namespace WebCore {
m_killed = true; m_killed = true;
m_condition.broadcast(); m_condition.broadcast();
} }
template<typename DataType>
inline bool MessageQueue<DataType>::killed() const
{
MutexLocker lock(m_mutex);
return m_killed;
}
} }
using WTF::MessageQueue;
#endif // MessageQueue_h #endif // MessageQueue_h
...@@ -59,9 +59,8 @@ ...@@ -59,9 +59,8 @@
#ifndef Threading_h #ifndef Threading_h
#define Threading_h #define Threading_h
#include "Locker.h"
#include <wtf/Assertions.h> #include <wtf/Assertions.h>
#include <wtf/Locker.h>
#include <wtf/Noncopyable.h> #include <wtf/Noncopyable.h>
#if PLATFORM(WIN_OS) #if PLATFORM(WIN_OS)
...@@ -92,7 +91,7 @@ class QWaitCondition; ...@@ -92,7 +91,7 @@ class QWaitCondition;
#include <stdint.h> #include <stdint.h>
namespace WebCore { namespace WTF {
typedef uint32_t ThreadIdentifier; typedef uint32_t ThreadIdentifier;
typedef void* (*ThreadFunction)(void* argument); typedef void* (*ThreadFunction)(void* argument);
...@@ -231,18 +230,26 @@ private: ...@@ -231,18 +230,26 @@ private:
#endif #endif
}; };
typedef void MainThreadFunction(void*);
void callOnMainThread(MainThreadFunction*, void* context);
void initializeThreading(); void initializeThreading();
#if !PLATFORM(WIN) && !PLATFORM(GTK) #if !PLATFORM(GTK)
inline void initializeThreading() inline void initializeThreading()
{ {
} }
#endif #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 #endif // Threading_h
...@@ -31,34 +31,11 @@ ...@@ -31,34 +31,11 @@
#include "Threading.h" #include "Threading.h"
#include "HashMap.h" #include "HashMap.h"
#include "Logging.h"
#include <glib.h> #include <glib.h>
namespace WebCore { namespace WebCore {
struct FunctionWithContext {
MainThreadFunction* function;
void* context;
};
static gboolean callFunctionOnMainThread(gpointer data)
{
FunctionWithContext* functionWithContext = static_cast<FunctionWithContext*>(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() void initializeThreading()
{ {
if (!g_thread_supported()) if (!g_thread_supported())
...@@ -127,7 +104,6 @@ ThreadIdentifier createThread(ThreadFunction entryPoint, void* data) ...@@ -127,7 +104,6 @@ ThreadIdentifier createThread(ThreadFunction entryPoint, void* data)
} }
ThreadIdentifier threadID = establishIdentifierForThread(thread); ThreadIdentifier threadID = establishIdentifierForThread(thread);
LOG(Threading, "Created thread with thread id %u", threadID);
return threadID; return threadID;
} }
......
...@@ -29,12 +29,11 @@ ...@@ -29,12 +29,11 @@
#include "config.h" #include "config.h"
#include "Threading.h" #include "Threading.h"
#include "Logging.h"
#include <wtf/HashMap.h> #include <wtf/HashMap.h>
#include <errno.h> #include <errno.h>
namespace WebCore { namespace WTF {
static Mutex& threadMapMutex() static Mutex& threadMapMutex()
{ {
...@@ -97,7 +96,6 @@ ThreadIdentifier createThread(ThreadFunction entryPoint, void* data) ...@@ -97,7 +96,6 @@ ThreadIdentifier createThread(ThreadFunction entryPoint, void* data)
} }
ThreadIdentifier threadID = establishIdentifierForPthreadHandle(threadHandle); ThreadIdentifier threadID = establishIdentifierForPthreadHandle(threadHandle);
LOG(Threading, "Created thread with thread id %u", threadID);
return threadID; return threadID;
} }
...@@ -197,4 +195,4 @@ void ThreadCondition::broadcast() ...@@ -197,4 +195,4 @@ void ThreadCondition::broadcast()
ASSERT(false); ASSERT(false);
} }
} // namespace WebCore } // namespace WTF
/* /*
* Copyright (C) 2007 Apple Inc. All rights reserved. * Copyright (C) 2007, 2008 Apple Inc. All rights reserved.
* Copyright (C) 2007 Brent Fulgham
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
...@@ -26,10 +25,95 @@ ...@@ -26,10 +25,95 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#include "config.h" #include "config.h"
#include "Threading.h" #include "Threading.h"
namespace WebCore { #include <windows.h>
#include <wtf/HashMap.h>
namespace WTF {
static Mutex& threadMapMutex()
{
static Mutex mutex;
return mutex;
}
static HashMap<DWORD, HANDLE>& threadMap()
{
static HashMap<DWORD, HANDLE> 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>(threadIdentifier);
storeThreadHandleByIdentifier(threadIdentifier, threadHandle);
return threadID;
}
int waitForThreadCompletion(ThreadIdentifier threadID, void** result)