Created
December 30, 2011 13:21
-
-
Save huangdongxu/1539826 to your computer and use it in GitHub Desktop.
chromuim thread1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DWORD __stdcall ThreadFunc(void* params) { | |
ThreadParams* thread_params = static_cast<ThreadParams*>(params); | |
PlatformThread::Delegate* delegate = thread_params->delegate; | |
if (!thread_params->joinable) | |
base::ThreadRestrictions::SetSingletonAllowed(false); | |
delete thread_params; | |
delegate->ThreadMain(); | |
return NULL; | |
} | |
// CreateThreadInternal() matches PlatformThread::Create(), 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 thread_handle; | |
unsigned int flags = 0; | |
if (stack_size > 0 && base::win::GetVersion() >= base::win::VERSION_XP) { | |
flags = STACK_SIZE_PARAM_IS_A_RESERVATION; | |
} else { | |
stack_size = 0; | |
} | |
ThreadParams* params = new ThreadParams; | |
params->delegate = delegate; | |
params->joinable = out_thread_handle != 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, params, flags, NULL); | |
if (!thread_handle) { | |
delete params; | |
return false; | |
} | |
if (out_thread_handle) | |
*out_thread_handle = thread_handle; | |
else | |
CloseHandle(thread_handle); | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment