summaryrefslogtreecommitdiffstats
path: root/base/threading
diff options
context:
space:
mode:
authortoyoshim <toyoshim@chromium.org>2015-06-24 19:34:09 -0700
committerCommit bot <commit-bot@chromium.org>2015-06-25 02:34:37 +0000
commit0da84eb2bdb24a044412e5ba6e1f605d4cdbbe71 (patch)
treea449a3bb3e0f8a7d230c0a094242fccff7035930 /base/threading
parentebf7b741408ed2054405d39e049e3ce5a1ab3d18 (diff)
downloadchromium_src-0da84eb2bdb24a044412e5ba6e1f605d4cdbbe71.zip
chromium_src-0da84eb2bdb24a044412e5ba6e1f605d4cdbbe71.tar.gz
chromium_src-0da84eb2bdb24a044412e5ba6e1f605d4cdbbe71.tar.bz2
Apply the initial thread priority on the starting thread on Windows
To remove a dependency to the thread handle on setting the initial thread priority, change the logic to apply the initial thread priority on the starting thread. BUG=468793 Review URL: https://codereview.chromium.org/1199313004 Cr-Commit-Position: refs/heads/master@{#336076}
Diffstat (limited to 'base/threading')
-rw-r--r--base/threading/platform_thread_win.cc27
1 files changed, 17 insertions, 10 deletions
diff --git a/base/threading/platform_thread_win.cc b/base/threading/platform_thread_win.cc
index 395fc9e..c2eab6c 100644
--- a/base/threading/platform_thread_win.cc
+++ b/base/threading/platform_thread_win.cc
@@ -46,6 +46,7 @@ void SetNameInternal(PlatformThreadId thread_id, const char* name) {
struct ThreadParams {
PlatformThread::Delegate* delegate;
bool joinable;
+ ThreadPriority priority;
};
DWORD __stdcall ThreadFunc(void* params) {
@@ -54,6 +55,11 @@ DWORD __stdcall ThreadFunc(void* params) {
if (!thread_params->joinable)
base::ThreadRestrictions::SetSingletonAllowed(false);
+ if (thread_params->priority != ThreadPriority::NORMAL) {
+ PlatformThread::SetThreadPriority(
+ PlatformThread::CurrentHandle(), thread_params->priority);
+ }
+
// Retrieve a copy of the thread handle to use as the key in the
// thread name mapping.
PlatformThreadHandle::Handle platform_handle;
@@ -86,12 +92,13 @@ DWORD __stdcall ThreadFunc(void* params) {
return NULL;
}
-// CreateThreadInternal() matches PlatformThread::Create(), except that
-// |out_thread_handle| may be NULL, in which case a non-joinable thread is
+// CreateThreadInternal() matches PlatformThread::CreateWithPriority(), except
+// that |out_thread_handle| may be NULL, in which case a non-joinable thread is
// created.
bool CreateThreadInternal(size_t stack_size,
PlatformThread::Delegate* delegate,
- PlatformThreadHandle* out_thread_handle) {
+ PlatformThreadHandle* out_thread_handle,
+ ThreadPriority priority) {
unsigned int flags = 0;
if (stack_size > 0 && base::win::GetVersion() >= base::win::VERSION_XP) {
flags = STACK_SIZE_PARAM_IS_A_RESERVATION;
@@ -102,6 +109,7 @@ bool CreateThreadInternal(size_t stack_size,
ThreadParams* params = new ThreadParams;
params->delegate = delegate;
params->joinable = out_thread_handle != NULL;
+ params->priority = priority;
// Using CreateThread here vs _beginthreadex makes thread creation a bit
// faster and doesn't require the loader lock to be available. Our code will
@@ -185,23 +193,22 @@ const char* PlatformThread::GetName() {
// static
bool PlatformThread::Create(size_t stack_size, Delegate* delegate,
PlatformThreadHandle* thread_handle) {
- DCHECK(thread_handle);
- return CreateThreadInternal(stack_size, delegate, thread_handle);
+ return CreateWithPriority(
+ stack_size, delegate, thread_handle, ThreadPriority::NORMAL);
}
// static
bool PlatformThread::CreateWithPriority(size_t stack_size, Delegate* delegate,
PlatformThreadHandle* thread_handle,
ThreadPriority priority) {
- bool result = Create(stack_size, delegate, thread_handle);
- if (result)
- SetThreadPriority(*thread_handle, priority);
- return result;
+ DCHECK(thread_handle);
+ return CreateThreadInternal(stack_size, delegate, thread_handle, priority);
}
// static
bool PlatformThread::CreateNonJoinable(size_t stack_size, Delegate* delegate) {
- return CreateThreadInternal(stack_size, delegate, NULL);
+ return CreateThreadInternal(
+ stack_size, delegate, NULL, ThreadPriority::NORMAL);
}
// static