From 4bc9e808de5d010814ecab4bae5c94f610789145 Mon Sep 17 00:00:00 2001 From: "deanm@chromium.org" Date: Tue, 4 Nov 2008 07:59:37 +0000 Subject: Use CreateThread instead of _beginthreadex. This should still be safe, and we'll see if it makes a noticable impact on startup time. Review URL: http://codereview.chromium.org/9059 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@4580 0039d316-1c4b-4281-b951-d872f2087c98 --- base/platform_thread_win.cc | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'base') diff --git a/base/platform_thread_win.cc b/base/platform_thread_win.cc index f477ff0..c390e18 100644 --- a/base/platform_thread_win.cc +++ b/base/platform_thread_win.cc @@ -4,8 +4,6 @@ #include "base/platform_thread.h" -#include - #include "base/logging.h" #include "base/win_util.h" @@ -22,7 +20,7 @@ typedef struct tagTHREADNAME_INFO { DWORD dwFlags; // Reserved for future use, must be zero. } THREADNAME_INFO; -unsigned __stdcall ThreadFunc(void* closure) { +DWORD __stdcall ThreadFunc(void* closure) { PlatformThread::Delegate* delegate = static_cast(closure); delegate->ThreadMain(); @@ -76,8 +74,13 @@ bool PlatformThread::Create(size_t stack_size, Delegate* delegate, stack_size = 0; } - *thread_handle = reinterpret_cast(_beginthreadex( - NULL, stack_size, ThreadFunc, delegate, flags, NULL)); + // Using CreateThread here vs _beginthreadex makes thread creation a bit + // faster and doesn't require the loader lock to be available. Our code will + // have to work running on CreateThread() threads anyway, since we run code + // on the Windows thread pool, etc. For some background on the difference: + // http://www.microsoft.com/msj/1099/win32/win321099.aspx + *thread_handle = CreateThread( + NULL, stack_size, ThreadFunc, delegate, flags, NULL); return *thread_handle != NULL; } @@ -92,4 +95,3 @@ void PlatformThread::Join(PlatformThreadHandle thread_handle) { CloseHandle(thread_handle); } - -- cgit v1.1