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

Side by Side Diff: base/synchronization/condition_variable_win.cc

Issue 10151009: Disallow UI/IO thread blocking on any other thread. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 8 months 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/synchronization/condition_variable.h" 5 #include "base/synchronization/condition_variable.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 #include <stack> 8 #include <stack>
9 9
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/synchronization/lock.h" 12 #include "base/synchronization/lock.h"
13 #include "base/threading/thread_restrictions.h"
13 #include "base/time.h" 14 #include "base/time.h"
14 15
15 namespace { 16 namespace {
16 // We can't use the linker supported delay-load for kernel32 so all this 17 // We can't use the linker supported delay-load for kernel32 so all this
17 // cruft here is to manually late-bind the needed functions. 18 // cruft here is to manually late-bind the needed functions.
18 typedef void (WINAPI *InitializeConditionVariableFn)(PCONDITION_VARIABLE); 19 typedef void (WINAPI *InitializeConditionVariableFn)(PCONDITION_VARIABLE);
19 typedef BOOL (WINAPI *SleepConditionVariableCSFn)(PCONDITION_VARIABLE, 20 typedef BOOL (WINAPI *SleepConditionVariableCSFn)(PCONDITION_VARIABLE,
20 PCRITICAL_SECTION, DWORD); 21 PCRITICAL_SECTION, DWORD);
21 typedef void (WINAPI *WakeConditionVariableFn)(PCONDITION_VARIABLE); 22 typedef void (WINAPI *WakeConditionVariableFn)(PCONDITION_VARIABLE);
22 typedef void (WINAPI *WakeAllConditionVariableFn)(PCONDITION_VARIABLE); 23 typedef void (WINAPI *WakeAllConditionVariableFn)(PCONDITION_VARIABLE);
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 : user_lock_(*user_lock) { 88 : user_lock_(*user_lock) {
88 initialize_condition_variable_fn(&cv_); 89 initialize_condition_variable_fn(&cv_);
89 DCHECK(user_lock); 90 DCHECK(user_lock);
90 } 91 }
91 92
92 void WinVistaCondVar::Wait() { 93 void WinVistaCondVar::Wait() {
93 TimedWait(TimeDelta::FromMilliseconds(INFINITE)); 94 TimedWait(TimeDelta::FromMilliseconds(INFINITE));
94 } 95 }
95 96
96 void WinVistaCondVar::TimedWait(const TimeDelta& max_time) { 97 void WinVistaCondVar::TimedWait(const TimeDelta& max_time) {
98 base::ThreadRestrictions::AssertWaitAllowed();
97 DWORD timeout = static_cast<DWORD>(max_time.InMilliseconds()); 99 DWORD timeout = static_cast<DWORD>(max_time.InMilliseconds());
98 CRITICAL_SECTION* cs = user_lock_.lock_.os_lock(); 100 CRITICAL_SECTION* cs = user_lock_.lock_.os_lock();
99 101
100 #if !defined(NDEBUG) 102 #if !defined(NDEBUG)
101 user_lock_.CheckHeldAndUnmark(); 103 user_lock_.CheckHeldAndUnmark();
102 #endif 104 #endif
103 105
104 if (FALSE == sleep_condition_variable_fn(&cv_, cs, timeout)) { 106 if (FALSE == sleep_condition_variable_fn(&cv_, cs, timeout)) {
105 DCHECK(GetLastError() != WAIT_TIMEOUT); 107 DCHECK(GetLastError() != WAIT_TIMEOUT);
106 } 108 }
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 DCHECK_EQ(recycling_list_size_, allocation_counter_); 235 DCHECK_EQ(recycling_list_size_, allocation_counter_);
234 } 236 }
235 237
236 void WinXPCondVar::Wait() { 238 void WinXPCondVar::Wait() {
237 // Default to "wait forever" timing, which means have to get a Signal() 239 // Default to "wait forever" timing, which means have to get a Signal()
238 // or Broadcast() to come out of this wait state. 240 // or Broadcast() to come out of this wait state.
239 TimedWait(TimeDelta::FromMilliseconds(INFINITE)); 241 TimedWait(TimeDelta::FromMilliseconds(INFINITE));
240 } 242 }
241 243
242 void WinXPCondVar::TimedWait(const TimeDelta& max_time) { 244 void WinXPCondVar::TimedWait(const TimeDelta& max_time) {
245 base::ThreadRestrictions::AssertWaitAllowed();
243 Event* waiting_event; 246 Event* waiting_event;
244 HANDLE handle; 247 HANDLE handle;
245 { 248 {
246 AutoLock auto_lock(internal_lock_); 249 AutoLock auto_lock(internal_lock_);
247 if (RUNNING != run_state_) return; // Destruction in progress. 250 if (RUNNING != run_state_) return; // Destruction in progress.
248 waiting_event = GetEventForWaiting(); 251 waiting_event = GetEventForWaiting();
249 handle = waiting_event->handle(); 252 handle = waiting_event->handle();
250 DCHECK(handle); 253 DCHECK(handle);
251 } // Release internal_lock. 254 } // Release internal_lock.
252 255
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after
657 660
658 void ConditionVariable::Broadcast() { 661 void ConditionVariable::Broadcast() {
659 impl_->Broadcast(); 662 impl_->Broadcast();
660 } 663 }
661 664
662 void ConditionVariable::Signal() { 665 void ConditionVariable::Signal() {
663 impl_->Signal(); 666 impl_->Signal();
664 } 667 }
665 668
666 } // namespace base 669 } // namespace base
OLDNEW
« no previous file with comments | « base/synchronization/condition_variable_posix.cc ('k') | base/synchronization/waitable_event_posix.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698