Commit 6f520711 authored by mrowe@apple.com's avatar mrowe@apple.com

2007-11-11 Justin Haygood <jhaygood@reaktix.com>

        Reviewed by Adam Roben.

        http://bugs.webkit.org/show_bug.cgi?id=15939
        Adds a currentThread API for use by SQLiteDatabase, etc.

        * platform/Threading.h:
        * platform/ThreadingNone.cpp:
        (WebCore::currentThread):
        * platform/gtk/ThreadingGtk.cpp:
        (WebCore::identifierByGthreadHandle):
        (WebCore::):
        * platform/pthreads/ThreadingPthreads.cpp:
        (WebCore::identifierByPthreadHandle):
        (WebCore::currentThread):


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@27707 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent cb71b59e
2007-11-11 Justin Haygood <jhaygood@reaktix.com>
Reviewed by Adam Roben.
http://bugs.webkit.org/show_bug.cgi?id=15939
Adds a currentThread API for use by SQLiteDatabase, etc.
* platform/Threading.h:
* platform/ThreadingNone.cpp:
(WebCore::currentThread):
* platform/gtk/ThreadingGtk.cpp:
(WebCore::identifierByGthreadHandle):
(WebCore::):
* platform/pthreads/ThreadingPthreads.cpp:
(WebCore::identifierByPthreadHandle):
(WebCore::currentThread):
2007-11-11 Dan Bernstein <mitz@apple.com> 2007-11-11 Dan Bernstein <mitz@apple.com>
Reviewed by Adam Roben. Reviewed by Adam Roben.
......
/* /*
* Copyright (C) 2007 Apple Inc. All rights reserved. * Copyright (C) 2007 Apple Inc. All rights reserved.
* Copyright (C) 2007 Justin Haygood (jhaygood@reaktix.com)
* *
* 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
...@@ -41,6 +42,11 @@ typedef struct _GMutex GMutex; ...@@ -41,6 +42,11 @@ typedef struct _GMutex GMutex;
typedef struct _GCond GCond; typedef struct _GCond GCond;
#endif #endif
#if PLATFORM(QT)
class QMutex;
class QWaitCondition;
#endif
#include <stdint.h> #include <stdint.h>
namespace WebCore { namespace WebCore {
...@@ -50,6 +56,7 @@ typedef void* (*ThreadFunction)(void* argument); ...@@ -50,6 +56,7 @@ typedef void* (*ThreadFunction)(void* argument);
// Returns 0 if thread creation failed // Returns 0 if thread creation failed
ThreadIdentifier createThread(ThreadFunction, void*); ThreadIdentifier createThread(ThreadFunction, void*);
ThreadIdentifier currentThread();
int waitForThreadCompletion(ThreadIdentifier, void**); int waitForThreadCompletion(ThreadIdentifier, void**);
void detachThread(ThreadIdentifier); void detachThread(ThreadIdentifier);
...@@ -59,6 +66,9 @@ typedef pthread_cond_t PlatformCondition; ...@@ -59,6 +66,9 @@ typedef pthread_cond_t PlatformCondition;
#elif PLATFORM(GTK) #elif PLATFORM(GTK)
typedef GMutex* PlatformMutex; typedef GMutex* PlatformMutex;
typedef GCond* PlatformCondition; typedef GCond* PlatformCondition;
#elif PLATFORM(QT)
typedef QMutex* PlatformMutex;
typedef QWaitCondition* PlatformCondition;
#else #else
typedef void* PlatformMutex; typedef void* PlatformMutex;
typedef void* PlatformCondition; typedef void* PlatformCondition;
......
/* /*
* Copyright (C) 2007 Apple Inc. All rights reserved. * Copyright (C) 2007 Apple Inc. All rights reserved.
* Copyright (C) 2007 Justin Haygood (jhaygood@reaktix.com)
* *
* 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
...@@ -33,6 +34,7 @@ namespace WebCore { ...@@ -33,6 +34,7 @@ namespace WebCore {
ThreadIdentifier createThread(ThreadFunction, void*) { return 0; } ThreadIdentifier createThread(ThreadFunction, void*) { return 0; }
int waitForThreadCompletion(ThreadIdentifier, void**) { return 0; } int waitForThreadCompletion(ThreadIdentifier, void**) { return 0; }
void detachThread(ThreadIdentifier) { } void detachThread(ThreadIdentifier) { }
ThreadIdentifier currentThread() { return 0; }
Mutex::Mutex() {} Mutex::Mutex() {}
Mutex::~Mutex() {} Mutex::~Mutex() {}
......
/* /*
* Copyright (C) 2007 Apple Inc. All rights reserved. * Copyright (C) 2007 Apple Inc. All rights reserved.
* Copyright (C) 2007 Justin Haygood (jhaygood@reaktix.com)
* *
* 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
...@@ -79,6 +80,19 @@ static ThreadIdentifier establishIdentifierForThread(GThread*& thread) ...@@ -79,6 +80,19 @@ static ThreadIdentifier establishIdentifierForThread(GThread*& thread)
return identifierCount++; return identifierCount++;
} }
static ThreadIdentifier identifierByGthreadHandle(GThread*& thread)
{
MutexLocker locker(threadMapMutex());
HashMap<ThreadIdentifier, GThread*>::iterator i = threadMap().begin();
for (; i != threadMap().end(); ++i) {
if (i->second == thread)
return i->first;
}
return 0;
}
static GThread* threadForIdentifier(ThreadIdentifier id) static GThread* threadForIdentifier(ThreadIdentifier id)
{ {
MutexLocker locker(threadMapMutex()); MutexLocker locker(threadMapMutex());
...@@ -124,6 +138,14 @@ void detachThread(ThreadIdentifier) ...@@ -124,6 +138,14 @@ void detachThread(ThreadIdentifier)
{ {
} }
ThreadIdentifier currentThread()
{
GThread* currentThread = g_thread_self();
if (ThreadIdentifier id = identifierByGthreadHandle(currentThread))
return id;
return establishIdentifierForThread(currentThread);
}
Mutex::Mutex() Mutex::Mutex()
: m_mutex(g_mutex_new()) : m_mutex(g_mutex_new())
{ {
......
/* /*
* Copyright (C) 2007 Apple Inc. All rights reserved. * Copyright (C) 2007 Apple Inc. All rights reserved.
* Copyright (C) 2007 Justin Haygood (jhaygood@reaktix.com)
* *
* 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
...@@ -58,6 +59,19 @@ static ThreadIdentifier establishIdentifierForPthreadHandle(pthread_t& pthreadHa ...@@ -58,6 +59,19 @@ static ThreadIdentifier establishIdentifierForPthreadHandle(pthread_t& pthreadHa
return identifierCount++; return identifierCount++;
} }
static ThreadIdentifier identifierByPthreadHandle(const pthread_t& pthreadHandle)
{
MutexLocker locker(threadMapMutex());
HashMap<ThreadIdentifier, pthread_t>::iterator i = threadMap().begin();
for (; i != threadMap().end(); ++i) {
if (pthread_equal(i->second, pthreadHandle))
return i->first;
}
return 0;
}
static pthread_t pthreadHandleForIdentifier(ThreadIdentifier id) static pthread_t pthreadHandleForIdentifier(ThreadIdentifier id)
{ {
MutexLocker locker(threadMapMutex()); MutexLocker locker(threadMapMutex());
...@@ -112,6 +126,14 @@ void detachThread(ThreadIdentifier threadID) ...@@ -112,6 +126,14 @@ void detachThread(ThreadIdentifier threadID)
clearPthreadHandleForIdentifier(threadID); clearPthreadHandleForIdentifier(threadID);
} }
ThreadIdentifier currentThread()
{
pthread_t currentThread = pthread_self();
if (ThreadIdentifier id = identifierByPthreadHandle(currentThread))
return id;
return establishIdentifierForPthreadHandle(currentThread);
}
Mutex::Mutex() Mutex::Mutex()
{ {
pthread_mutex_init(&m_mutex, NULL); pthread_mutex_init(&m_mutex, NULL);
......
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