Skip to content
Permalink
Browse files
Move isMainThread predicate function to MainThread.h

Reviewed by Anders Carlsson.

JavaScriptCore:

* wtf/MainThread.cpp:
(WTF::initializeMainThread):
(WTF::isMainThread):
* wtf/MainThread.h:
* wtf/Threading.h:
* wtf/ThreadingPthreads.cpp:
(WTF::initializeThreading):
* wtf/ThreadingWin.cpp:
(WTF::initializeThreading):
* wtf/gtk/ThreadingGtk.cpp:
(WTF::initializeThreading):
* wtf/mac/MainThreadMac.mm:
(WTF::initializeMainThreadPlatform):
(WTF::isMainThread):
* wtf/qt/MainThreadQt.cpp:
(WTF::isMainThread):
* wtf/qt/ThreadingQt.cpp:
(WTF::initializeThreading):
* wtf/text/AtomicString.cpp:

JavaScriptGlue:

Added forwarding header for MainThread.h

* ForwardingHeaders/wtf/MainThread.h: Added.

WebKitTools:

Added forwarding header for MainThread.h

* DumpRenderTree/ForwardingHeaders/wtf/MainThread.h: Added.



Canonical link: https://commits.webkit.org/49459@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@58179 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
weinig committed Apr 23, 2010
1 parent 47c6559 commit 1e28937a1aa864ca6454bbf85a62c9c737ade056
Showing 15 changed files with 87 additions and 46 deletions.
@@ -1,3 +1,30 @@
2010-04-22 Sam Weinig <sam@webkit.org>

Reviewed by Anders Carlsson.

Fix for https://bugs.webkit.org/show_bug.cgi?id=38022
Move isMainThread predicate function to MainThread.h

* wtf/MainThread.cpp:
(WTF::initializeMainThread):
(WTF::isMainThread):
* wtf/MainThread.h:
* wtf/Threading.h:
* wtf/ThreadingPthreads.cpp:
(WTF::initializeThreading):
* wtf/ThreadingWin.cpp:
(WTF::initializeThreading):
* wtf/gtk/ThreadingGtk.cpp:
(WTF::initializeThreading):
* wtf/mac/MainThreadMac.mm:
(WTF::initializeMainThreadPlatform):
(WTF::isMainThread):
* wtf/qt/MainThreadQt.cpp:
(WTF::isMainThread):
* wtf/qt/ThreadingQt.cpp:
(WTF::initializeThreading):
* wtf/text/AtomicString.cpp:

2010-04-23 Gabor Rapcsanyi <rgabor@inf.u-szeged.hu>

Reviewed by Laszlo Gombos.
@@ -36,6 +36,10 @@

namespace WTF {

#if !PLATFORM(MAC) && !PLATFORM(QT)
static ThreadIdentifier mainThreadIdentifier;
#endif

struct FunctionWithContext {
MainThreadFunction* function;
void* context;
@@ -69,6 +73,10 @@ void initializeMainThread()
{
mainThreadFunctionQueueMutex();
initializeMainThreadPlatform();

#if !PLATFORM(MAC) && !PLATFORM(QT)
mainThreadIdentifier = currentThread();
#endif
}

// 0.1 sec delays in UI is approximate threshold when they become noticeable. Have a limit that's half of that.
@@ -152,4 +160,11 @@ void setMainThreadCallbacksPaused(bool paused)
scheduleDispatchFunctionsOnMainThread();
}

#if !PLATFORM(MAC) && !PLATFORM(QT)
bool isMainThread()
{
return currentThread() == mainThreadIdentifier;
}
#endif

} // namespace WTF
@@ -52,10 +52,13 @@ void scheduleDispatchFunctionsOnMainThread();
Mutex& mainThreadFunctionQueueMutex();
void dispatchFunctionsFromMainThread();

bool isMainThread();

} // namespace WTF

