diff options
| author | Konstantin Tokarev <annulen@yandex.ru> | 2016-08-25 19:20:41 +0300 |
|---|---|---|
| committer | Konstantin Tokarev <annulen@yandex.ru> | 2017-02-02 12:30:55 +0000 |
| commit | 6882a04fb36642862b11efe514251d32070c3d65 (patch) | |
| tree | b7959826000b061fd5ccc7512035c7478742f7b0 /Source/WTF/wtf/ThreadingWin.cpp | |
| parent | ab6df191029eeeb0b0f16f127d553265659f739e (diff) | |
Imported QtWebKit TP3 (git b57bc6801f1876c3220d5a4bfea33d620d477443)
Change-Id: I3b1d8a2808782c9f34d50240000e20cb38d3680f
Reviewed-by: Konstantin Tokarev <annulen@yandex.ru>
Diffstat (limited to 'Source/WTF/wtf/ThreadingWin.cpp')
| -rw-r--r-- | Source/WTF/wtf/ThreadingWin.cpp | 65 |
1 files changed, 24 insertions, 41 deletions
diff --git a/Source/WTF/wtf/ThreadingWin.cpp b/Source/WTF/wtf/ThreadingWin.cpp index 49ecc1ae7..280a6d87a 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,12 +94,11 @@ #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/RandomNumberSeed.h> #include <wtf/WTFThreadData.h> @@ -107,10 +106,6 @@ #include "ThreadSpecific.h" #endif -#if !OS(WINCE) -#include <process.h> -#endif - #if HAVE(ERRNO_H) #include <errno.h> #endif @@ -148,19 +143,6 @@ void initializeCurrentThreadInternal(const char* szThreadName) #endif } -static Mutex* atomicallyInitializedStaticMutex; - -void lockAtomicallyInitializedStaticMutex() -{ - ASSERT(atomicallyInitializedStaticMutex); - atomicallyInitializedStaticMutex->lock(); -} - -void unlockAtomicallyInitializedStaticMutex() -{ - atomicallyInitializedStaticMutex->unlock(); -} - static Mutex& threadMapMutex() { static Mutex mutex; @@ -169,18 +151,20 @@ static Mutex& threadMapMutex() void initializeThreading() { - if (atomicallyInitializedStaticMutex) + static bool isInitialized; + + if (isInitialized) return; + isInitialized = true; + WTF::double_conversion::initialize(); // StringImpl::empty() does not construct its static string in a threadsafe fashion, // so ensure it has been initialized from here. StringImpl::empty(); - atomicallyInitializedStaticMutex = new Mutex; threadMapMutex(); initializeRandomNumberGenerator(); wtfThreadData(); - s_dtoaP5Mutex = new Mutex; initializeDates(); } @@ -212,7 +196,7 @@ 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) @@ -227,18 +211,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); @@ -247,7 +223,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); @@ -256,6 +232,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); @@ -284,11 +271,6 @@ void detachThread(ThreadIdentifier threadID) clearThreadHandleForIdentifier(threadID); } -void yield() -{ - ::Sleep(1); -} - ThreadIdentifier currentThread() { return static_cast<ThreadIdentifier>(GetCurrentThreadId()); @@ -311,6 +293,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, |
