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

Side by Side Diff: webrtc/rtc_base/criticalsection.h

Issue 3008193002: Revert of Rename thread annotation macros to have RTC prefix for syncrhonization primitives. (Closed)
Patch Set: Created 3 years, 3 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 /* 1 /*
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2004 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 #define CS_DEBUG_CODE(x) x 45 #define CS_DEBUG_CODE(x) x
46 #else // !CS_DEBUG_CHECKS 46 #else // !CS_DEBUG_CHECKS
47 #define CS_DEBUG_CODE(x) 47 #define CS_DEBUG_CODE(x)
48 #endif // !CS_DEBUG_CHECKS 48 #endif // !CS_DEBUG_CHECKS
49 49
50 namespace rtc { 50 namespace rtc {
51 51
52 // Locking methods (Enter, TryEnter, Leave)are const to permit protecting 52 // Locking methods (Enter, TryEnter, Leave)are const to permit protecting
53 // members inside a const context without requiring mutable CriticalSections 53 // members inside a const context without requiring mutable CriticalSections
54 // everywhere. 54 // everywhere.
55 class RTC_LOCKABLE CriticalSection { 55 class LOCKABLE CriticalSection {
56 public: 56 public:
57 CriticalSection(); 57 CriticalSection();
58 ~CriticalSection(); 58 ~CriticalSection();
59 59
60 void Enter() const RTC_EXCLUSIVE_LOCK_FUNCTION(); 60 void Enter() const EXCLUSIVE_LOCK_FUNCTION();
61 bool TryEnter() const RTC_EXCLUSIVE_TRYLOCK_FUNCTION(true); 61 bool TryEnter() const EXCLUSIVE_TRYLOCK_FUNCTION(true);
62 void Leave() const RTC_UNLOCK_FUNCTION(); 62 void Leave() const UNLOCK_FUNCTION();
63 63
64 private: 64 private:
65 // Use only for RTC_DCHECKing. 65 // Use only for RTC_DCHECKing.
66 bool CurrentThreadIsOwner() const; 66 bool CurrentThreadIsOwner() const;
67 67
68 #if defined(WEBRTC_WIN) 68 #if defined(WEBRTC_WIN)
69 mutable CRITICAL_SECTION crit_; 69 mutable CRITICAL_SECTION crit_;
70 #elif defined(WEBRTC_POSIX) 70 #elif defined(WEBRTC_POSIX)
71 # if defined(WEBRTC_MAC) && !USE_NATIVE_MUTEX_ON_MAC 71 # if defined(WEBRTC_MAC) && !USE_NATIVE_MUTEX_ON_MAC
72 // Number of times the lock has been locked + number of threads waiting. 72 // Number of times the lock has been locked + number of threads waiting.
(...skipping 11 matching lines...) Expand all
84 mutable pthread_mutex_t mutex_; 84 mutable pthread_mutex_t mutex_;
85 # endif 85 # endif
86 mutable PlatformThreadRef thread_; // Only used by RTC_DCHECKs. 86 mutable PlatformThreadRef thread_; // Only used by RTC_DCHECKs.
87 mutable int recursion_count_; // Only used by RTC_DCHECKs. 87 mutable int recursion_count_; // Only used by RTC_DCHECKs.
88 #else // !defined(WEBRTC_WIN) && !defined(WEBRTC_POSIX) 88 #else // !defined(WEBRTC_WIN) && !defined(WEBRTC_POSIX)
89 # error Unsupported platform. 89 # error Unsupported platform.
90 #endif 90 #endif
91 }; 91 };
92 92
93 // CritScope, for serializing execution through a scope. 93 // CritScope, for serializing execution through a scope.
94 class RTC_SCOPED_LOCKABLE CritScope { 94 class SCOPED_LOCKABLE CritScope {
95 public: 95 public:
96 explicit CritScope(const CriticalSection* cs) RTC_EXCLUSIVE_LOCK_FUNCTION(cs); 96 explicit CritScope(const CriticalSection* cs) EXCLUSIVE_LOCK_FUNCTION(cs);
97 ~CritScope() RTC_UNLOCK_FUNCTION(); 97 ~CritScope() UNLOCK_FUNCTION();
98
99 private: 98 private:
100 const CriticalSection* const cs_; 99 const CriticalSection* const cs_;
101 RTC_DISALLOW_COPY_AND_ASSIGN(CritScope); 100 RTC_DISALLOW_COPY_AND_ASSIGN(CritScope);
102 }; 101 };
103 102
104 // Tries to lock a critical section on construction via 103 // Tries to lock a critical section on construction via
105 // CriticalSection::TryEnter, and unlocks on destruction if the 104 // CriticalSection::TryEnter, and unlocks on destruction if the
106 // lock was taken. Never blocks. 105 // lock was taken. Never blocks.
107 // 106 //
108 // IMPORTANT: Unlike CritScope, the lock may not be owned by this thread in 107 // IMPORTANT: Unlike CritScope, the lock may not be owned by this thread in
(...skipping 12 matching lines...) Expand all
121 #endif 120 #endif
122 private: 121 private:
123 const CriticalSection* const cs_; 122 const CriticalSection* const cs_;
124 const bool locked_; 123 const bool locked_;
125 mutable bool lock_was_called_; // Only used by RTC_DCHECKs. 124 mutable bool lock_was_called_; // Only used by RTC_DCHECKs.
126 RTC_DISALLOW_COPY_AND_ASSIGN(TryCritScope); 125 RTC_DISALLOW_COPY_AND_ASSIGN(TryCritScope);
127 }; 126 };
128 127
129 // A POD lock used to protect global variables. Do NOT use for other purposes. 128 // A POD lock used to protect global variables. Do NOT use for other purposes.
130 // No custom constructor or private data member should be added. 129 // No custom constructor or private data member should be added.
131 class RTC_LOCKABLE GlobalLockPod { 130 class LOCKABLE GlobalLockPod {
132 public: 131 public:
133 void Lock() RTC_EXCLUSIVE_LOCK_FUNCTION(); 132 void Lock() EXCLUSIVE_LOCK_FUNCTION();
134 133
135 void Unlock() RTC_UNLOCK_FUNCTION(); 134 void Unlock() UNLOCK_FUNCTION();
136 135
137 volatile int lock_acquired; 136 volatile int lock_acquired;
138 }; 137 };
139 138
140 class GlobalLock : public GlobalLockPod { 139 class GlobalLock : public GlobalLockPod {
141 public: 140 public:
142 GlobalLock(); 141 GlobalLock();
143 }; 142 };
144 143
145 // GlobalLockScope, for serializing execution through a scope. 144 // GlobalLockScope, for serializing execution through a scope.
146 class RTC_SCOPED_LOCKABLE GlobalLockScope { 145 class SCOPED_LOCKABLE GlobalLockScope {
147 public: 146 public:
148 explicit GlobalLockScope(GlobalLockPod* lock) 147 explicit GlobalLockScope(GlobalLockPod* lock) EXCLUSIVE_LOCK_FUNCTION(lock);
149 RTC_EXCLUSIVE_LOCK_FUNCTION(lock); 148 ~GlobalLockScope() UNLOCK_FUNCTION();
150 ~GlobalLockScope() RTC_UNLOCK_FUNCTION();
151
152 private: 149 private:
153 GlobalLockPod* const lock_; 150 GlobalLockPod* const lock_;
154 RTC_DISALLOW_COPY_AND_ASSIGN(GlobalLockScope); 151 RTC_DISALLOW_COPY_AND_ASSIGN(GlobalLockScope);
155 }; 152 };
156 153
157 } // namespace rtc 154 } // namespace rtc
158 155
159 #endif // WEBRTC_RTC_BASE_CRITICALSECTION_H_ 156 #endif // WEBRTC_RTC_BASE_CRITICALSECTION_H_
OLDNEW
« no previous file with comments | « webrtc/modules/audio_device/linux/audio_device_pulse_linux.h ('k') | webrtc/rtc_base/criticalsection.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698