Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 1e28937
Show file tree
Hide file tree
Showing 15 changed files with 87 additions and 46 deletions.
27 changes: 27 additions & 0 deletions JavaScriptCore/ChangeLog
@@ -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.
Expand Down
15 changes: 15 additions & 0 deletions JavaScriptCore/wtf/MainThread.cpp
Expand Up @@ -36,6 +36,10 @@

namespace WTF {

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

struct FunctionWithContext {
MainThreadFunction* function;
void* context;
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -152,4 +160,11 @@ void setMainThreadCallbacksPaused(bool paused)
scheduleDispatchFunctionsOnMainThread();
}

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

} // namespace WTF
3 changes: 3 additions & 0 deletions JavaScriptCore/wtf/MainThread.h
Expand Up @@ -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
3 changes: 1 addition & 2 deletions JavaScriptCore/wtf/Threading.h
Expand Up @@ -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)
Expand Down Expand Up @@ -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);

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

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

Expand Down
16 changes: 0 additions & 16 deletions JavaScriptCore/wtf/ThreadingPthreads.cpp
Expand Up @@ -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()
Expand All @@ -75,9 +71,6 @@ void initializeThreading()
atomicallyInitializedStaticMutex = new Mutex;
threadMapMutex();
initializeRandomNumberGenerator();
#if !OS(DARWIN) || PLATFORM(CHROMIUM) || USE(WEB_THREAD)
mainThread = pthread_self();
#endif
initializeMainThread();
}
}
Expand Down Expand Up @@ -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);
Expand Down
7 changes: 0 additions & 7 deletions JavaScriptCore/wtf/ThreadingWin.cpp
Expand Up @@ -145,7 +145,6 @@ void unlockAtomicallyInitializedStaticMutex()
atomicallyInitializedStaticMutex->unlock();
}

static ThreadIdentifier mainThreadIdentifier;

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

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

Mutex::Mutex()
{
m_mutex.m_recursionCount = 0;
Expand Down
8 changes: 0 additions & 8 deletions JavaScriptCore/wtf/gtk/ThreadingGtk.cpp
Expand Up @@ -44,8 +44,6 @@ namespace WTF {

static Mutex* atomicallyInitializedStaticMutex;

static ThreadIdentifier mainThreadIdentifier;

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

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

Mutex::Mutex()
: m_mutex(g_mutex_new())
{
Expand Down
11 changes: 11 additions & 0 deletions JavaScriptCore/wtf/mac/MainThreadMac.mm
Expand Up @@ -52,6 +52,7 @@ - (void)call

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

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

#if USE(WEB_THREAD)
mainThread = pthread_self();
webThread = [[NSThread currentThread] retain];
#endif
}
Expand Down Expand Up @@ -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
6 changes: 5 additions & 1 deletion JavaScriptCore/wtf/qt/MainThreadQt.cpp
Expand Up @@ -34,7 +34,6 @@
#include <QtCore/QObject>
#include <QtCore/QCoreApplication>


namespace WTF {

class MainThreadInvoker : public QObject {
Expand Down Expand Up @@ -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"
11 changes: 0 additions & 11 deletions JavaScriptCore/wtf/qt/ThreadingQt.cpp
Expand Up @@ -84,8 +84,6 @@ public Q_SLOTS:

static Mutex* atomicallyInitializedStaticMutex;

static ThreadIdentifier mainThreadIdentifier;

static Mutex& threadMapMutex()
{
static Mutex mutex;
Expand Down Expand Up @@ -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();
}
}
Expand Down Expand Up @@ -215,11 +209,6 @@ ThreadIdentifier currentThread()
return establishIdentifierForThread(currentThread);
}

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

Mutex::Mutex()
: m_mutex(new QMutex())
{
Expand Down
2 changes: 1 addition & 1 deletion JavaScriptCore/wtf/text/AtomicString.cpp
Expand Up @@ -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>

Expand Down
11 changes: 11 additions & 0 deletions JavaScriptGlue/ChangeLog
@@ -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
Expand Down
1 change: 1 addition & 0 deletions JavaScriptGlue/ForwardingHeaders/wtf/MainThread.h
@@ -0,0 +1 @@
#include <JavaScriptCore/MainThread.h>
11 changes: 11 additions & 0 deletions WebKitTools/ChangeLog
@@ -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.
Expand Down
@@ -0,0 +1 @@
#include <JavaScriptCore/MainThread.h>

0 comments on commit 1e28937

Please sign in to comment.