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

Side by Side Diff: webrtc/base/criticalsection.cc

Issue 1611223002: Make rtc::CriticalSection lockable from f() const. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: comment Created 4 years, 11 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
« no previous file with comments | « webrtc/base/criticalsection.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2015 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2015 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 18 matching lines...) Expand all
29 } 29 }
30 30
31 CriticalSection::~CriticalSection() { 31 CriticalSection::~CriticalSection() {
32 #if defined(WEBRTC_WIN) 32 #if defined(WEBRTC_WIN)
33 DeleteCriticalSection(&crit_); 33 DeleteCriticalSection(&crit_);
34 #else 34 #else
35 pthread_mutex_destroy(&mutex_); 35 pthread_mutex_destroy(&mutex_);
36 #endif 36 #endif
37 } 37 }
38 38
39 void CriticalSection::Enter() EXCLUSIVE_LOCK_FUNCTION() { 39 void CriticalSection::Enter() const EXCLUSIVE_LOCK_FUNCTION() {
40 #if defined(WEBRTC_WIN) 40 #if defined(WEBRTC_WIN)
41 EnterCriticalSection(&crit_); 41 EnterCriticalSection(&crit_);
42 #else 42 #else
43 pthread_mutex_lock(&mutex_); 43 pthread_mutex_lock(&mutex_);
44 #if CS_DEBUG_CHECKS 44 #if CS_DEBUG_CHECKS
45 if (!recursion_count_) { 45 if (!recursion_count_) {
46 RTC_DCHECK(!thread_); 46 RTC_DCHECK(!thread_);
47 thread_ = pthread_self(); 47 thread_ = pthread_self();
48 } else { 48 } else {
49 RTC_DCHECK(CurrentThreadIsOwner()); 49 RTC_DCHECK(CurrentThreadIsOwner());
50 } 50 }
51 ++recursion_count_; 51 ++recursion_count_;
52 #endif 52 #endif
53 #endif 53 #endif
54 } 54 }
55 55
56 bool CriticalSection::TryEnter() EXCLUSIVE_TRYLOCK_FUNCTION(true) { 56 bool CriticalSection::TryEnter() const EXCLUSIVE_TRYLOCK_FUNCTION(true) {
57 #if defined(WEBRTC_WIN) 57 #if defined(WEBRTC_WIN)
58 return TryEnterCriticalSection(&crit_) != FALSE; 58 return TryEnterCriticalSection(&crit_) != FALSE;
59 #else 59 #else
60 if (pthread_mutex_trylock(&mutex_) != 0) 60 if (pthread_mutex_trylock(&mutex_) != 0)
61 return false; 61 return false;
62 #if CS_DEBUG_CHECKS 62 #if CS_DEBUG_CHECKS
63 if (!recursion_count_) { 63 if (!recursion_count_) {
64 RTC_DCHECK(!thread_); 64 RTC_DCHECK(!thread_);
65 thread_ = pthread_self(); 65 thread_ = pthread_self();
66 } else { 66 } else {
67 RTC_DCHECK(CurrentThreadIsOwner()); 67 RTC_DCHECK(CurrentThreadIsOwner());
68 } 68 }
69 ++recursion_count_; 69 ++recursion_count_;
70 #endif 70 #endif
71 return true; 71 return true;
72 #endif 72 #endif
73 } 73 }
74 void CriticalSection::Leave() UNLOCK_FUNCTION() { 74 void CriticalSection::Leave() const UNLOCK_FUNCTION() {
75 RTC_DCHECK(CurrentThreadIsOwner()); 75 RTC_DCHECK(CurrentThreadIsOwner());
76 #if defined(WEBRTC_WIN) 76 #if defined(WEBRTC_WIN)
77 LeaveCriticalSection(&crit_); 77 LeaveCriticalSection(&crit_);
78 #else 78 #else
79 #if CS_DEBUG_CHECKS 79 #if CS_DEBUG_CHECKS
80 --recursion_count_; 80 --recursion_count_;
81 RTC_DCHECK(recursion_count_ >= 0); 81 RTC_DCHECK(recursion_count_ >= 0);
82 if (!recursion_count_) 82 if (!recursion_count_)
83 thread_ = 0; 83 thread_ = 0;
84 #endif 84 #endif
(...skipping 23 matching lines...) Expand all
108 return crit_.LockCount != -1; 108 return crit_.LockCount != -1;
109 #else 109 #else
110 #if CS_DEBUG_CHECKS 110 #if CS_DEBUG_CHECKS
111 return thread_ != 0; 111 return thread_ != 0;
112 #else 112 #else
113 return true; 113 return true;
114 #endif 114 #endif
115 #endif 115 #endif
116 } 116 }
117 117
118 CritScope::CritScope(CriticalSection* cs) : cs_(cs) { cs_->Enter(); } 118 CritScope::CritScope(const CriticalSection* cs) : cs_(cs) { cs_->Enter(); }
119 CritScope::~CritScope() { cs_->Leave(); } 119 CritScope::~CritScope() { cs_->Leave(); }
120 120
121 TryCritScope::TryCritScope(CriticalSection* cs) 121 TryCritScope::TryCritScope(const CriticalSection* cs)
122 : cs_(cs), locked_(cs->TryEnter()) { 122 : cs_(cs), locked_(cs->TryEnter()) {
123 CS_DEBUG_CODE(lock_was_called_ = false); 123 CS_DEBUG_CODE(lock_was_called_ = false);
124 } 124 }
125 125
126 TryCritScope::~TryCritScope() { 126 TryCritScope::~TryCritScope() {
127 CS_DEBUG_CODE(RTC_DCHECK(lock_was_called_)); 127 CS_DEBUG_CODE(RTC_DCHECK(lock_was_called_));
128 if (locked_) 128 if (locked_)
129 cs_->Leave(); 129 cs_->Leave();
130 } 130 }
131 131
(...skipping 28 matching lines...) Expand all
160 GlobalLockScope::GlobalLockScope(GlobalLockPod* lock) 160 GlobalLockScope::GlobalLockScope(GlobalLockPod* lock)
161 : lock_(lock) { 161 : lock_(lock) {
162 lock_->Lock(); 162 lock_->Lock();
163 } 163 }
164 164
165 GlobalLockScope::~GlobalLockScope() { 165 GlobalLockScope::~GlobalLockScope() {
166 lock_->Unlock(); 166 lock_->Unlock();
167 } 167 }
168 168
169 } // namespace rtc 169 } // namespace rtc
OLDNEW
« no previous file with comments | « webrtc/base/criticalsection.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698