From 5080e18216a41a978c42c2bacf4e16ad15ca84e4 Mon Sep 17 00:00:00 2001 From: "deanm@chromium.org" Date: Tue, 4 Nov 2008 08:33:49 +0000 Subject: Use the worker pool instead of a one-time thread for the breakpad initialization. This allows the thread to be reused later. Review URL: http://codereview.chromium.org/9276 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@4585 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/app/breakpad.cc | 16 ++++++++-------- chrome/app/breakpad.h | 3 --- 2 files changed, 8 insertions(+), 11 deletions(-) (limited to 'chrome') diff --git a/chrome/app/breakpad.cc b/chrome/app/breakpad.cc index 34607a4..773a2da 100644 --- a/chrome/app/breakpad.cc +++ b/chrome/app/breakpad.cc @@ -5,7 +5,6 @@ #include "chrome/app/breakpad.h" #include -#include #include #include "base/base_switches.h" @@ -153,7 +152,7 @@ bool ShowRestartDialogIfCrashed(bool* exit_now) { return true; } -unsigned __stdcall InitCrashReporterThread(void* param) { +static DWORD __stdcall InitCrashReporterThread(void* param) { CrashReporterInfo* info = reinterpret_cast(param); CommandLine command; @@ -242,15 +241,16 @@ void InitCrashReporter(std::wstring dll_path) { // If this is not the browser, we can't be sure that we will be able to // initialize the crash_handler in another thread, so we run it right away. // This is important to keep the thread for the browser process because - // it may take some times to initialize the crash_service process. + // it may take some times to initialize the crash_service process. We use + // the Windows worker pool to make better reuse of the thread. if (info->process_type != L"browser") { InitCrashReporterThread(info); } else { - uintptr_t thread = _beginthreadex(NULL, 0, &InitCrashReporterThread, - info, 0, NULL); - HANDLE thread_handle = reinterpret_cast(thread); - if (thread_handle != INVALID_HANDLE_VALUE) - ::CloseHandle(thread_handle); + if (QueueUserWorkItem( + &InitCrashReporterThread, info, WT_EXECUTELONGFUNCTION) == 0) { + // We failed to queue to the worker pool, initialize in this thread. + InitCrashReporterThread(info); + } } } } diff --git a/chrome/app/breakpad.h b/chrome/app/breakpad.h index af8fe46..8250b4b 100644 --- a/chrome/app/breakpad.h +++ b/chrome/app/breakpad.h @@ -16,9 +16,6 @@ void InitCrashReporter(std::wstring dll_path); // the browser or not. void InitDefaultCrashCallback(); -// Initializes the crash reporter in chrome. -unsigned __stdcall InitCrashReporterThread(void* param); - // If chrome has been restarted because it crashed, this function will display // a dialog asking for permission to continue execution or to exit now. bool ShowRestartDialogIfCrashed(bool* exit_now); -- cgit v1.1