Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(347)

Unified Diff: base/platform_thread_win.cc

Issue 5206005: Revert 66719 - Reland r65996. Disallows Singletons on non-joinable thread.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 10 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/platform_thread_posix.cc ('k') | base/singleton.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/platform_thread_win.cc
===================================================================
--- base/platform_thread_win.cc (revision 66790)
+++ base/platform_thread_win.cc (working copy)
@@ -5,7 +5,6 @@
#include "base/platform_thread.h"
#include "base/logging.h"
-#include "base/thread_restrictions.h"
#include "base/win/windows_version.h"
namespace {
@@ -21,58 +20,13 @@
DWORD dwFlags; // Reserved for future use, must be zero.
} THREADNAME_INFO;
-struct ThreadParams {
- PlatformThread::Delegate* delegate;
- bool joinable;
-};
-
-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;
+DWORD __stdcall ThreadFunc(void* closure) {
+ PlatformThread::Delegate* delegate =
+ static_cast<PlatformThread::Delegate*>(closure);
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;
-}
-
} // namespace
// static
@@ -113,13 +67,29 @@
// static
bool PlatformThread::Create(size_t stack_size, Delegate* delegate,
PlatformThreadHandle* thread_handle) {
- DCHECK(thread_handle);
- return CreateThreadInternal(stack_size, delegate, 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;
+ }
+
+ // 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;
}
// static
bool PlatformThread::CreateNonJoinable(size_t stack_size, Delegate* delegate) {
- return CreateThreadInternal(stack_size, delegate, NULL);
+ PlatformThreadHandle thread_handle;
+ bool result = Create(stack_size, delegate, &thread_handle);
+ CloseHandle(thread_handle);
+ return result;
}
// static
« no previous file with comments | « base/platform_thread_posix.cc ('k') | base/singleton.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698