using WTF::callOnMainThread;
using WTF::callOnMainThreadAndWait;
using WTF::setMainThreadCallbacksPaused;
using WTF::isMainThread;

#endif // MainThread_h
@@ -67,6 +67,7 @@

#include <wtf/Assertions.h>
#include <wtf/Locker.h>
#include <wtf/MainThread.h>
#include <wtf/Noncopyable.h>

#if OS(WINDOWS) && !OS(WINCE)
@@ -124,7 +125,6 @@ ThreadIdentifier createThreadInternal(ThreadFunction, void*, const char* threadN
void initializeCurrentThreadInternal(const char* threadName);

ThreadIdentifier currentThread();
bool isMainThread();
int waitForThreadCompletion(ThreadIdentifier, void**);
void detachThread(ThreadIdentifier);

@@ -343,7 +343,6 @@ using WTF::atomicIncrement;

using WTF::createThread;
using WTF::currentThread;
using WTF::isMainThread;
using WTF::detachThread;
using WTF::waitForThreadCompletion;

@@ -57,10 +57,6 @@ typedef HashMap<ThreadIdentifier, pthread_t> ThreadMap;

static Mutex* atomicallyInitializedStaticMutex;

#if !OS(DARWIN) || PLATFORM(CHROMIUM) || USE(WEB_THREAD)
static pthread_t mainThread; // The thread that was the first to call initializeThreading(), which must be the main thread.
#endif

void clearPthreadHandleForIdentifier(ThreadIdentifier);

static Mutex& threadMapMutex()
@@ -75,9 +71,6 @@ void initializeThreading()
atomicallyInitializedStaticMutex = new Mutex;
threadMapMutex();
initializeRandomNumberGenerator();
#if !OS(DARWIN) || PLATFORM(CHROMIUM) || USE(WEB_THREAD)
mainThread = pthread_self();
#endif
initializeMainThread();
}
}
@@ -240,15 +233,6 @@ ThreadIdentifier currentThread()
return id;
}

bool isMainThread()
{
#if OS(DARWIN) && !PLATFORM(CHROMIUM) && !USE(WEB_THREAD)
return pthread_main_np();
#else
return pthread_equal(pthread_self(), mainThread);
#endif
}

Mutex::Mutex()
{
pthread_mutex_init(&m_mutex, NULL);
@@ -145,7 +145,6 @@ void unlockAtomicallyInitializedStaticMutex()
atomicallyInitializedStaticMutex->unlock();
}

static ThreadIdentifier mainThreadIdentifier;

static Mutex& threadMapMutex()
{
@@ -160,7 +159,6 @@ void initializeThreading()
threadMapMutex();
initializeRandomNumberGenerator();
initializeMainThread();
mainThreadIdentifier = currentThread();
initializeCurrentThreadInternal("Main Thread");
}
}
@@ -275,11 +273,6 @@ ThreadIdentifier currentThread()
return static_cast<ThreadIdentifier>(GetCurrentThreadId());
}

bool isMainThread()
{
return currentThread() == mainThreadIdentifier;
}

Mutex::Mutex()
{
m_mutex.m_recursionCount = 0;
@@ -44,8 +44,6 @@ namespace WTF {

static Mutex* atomicallyInitializedStaticMutex;

static ThreadIdentifier mainThreadIdentifier;

static Mutex& threadMapMutex()
{
static Mutex mutex;
@@ -62,7 +60,6 @@ void initializeThreading()
atomicallyInitializedStaticMutex = new Mutex;
threadMapMutex();
initializeRandomNumberGenerator();
mainThreadIdentifier = currentThread();
initializeMainThread();
}
}
@@ -168,11 +165,6 @@ ThreadIdentifier currentThread()
return establishIdentifierForThread(currentThread);
}

bool isMainThread()
{
return currentThread() == mainThreadIdentifier;
}

