From c50346b3413cd4f5eede6730dd74f950e9968169 Mon Sep 17 00:00:00 2001 From: "mark@chromium.org" Date: Tue, 12 Jun 2012 21:06:11 +0000 Subject: CrashGenerationServer's state machine can be invoked from both the application thread and thread pool threads. This CL serializes access to the FSM state. Handling of crash dump and client shutdown requests is still done asynchronously. Patch by Alex Pakhunov BUG=132164 TEST=remoting_unittests.BreakpadWinDeathTest.* Review URL: https://breakpad.appspot.com/396002/ git-svn-id: http://google-breakpad.googlecode.com/svn/trunk@970 4c0a9323-5329-0410-9bdc-e9ce6186880e --- src/client/windows/common/auto_critical_section.h | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'src/client/windows/common') diff --git a/src/client/windows/common/auto_critical_section.h b/src/client/windows/common/auto_critical_section.h index 82c7b7f1..a2076b04 100644 --- a/src/client/windows/common/auto_critical_section.h +++ b/src/client/windows/common/auto_critical_section.h @@ -40,14 +40,31 @@ class AutoCriticalSection { public: // Creates a new instance with the given critical section object // and enters the critical section immediately. - explicit AutoCriticalSection(CRITICAL_SECTION* cs) : cs_(cs) { + explicit AutoCriticalSection(CRITICAL_SECTION* cs) : cs_(cs), taken_(false) { assert(cs_); - EnterCriticalSection(cs_); + Acquire(); } // Destructor: leaves the critical section. ~AutoCriticalSection() { + if (taken_) { + Release(); + } + } + + // Enters the critical section. Recursive Acquire() calls are not allowed. + void Acquire() { + assert(!taken_); + EnterCriticalSection(cs_); + taken_ = true; + } + + // Leaves the critical section. The caller should not call Release() unless + // the critical seciton has been entered already. + void Release() { + assert(taken_); LeaveCriticalSection(cs_); + taken_ = false; } private: @@ -56,6 +73,7 @@ class AutoCriticalSection { AutoCriticalSection& operator=(const AutoCriticalSection&); CRITICAL_SECTION* cs_; + bool taken_; }; } // namespace google_breakpad -- cgit v1.2.1