Commit 0e011882 authored by darin@apple.com's avatar darin@apple.com
Browse files

2009-03-11 Darin Adler <darin@apple.com>

        Reviewed by Mark Rowe.

        Give threads names on platforms with pthread_setname_np.

        * wtf/Threading.cpp:
        (WTF::NewThreadContext::NewThreadContext): Initialize thread name.
        (WTF::threadEntryPoint): Call setThreadNameInternal.
        (WTF::createThread): Pass thread name.

        * wtf/Threading.h: Added new comments, setThreadNameInternal.

        * wtf/ThreadingGtk.cpp:
        (WTF::setThreadNameInternal): Added. Empty.
        * wtf/ThreadingNone.cpp:
        (WTF::setThreadNameInternal): Added. Empty.
        * wtf/ThreadingPthreads.cpp:
        (WTF::setThreadNameInternal): Call pthread_setname_np when available.
        * wtf/ThreadingQt.cpp:
        (WTF::setThreadNameInternal): Added. Empty.
        * wtf/ThreadingWin.cpp:
        (WTF::setThreadNameInternal): Added. Empty.



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@41605 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 177a62e1
2009-03-11 Darin Adler <darin@apple.com>
Reviewed by Mark Rowe.
Give threads names on platforms with pthread_setname_np.
* wtf/Threading.cpp:
(WTF::NewThreadContext::NewThreadContext): Initialize thread name.
(WTF::threadEntryPoint): Call setThreadNameInternal.
(WTF::createThread): Pass thread name.
* wtf/Threading.h: Added new comments, setThreadNameInternal.
* wtf/ThreadingGtk.cpp:
(WTF::setThreadNameInternal): Added. Empty.
* wtf/ThreadingNone.cpp:
(WTF::setThreadNameInternal): Added. Empty.
* wtf/ThreadingPthreads.cpp:
(WTF::setThreadNameInternal): Call pthread_setname_np when available.
* wtf/ThreadingQt.cpp:
(WTF::setThreadNameInternal): Added. Empty.
* wtf/ThreadingWin.cpp:
(WTF::setThreadNameInternal): Added. Empty.
2009-03-11 Adam Roben <aroben@apple.com>
 
Change the Windows implementation of ThreadSpecific to use functions
/*
* Copyright (C) 2008 Apple Inc. All rights reserved.
* Copyright (C) 2008, 2009 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
......@@ -29,13 +29,16 @@
namespace WTF {
struct NewThreadContext {
NewThreadContext(ThreadFunction entryPoint, void* data)
NewThreadContext(ThreadFunction entryPoint, void* data, const char* name)
: entryPoint(entryPoint)
, data(data)
{ }
, name(name)
{
}
ThreadFunction entryPoint;
void* data;
const char* name;
Mutex creationMutex;
};
......@@ -44,6 +47,8 @@ static void* threadEntryPoint(void* contextData)
{
NewThreadContext* context = reinterpret_cast<NewThreadContext*>(contextData);
setThreadNameInternal(context->name);
// Block until our creating thread has completed any extra setup work
{
MutexLocker locker(context->creationMutex);
......@@ -59,7 +64,7 @@ static void* threadEntryPoint(void* contextData)
ThreadIdentifier createThread(ThreadFunction entryPoint, void* data, const char* name)
{
NewThreadContext* context = new NewThreadContext(entryPoint, data);
NewThreadContext* context = new NewThreadContext(entryPoint, data, name);
// Prevent the thread body from executing until we've established the thread identifier
MutexLocker locker(context->creationMutex);
......
......@@ -108,10 +108,17 @@ namespace WTF {
typedef uint32_t ThreadIdentifier;
typedef void* (*ThreadFunction)(void* argument);
// Returns 0 if thread creation failed
// Returns 0 if thread creation failed.
// The thread name must be a literal since on some platforms it's passed in to the thread.
ThreadIdentifier createThread(ThreadFunction, void*, const char* threadName);
// Internal platform-specific createThread implementation.
ThreadIdentifier createThreadInternal(ThreadFunction, void*, const char* threadName);
// Called in the thread during initialization.
// Helpful for platforms where the thread name must be set from within the thread.
void setThreadNameInternal(const char* threadName);
ThreadIdentifier currentThread();
bool isMainThread();
int waitForThreadCompletion(ThreadIdentifier, void**);
......
......@@ -138,6 +138,10 @@ ThreadIdentifier createThreadInternal(ThreadFunction entryPoint, void* data, con
return threadID;
}
void setThreadNameInternal(const char*)
{
}
int waitForThreadCompletion(ThreadIdentifier threadID, void** result)
{
ASSERT(threadID);
......
......@@ -34,6 +34,7 @@ namespace WTF {
void initializeThreading() { }
ThreadIdentifier createThreadInternal(ThreadFunction, void*, const char*) { return 0; }
void setThreadNameInternal(const char*) { }
int waitForThreadCompletion(ThreadIdentifier, void**) { return 0; }
void detachThread(ThreadIdentifier) { }
ThreadIdentifier currentThread() { return 0; }
......
/*
* Copyright (C) 2007 Apple Inc. All rights reserved.
* Copyright (C) 2007, 2009 Apple Inc. All rights reserved.
* Copyright (C) 2007 Justin Haygood (jhaygood@reaktix.com)
*
* Redistribution and use in source and binary forms, with or without
......@@ -26,18 +26,18 @@
* (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"
#include "StdLibExtras.h"
#if USE(PTHREADS)
#include "CurrentTime.h"
#include "HashMap.h"
#include "MainThread.h"
#include "RandomNumberSeed.h"
#include "StdLibExtras.h"
#include "UnusedParam.h"
#include <errno.h>
#include <limits.h>
#include <sys/time.h>
......@@ -133,7 +133,7 @@ static void clearPthreadHandleForIdentifier(ThreadIdentifier id)
ThreadIdentifier createThreadInternal(ThreadFunction entryPoint, void* data, const char*)
{
pthread_t threadHandle;
if (pthread_create(&threadHandle, NULL, entryPoint, data)) {
if (pthread_create(&threadHandle, 0, entryPoint, data)) {
LOG_ERROR("Failed to create pthread at entry point %p with data %p", entryPoint, data);
return 0;
}
......@@ -141,6 +141,15 @@ ThreadIdentifier createThreadInternal(ThreadFunction entryPoint, void* data, con
return establishIdentifierForPthreadHandle(threadHandle);
}
void setThreadNameInternal(const char* threadName)
{
#if PLATFORM(DARWIN) && !defined(BUILDING_ON_TIGER) && !defined(BUILDING_ON_LEOPARD)
pthread_setname_np(threadName);
#else
UNUSED_PARAM(threadName);
#endif
}
int waitForThreadCompletion(ThreadIdentifier threadID, void** result)
{
ASSERT(threadID);
......
......@@ -162,6 +162,10 @@ ThreadIdentifier createThreadInternal(ThreadFunction entryPoint, void* data, con
return establishIdentifierForThread(threadRef);
}
void setThreadNameInternal(const char*)
{
}
int waitForThreadCompletion(ThreadIdentifier threadID, void** result)
{
ASSERT(threadID);
......
......@@ -229,6 +229,10 @@ ThreadIdentifier createThreadInternal(ThreadFunction entryPoint, void* data, con
return threadID;
}
void setThreadNameInternal(const char*)
{
}
int waitForThreadCompletion(ThreadIdentifier threadID, void** result)
{
ASSERT(threadID);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment