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

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

Issue 3004393002: 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 LOCKABLE CriticalSection { 55 class RTC_LOCKABLE CriticalSection {
56 public: 56 public:
57 CriticalSection(); 57 CriticalSection();
58 ~CriticalSection(); 58 ~CriticalSection();
59 59
60 void Enter() const EXCLUSIVE_LOCK_FUNCTION(); 60 void Enter() const RTC_EXCLUSIVE_LOCK_FUNCTION();
61 bool TryEnter() const EXCLUSIVE_TRYLOCK_FUNCTION(true); 61 bool TryEnter() const RTC_EXCLUSIVE_TRYLOCK_FUNCTION(true);
62 void Leave() const UNLOCK_FUNCTION(); 62 void Leave() const RTC_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 SCOPED_LOCKABLE CritScope { 94 class RTC_SCOPED_LOCKABLE CritScope {
95 public: 95 public:
96 explicit CritScope(const CriticalSection* cs) EXCLUSIVE_LOCK_FUNCTION(cs); 96 explicit CritScope(const CriticalSection* cs) RTC_EXCLUSIVE_LOCK_FUNCTION(cs);
97 ~CritScope() UNLOCK_FUNCTION(); 97 ~CritScope() RTC_UNLOCK_FUNCTION();
98
98 private: 99 private:
99 const CriticalSection* const cs_; 100 const CriticalSection* const cs_;
100 RTC_DISALLOW_COPY_AND_ASSIGN(CritScope); 101 RTC_DISALLOW_COPY_AND_ASSIGN(CritScope);
101 }; 102 };
102 103
103 // Tries to lock a critical section on construction via 104 // Tries to lock a critical section on construction via
104 // CriticalSection::TryEnter, and unlocks on destruction if the 105 // CriticalSection::TryEnter, and unlocks on destruction if the
105 // lock was taken. Never blocks. 106 // lock was taken. Never blocks.
106 // 107 //
107 // IMPORTANT: Unlike CritScope, the lock may not be owned by this thread in 108 // IMPORTANT: Unlike CritScope, the lock may not be owned by this thread in
(...skipping 12 matching lines...) Expand all
120 #endif 121 #endif
121 private: 122 private:
122 const CriticalSection* const cs_; 123 const CriticalSection* const cs_;
123 const bool locked_; 124 const bool locked_;
124 mutable bool lock_was_called_; // Only used by RTC_DCHECKs. 125 mutable bool lock_was_called_; // Only used by RTC_DCHECKs.
125 RTC_DISALLOW_COPY_AND_ASSIGN(TryCritScope); 126 RTC_DISALLOW_COPY_AND_ASSIGN(TryCritScope);
126 }; 127 };
127 128
128 // A POD lock used to protect global variables. Do NOT use for other purposes. 129 // A POD lock used to protect global variables. Do NOT use for other purposes.
129 // No custom constructor or private data member should be added. 130 // No custom constructor or private data member should be added.
130 class LOCKABLE GlobalLockPod { 131 class RTC_LOCKABLE GlobalLockPod {
131 public: 132 public:
132 void Lock() EXCLUSIVE_LOCK_FUNCTION(); 133 void Lock() RTC_EXCLUSIVE_LOCK_FUNCTION();
133 134
134 void Unlock() UNLOCK_FUNCTION(); 135 void Unlock() RTC_UNLOCK_FUNCTION();
135 136
136 volatile int lock_acquired; 137 volatile int lock_acquired;
137 }; 138 };
138 139
139 class GlobalLock : public GlobalLockPod { 140 class GlobalLock : public GlobalLockPod {
140 public: 141 public:
141 GlobalLock(); 142 GlobalLock();
142 }; 143 };
143 144
144 // GlobalLockScope, for serializing execution through a scope. 145 // GlobalLockScope, for serializing execution through a scope.
145 class SCOPED_LOCKABLE GlobalLockScope { 146 class RTC_SCOPED_LOCKABLE GlobalLockScope {
146 public: 147 public:
147 explicit GlobalLockScope(GlobalLockPod* lock) EXCLUSIVE_LOCK_FUNCTION(lock); 148 explicit GlobalLockScope(GlobalLockPod* lock)
148 ~GlobalLockScope() UNLOCK_FUNCTION(); 149 RTC_EXCLUSIVE_LOCK_FUNCTION(lock);
150 ~GlobalLockScope() RTC_UNLOCK_FUNCTION();
151
149 private: 152 private:
150 GlobalLockPod* const lock_; 153 GlobalLockPod* const lock_;
151 RTC_DISALLOW_COPY_AND_ASSIGN(GlobalLockScope); 154 RTC_DISALLOW_COPY_AND_ASSIGN(GlobalLockScope);
152 }; 155 };
153 156
154 } // namespace rtc 157 } // namespace rtc
155 158
156 #endif // WEBRTC_RTC_BASE_CRITICALSECTION_H_ 159 #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