summaryrefslogtreecommitdiff
path: root/Source/WTF/wtf/ThreadingWin.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Source/WTF/wtf/ThreadingWin.cpp')
-rw-r--r--Source/WTF/wtf/ThreadingWin.cpp56
1 files changed, 23 insertions, 33 deletions
diff --git a/Source/WTF/wtf/ThreadingWin.cpp b/Source/WTF/wtf/ThreadingWin.cpp
index e37c77e07..54b43efef 100644
--- a/Source/WTF/wtf/ThreadingWin.cpp
+++ b/Source/WTF/wtf/ThreadingWin.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2007, 2008 Apple Inc. All rights reserved.
+ * Copyright (C) 2007, 2008, 2015 Apple Inc. All rights reserved.
* Copyright (C) 2009 Google Inc. All rights reserved.
* Copyright (C) 2009 Torch Mobile, Inc. 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.
*
@@ -94,23 +94,15 @@
#include "MainThread.h"
#include "ThreadFunctionInvocation.h"
+#include <process.h>
#include <windows.h>
#include <wtf/CurrentTime.h>
#include <wtf/HashMap.h>
#include <wtf/MathExtras.h>
-#include <wtf/OwnPtr.h>
-#include <wtf/PassOwnPtr.h>
+#include <wtf/NeverDestroyed.h>
#include <wtf/RandomNumberSeed.h>
#include <wtf/WTFThreadData.h>
-#if !USE(PTHREADS) && OS(WINDOWS)
-#include "ThreadSpecific.h"
-#endif
-
-#if !OS(WINCE)
-#include <process.h>
-#endif
-
#if HAVE(ERRNO_H)
#include <errno.h>
#endif
@@ -137,7 +129,7 @@ void initializeCurrentThreadInternal(const char* szThreadName)
#else
THREADNAME_INFO info;
info.dwType = 0x1000;
- info.szName = szThreadName;
+ info.szName = normalizeThreadName(szThreadName);
info.dwThreadID = GetCurrentThreadId();
info.dwFlags = 0;
@@ -150,7 +142,7 @@ void initializeCurrentThreadInternal(const char* szThreadName)
static Mutex& threadMapMutex()
{
- static Mutex mutex;
+ static NeverDestroyed<Mutex> mutex;
return mutex;
}
@@ -170,13 +162,12 @@ void initializeThreading()
threadMapMutex();
initializeRandomNumberGenerator();
wtfThreadData();
- s_dtoaP5Mutex = new Mutex;
initializeDates();
}
static HashMap<DWORD, HANDLE>& threadMap()
{
- static HashMap<DWORD, HANDLE> map;
+ static NeverDestroyed<HashMap<DWORD, HANDLE>> map;
return map;
}
@@ -202,14 +193,9 @@ static void clearThreadHandleForIdentifier(ThreadIdentifier id)
static unsigned __stdcall wtfThreadEntryPoint(void* param)
{
- OwnPtr<ThreadFunctionInvocation> invocation = adoptPtr(static_cast<ThreadFunctionInvocation*>(param));
+ std::unique_ptr<ThreadFunctionInvocation> invocation(static_cast<ThreadFunctionInvocation*>(param));
invocation->function(invocation->data);
-#if !USE(PTHREADS) && OS(WINDOWS)
- // Do the TLS cleanup.
- ThreadSpecificThreadExit();
-#endif
-
return 0;
}
@@ -217,18 +203,10 @@ ThreadIdentifier createThreadInternal(ThreadFunction entryPoint, void* data, con
{
unsigned threadIdentifier = 0;
ThreadIdentifier threadID = 0;
- OwnPtr<ThreadFunctionInvocation> invocation = adoptPtr(new ThreadFunctionInvocation(entryPoint, data));
-#if OS(WINCE)
- // This is safe on WINCE, since CRT is in the core and innately multithreaded.
- // On desktop Windows, need to use _beginthreadex (not available on WinCE) if using any CRT functions
- HANDLE threadHandle = CreateThread(0, 0, (LPTHREAD_START_ROUTINE)wtfThreadEntryPoint, invocation.get(), 0, (LPDWORD)&threadIdentifier);
-#else
+ auto invocation = std::make_unique<ThreadFunctionInvocation>(entryPoint, data);
HANDLE threadHandle = reinterpret_cast<HANDLE>(_beginthreadex(0, 0, wtfThreadEntryPoint, invocation.get(), 0, &threadIdentifier));
-#endif
if (!threadHandle) {
-#if OS(WINCE)
- LOG_ERROR("Failed to create thread at entry point %p with data %p: %ld", entryPoint, data, ::GetLastError());
-#elif !HAVE(ERRNO_H)
+#if !HAVE(ERRNO_H)
LOG_ERROR("Failed to create thread at entry point %p with data %p.", entryPoint, data);
#else
LOG_ERROR("Failed to create thread at entry point %p with data %p: %ld", entryPoint, data, errno);
@@ -237,7 +215,7 @@ ThreadIdentifier createThreadInternal(ThreadFunction entryPoint, void* data, con
}
// The thread will take ownership of invocation.
- ThreadFunctionInvocation* leakedInvocation = invocation.leakPtr();
+ ThreadFunctionInvocation* leakedInvocation = invocation.release();
UNUSED_PARAM(leakedInvocation);
threadID = static_cast<ThreadIdentifier>(threadIdentifier);
@@ -246,6 +224,17 @@ ThreadIdentifier createThreadInternal(ThreadFunction entryPoint, void* data, con
return threadID;
}
+void changeThreadPriority(ThreadIdentifier threadID, int delta)
+{
+ ASSERT(threadID);
+
+ HANDLE threadHandle = threadHandleForIdentifier(threadID);
+ if (!threadHandle)
+ LOG_ERROR("ThreadIdentifier %u does not correspond to an active thread", threadID);
+
+ SetThreadPriority(threadHandle, THREAD_PRIORITY_NORMAL + delta);
+}
+
int waitForThreadCompletion(ThreadIdentifier threadID)
{
ASSERT(threadID);
@@ -296,6 +285,7 @@ void Mutex::lock()
++m_mutex.m_recursionCount;
}
+#pragma warning(suppress: 26115)
bool Mutex::tryLock()
{
// This method is modeled after the behavior of pthread_mutex_trylock,