Commit a3af6a64 authored by aroben@apple.com's avatar aroben@apple.com
Browse files

Add WTF::isMainThread

        Reviewed by Alexey Proskuryakov.

        * wtf/Threading.h: Declare the new function.
        * wtf/ThreadingGtk.cpp:
        (WTF::initializeThreading): Initialize the main thread identifier.
        (WTF::isMainThread): Added.
        * wtf/ThreadingNone.cpp: Ditto ThreadingGtk.cpp.
        (WTF::initializeThreading):
        (WTF::isMainThread):
        * wtf/ThreadingPthreads.cpp: Ditto.
        (WTF::initializeThreading):
        (WTF::isMainThread):
        * wtf/ThreadingWin.cpp: Ditto.
        (WTF::initializeThreading):
        (WTF::isMainThread):


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@31690 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 7cda5b10
2008-04-07 Adam Roben <aroben@apple.com>
Add WTF::isMainThread
Reviewed by Alexey Proskuryakov.
* wtf/Threading.h: Declare the new function.
* wtf/ThreadingGtk.cpp:
(WTF::initializeThreading): Initialize the main thread identifier.
(WTF::isMainThread): Added.
* wtf/ThreadingNone.cpp: Ditto ThreadingGtk.cpp.
(WTF::initializeThreading):
(WTF::isMainThread):
* wtf/ThreadingPthreads.cpp: Ditto.
(WTF::initializeThreading):
(WTF::isMainThread):
* wtf/ThreadingWin.cpp: Ditto.
(WTF::initializeThreading):
(WTF::isMainThread):
2008-04-06 Alexey Proskuryakov <ap@webkit.org>
Reviewed by Darin.
......
......@@ -105,6 +105,7 @@ typedef void* (*ThreadFunction)(void* argument);
// Returns 0 if thread creation failed
ThreadIdentifier createThread(ThreadFunction, void*);
ThreadIdentifier currentThread();
bool isMainThread();
int waitForThreadCompletion(ThreadIdentifier, void**);
void detachThread(ThreadIdentifier);
......@@ -252,6 +253,7 @@ using WTF::ThreadSafeShared;
using WTF::createThread;
using WTF::currentThread;
using WTF::isMainThread;
using WTF::detachThread;
using WTF::waitForThreadCompletion;
......
......@@ -39,6 +39,8 @@ namespace WTF {
Mutex* atomicallyInitializedStaticMutex;
static ThreadIdentifier mainThreadIdentifier;
void initializeThreading()
{
if (!g_thread_supported()) {
......@@ -46,6 +48,7 @@ void initializeThreading()
ASSERT(!atomicallyInitializedStaticMutex);
atomicallyInitializedStaticMutex = new Mutex;
wtf_random_init();
mainThreadIdentifier = currentThread();
}
ASSERT(g_thread_supported());
}
......@@ -138,6 +141,11 @@ ThreadIdentifier currentThread()
return establishIdentifierForThread(currentThread);
}
bool isMainThread()
{
return currentThread() == mainThreadIdentifier;
}
Mutex::Mutex()
: m_mutex(g_mutex_new())
{
......
......@@ -38,6 +38,7 @@ ThreadIdentifier createThread(ThreadFunction, void*) { return 0; }
int waitForThreadCompletion(ThreadIdentifier, void**) { return 0; }
void detachThread(ThreadIdentifier) { }
ThreadIdentifier currentThread() { return 0; }
bool isMainThread() { return false; }
Mutex::Mutex() {}
Mutex::~Mutex() {}
......
......@@ -39,11 +39,14 @@ namespace WTF {
Mutex* atomicallyInitializedStaticMutex;
static ThreadIdentifier mainThreadIdentifier;
void initializeThreading()
{
if (!atomicallyInitializedStaticMutex) {
atomicallyInitializedStaticMutex = new Mutex;
wtf_random_init();
mainThreadIdentifier = currentThread();
}
}
......@@ -144,6 +147,11 @@ ThreadIdentifier currentThread()
return establishIdentifierForPthreadHandle(currentThread);
}
bool isMainThread()
{
return currentThread() == mainThreadIdentifier;
}
Mutex::Mutex()
{
pthread_mutex_init(&m_mutex, NULL);
......
......@@ -63,6 +63,7 @@
#include "config.h"
#include "Threading.h"
#include "MainThread.h"
#include <windows.h>
#include <wtf/HashMap.h>
#include <wtf/MathExtras.h>
......@@ -71,11 +72,15 @@ namespace WTF {
Mutex* atomicallyInitializedStaticMutex;
static ThreadIdentifier mainThreadIdentifier;
void initializeThreading()
{
if (!atomicallyInitializedStaticMutex) {
atomicallyInitializedStaticMutex = new Mutex;
wtf_random_init();
initializeMainThread();
mainThreadIdentifier = currentThread();
}
}
......@@ -160,6 +165,11 @@ ThreadIdentifier currentThread()
return static_cast<ThreadIdentifier>(::GetCurrentThreadId());
}
bool isMainThread()
{
return currentThread() == mainThreadIdentifier;
}
Mutex::Mutex()
{
m_mutex.m_recursionCount = 0;
......
Supports Markdown
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