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

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

Issue 2047433004: content: Add heartbeat trace for CategorizedWorkerPool. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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
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 "base/synchronization/lock.h" 7 #include "base/synchronization/lock.h"
8 #include "base/threading/thread_restrictions.h" 8 #include "base/threading/thread_restrictions.h"
9 #include "base/time/time.h" 9 #include "base/time/time.h"
10 10
11 namespace base { 11 namespace base {
12 12
13 ConditionVariable::ConditionVariable(Lock* user_lock) 13 ConditionVariable::ConditionVariable(Lock* user_lock)
14 : srwlock_(user_lock->lock_.native_handle()) 14 : srwlock_(user_lock->lock_.native_handle())
15 #if DCHECK_IS_ON() 15 #if DCHECK_IS_ON()
16 , user_lock_(user_lock) 16 , user_lock_(user_lock)
17 #endif 17 #endif
18 { 18 {
19 DCHECK(user_lock); 19 DCHECK(user_lock);
20 InitializeConditionVariable(&cv_); 20 InitializeConditionVariable(&cv_);
21 } 21 }
22 22
23 ConditionVariable::~ConditionVariable() = default; 23 ConditionVariable::~ConditionVariable() = default;
24 24
25 void ConditionVariable::Wait() { 25 void ConditionVariable::Wait() {
26 TimedWait(TimeDelta::FromMilliseconds(INFINITE)); 26 TimedWait(TimeDelta::FromMilliseconds(INFINITE));
27 } 27 }
28 28
29 void ConditionVariable::TimedWait(const TimeDelta& max_time) { 29 bool ConditionVariable::TimedWait(const TimeDelta& max_time) {
30 base::ThreadRestrictions::AssertWaitAllowed(); 30 base::ThreadRestrictions::AssertWaitAllowed();
31 bool timed_out = false;
robliao 2016/06/07 15:40:30 Minimal scope: Move to right before the if check b
31 DWORD timeout = static_cast<DWORD>(max_time.InMilliseconds()); 32 DWORD timeout = static_cast<DWORD>(max_time.InMilliseconds());
32 33
33 #if DCHECK_IS_ON() 34 #if DCHECK_IS_ON()
34 user_lock_->CheckHeldAndUnmark(); 35 user_lock_->CheckHeldAndUnmark();
35 #endif 36 #endif
36 37
37 if (FALSE == SleepConditionVariableSRW(&cv_, srwlock_, timeout, 0)) { 38 if (FALSE == SleepConditionVariableSRW(&cv_, srwlock_, timeout, 0)) {
38 DCHECK(GetLastError() != WAIT_TIMEOUT); 39 timed_out = GetLastError() == WAIT_TIMEOUT;
robliao 2016/06/07 15:40:30 Looks like your changelist uncovered a longstandin
prashant.n 2016/06/07 15:49:54 I just copied earlier code, I'll make chnages sugg
40 DCHECK(max_time != TimeDelta::FromMilliseconds(INFINITE) || !timed_out);
robliao 2016/06/07 15:40:30 This DCHECK will pass all cases where max_time is
prashant.n 2016/06/07 15:49:54 I'll correct this. May be I'll add two explicit dc
39 } 41 }
40 42
41 #if DCHECK_IS_ON() 43 #if DCHECK_IS_ON()
42 user_lock_->CheckUnheldAndMark(); 44 user_lock_->CheckUnheldAndMark();
43 #endif 45 #endif
46
47 return timed_out;
44 } 48 }
45 49
46 void ConditionVariable::Broadcast() { 50 void ConditionVariable::Broadcast() {
47 WakeAllConditionVariable(&cv_); 51 WakeAllConditionVariable(&cv_);
48 } 52 }
49 53
50 void ConditionVariable::Signal() { 54 void ConditionVariable::Signal() {
51 WakeConditionVariable(&cv_); 55 WakeConditionVariable(&cv_);
52 } 56 }
53 57
54 } // namespace base 58 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698