summaryrefslogtreecommitdiff
path: root/Source/WTF/wtf/ThreadingPthreads.cpp
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@lorry>2017-06-27 06:07:23 +0000
committerLorry Tar Creator <lorry-tar-importer@lorry>2017-06-27 06:07:23 +0000
commit1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c (patch)
tree46dcd36c86e7fbc6e5df36deb463b33e9967a6f7 /Source/WTF/wtf/ThreadingPthreads.cpp
parent32761a6cee1d0dee366b885b7b9c777e67885688 (diff)
downloadWebKitGtk-tarball-master.tar.gz
Diffstat (limited to 'Source/WTF/wtf/ThreadingPthreads.cpp')
-rw-r--r--Source/WTF/wtf/ThreadingPthreads.cpp61
1 files changed, 42 insertions, 19 deletions
diff --git a/Source/WTF/wtf/ThreadingPthreads.cpp b/Source/WTF/wtf/ThreadingPthreads.cpp
index dab2d447f..646164a53 100644
--- a/Source/WTF/wtf/ThreadingPthreads.cpp
+++ b/Source/WTF/wtf/ThreadingPthreads.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2007, 2009 Apple Inc. All rights reserved.
+ * Copyright (C) 2007, 2009, 2015 Apple Inc. All rights reserved.
* Copyright (C) 2007 Justin Haygood (jhaygood@reaktix.com)
* Copyright (C) 2011 Research In Motion Limited. All rights reserved.
*
@@ -12,7 +12,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * 3. Neither the name of Apple Inc. ("Apple") nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
@@ -39,13 +39,13 @@
#include "dtoa/cached-powers.h"
#include "HashMap.h"
#include "RandomNumberSeed.h"
-#include "StackStats.h"
#include "StdLibExtras.h"
#include "ThreadFunctionInvocation.h"
#include "ThreadIdentifierDataPthreads.h"
#include "ThreadSpecific.h"
-#include <wtf/OwnPtr.h>
-#include <wtf/PassOwnPtr.h>
+#include <wtf/DataLog.h>
+#include <wtf/NeverDestroyed.h>
+#include <wtf/RawPointer.h>
#include <wtf/WTFThreadData.h>
#include <errno.h>
@@ -55,8 +55,8 @@
#include <sys/time.h>
#endif
-#if OS(MAC_OS_X)
-#include <objc/objc-auto.h>
+#if OS(LINUX)
+#include <sys/prctl.h>
#endif
namespace WTF {
@@ -104,7 +104,7 @@ void threadWasJoined(ThreadIdentifier);
static Mutex& threadMapMutex()
{
- DEFINE_STATIC_LOCAL(Mutex, mutex, ());
+ static NeverDestroyed<Mutex> mutex;
return mutex;
}
@@ -124,15 +124,13 @@ void initializeThreading()
threadMapMutex();
initializeRandomNumberGenerator();
ThreadIdentifierData::initializeOnce();
- StackStats::initialize();
wtfThreadData();
- s_dtoaP5Mutex = new Mutex;
initializeDates();
}
static ThreadMap& threadMap()
{
- DEFINE_STATIC_LOCAL(ThreadMap, map, ());
+ static NeverDestroyed<ThreadMap> map;
return map;
}
@@ -175,7 +173,14 @@ ThreadIdentifier createThreadInternal(ThreadFunction entryPoint, void* data, con
{
auto invocation = std::make_unique<ThreadFunctionInvocation>(entryPoint, data);
pthread_t threadHandle;
- if (pthread_create(&threadHandle, 0, wtfThreadEntryPoint, invocation.get())) {
+ pthread_attr_t attr;
+ pthread_attr_init(&attr);
+#if HAVE(QOS_CLASSES)
+ pthread_attr_set_qos_class_np(&attr, adjustedQOSClass(QOS_CLASS_USER_INITIATED), 0);
+#endif
+ int error = pthread_create(&threadHandle, &attr, wtfThreadEntryPoint, invocation.get());
+ pthread_attr_destroy(&attr);
+ if (error) {
LOG_ERROR("Failed to create pthread at entry point %p with data %p", wtfThreadEntryPoint, invocation.get());
return 0;
}
@@ -190,21 +195,39 @@ ThreadIdentifier createThreadInternal(ThreadFunction entryPoint, void* data, con
void initializeCurrentThreadInternal(const char* threadName)
{
#if HAVE(PTHREAD_SETNAME_NP)
- pthread_setname_np(threadName);
+ pthread_setname_np(normalizeThreadName(threadName));
+#elif OS(LINUX)
+ prctl(PR_SET_NAME, normalizeThreadName(threadName));
#else
UNUSED_PARAM(threadName);
#endif
-#if OS(MAC_OS_X)
- // All threads that potentially use APIs above the BSD layer must be registered with the Objective-C
- // garbage collector in case API implementations use garbage-collected memory.
- objc_registerThreadWithCollector();
-#endif
-
ThreadIdentifier id = identifierByPthreadHandle(pthread_self());
ASSERT(id);
ThreadIdentifierData::initialize(id);
}
+
+void changeThreadPriority(ThreadIdentifier threadID, int delta)
+{
+ pthread_t pthreadHandle;
+ ASSERT(threadID);
+
+ {
+ MutexLocker locker(threadMapMutex());
+ pthreadHandle = pthreadHandleForIdentifierWithLockAlreadyHeld(threadID);
+ ASSERT(pthreadHandle);
+ }
+
+ int policy;
+ struct sched_param param;
+
+ if (pthread_getschedparam(pthreadHandle, &policy, &param))
+ return;
+
+ param.sched_priority += delta;
+
+ pthread_setschedparam(pthreadHandle, policy, &param);
+}
int waitForThreadCompletion(ThreadIdentifier threadID)
{