Mutex::Mutex()
: m_mutex(g_mutex_new())
{
@@ -52,6 +52,7 @@ - (void)call

static WTFMainThreadCaller* staticMainThreadCaller = nil;
#if USE(WEB_THREAD)
static pthread_t mainThread;
static NSThread* webThread = nil;
#endif

@@ -61,6 +62,7 @@ void initializeMainThreadPlatform()
staticMainThreadCaller = [[WTFMainThreadCaller alloc] init];

#if USE(WEB_THREAD)
mainThread = pthread_self();
webThread = [[NSThread currentThread] retain];
#endif
}
@@ -102,4 +104,13 @@ void scheduleDispatchFunctionsOnMainThread()
#endif
}

bool isMainThread()
{
#if USE(WEB_THREAD)
return pthread_equal(pthread_self(), mainThread);
#else
return pthread_main_np();
#endif
}

} // namespace WTF
@@ -34,7 +34,6 @@
#include <QtCore/QObject>
#include <QtCore/QCoreApplication>


namespace WTF {

class MainThreadInvoker : public QObject {
@@ -67,6 +66,11 @@ void scheduleDispatchFunctionsOnMainThread()
QMetaObject::invokeMethod(webkit_main_thread_invoker(), "dispatch", Qt::QueuedConnection);
}

bool isMainThread()
{
return QThread::currentThread() == QCoreApplication::instance()->thread();
}

} // namespace WTF

#include "MainThreadQt.moc"
@@ -84,8 +84,6 @@ public Q_SLOTS:

static Mutex* atomicallyInitializedStaticMutex;

static ThreadIdentifier mainThreadIdentifier;

static Mutex& threadMapMutex()
{
static Mutex mutex;
@@ -146,10 +144,6 @@ void initializeThreading()
atomicallyInitializedStaticMutex = new Mutex;
threadMapMutex();
initializeRandomNumberGenerator();
QThread* mainThread = QCoreApplication::instance()->thread();
mainThreadIdentifier = identifierByQthreadHandle(mainThread);
if (!mainThreadIdentifier)
mainThreadIdentifier = establishIdentifierForThread(mainThread);
initializeMainThread();
}
}
@@ -215,11 +209,6 @@ ThreadIdentifier currentThread()
return establishIdentifierForThread(currentThread);
}

bool isMainThread()
{
return QThread::currentThread() == QCoreApplication::instance()->thread();
}

Mutex::Mutex()
: m_mutex(new QMutex())
{
@@ -28,8 +28,8 @@

#include "StaticConstructors.h"
#include "StringHash.h"
#include <wtf/Threading.h>
#include <wtf/HashSet.h>
#include <wtf/Threading.h>
#include <wtf/WTFThreadData.h>
#include <wtf/text/AtomicStringTable.h>

@@ -1,3 +1,14 @@
2010-04-22 Sam Weinig <sam@webkit.org>

Reviewed by Anders Carlsson.

Fix for https://bugs.webkit.org/show_bug.cgi?id=38022
Move isMainThread predicate function to MainThread.h

Added forwarding header for MainThread.h

* ForwardingHeaders/wtf/MainThread.h: Added.

2010-04-22 Gavin Barraclough <barraclough@apple.com>

Rubber stamped by Sam Weinig
@@ -0,0 +1 @@
#include <JavaScriptCore/MainThread.h>
@@ -1,3 +1,14 @@
2010-04-22 Sam Weinig <sam@webkit.org>

Reviewed by Anders Carlsson.

Fix for https://bugs.webkit.org/show_bug.cgi?id=38022
Move isMainThread predicate function to MainThread.h

Added forwarding header for MainThread.h

* DumpRenderTree/ForwardingHeaders/wtf/MainThread.h: Added.

2010-04-23 Laszlo Gombos <laszlo.1.gombos@nokia.com>

Reviewed by Kenneth Rohde Christiansen.
@@ -0,0 +1 @@
#include <JavaScriptCore/MainThread.h>

0 comments on commit 1e28937

Please sign in to comment.