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

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

Issue 1594723003: New lock implementation for mac (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Address comments 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 | « no previous file | webrtc/base/criticalsection.cc » ('j') | webrtc/base/criticalsection.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 11 matching lines...) Expand all
22 // exists as two separate projects, webrtc and libjingle. 22 // exists as two separate projects, webrtc and libjingle.
23 #include <winsock2.h> 23 #include <winsock2.h>
24 #include <windows.h> 24 #include <windows.h>
25 #include <sal.h> // must come after windows headers. 25 #include <sal.h> // must come after windows headers.
26 #endif // defined(WEBRTC_WIN) 26 #endif // defined(WEBRTC_WIN)
27 27
28 #if defined(WEBRTC_POSIX) 28 #if defined(WEBRTC_POSIX)
29 #include <pthread.h> 29 #include <pthread.h>
30 #endif 30 #endif
31 31
32 // See notes in the 'Performance' unit test for the effects of this flag.
33 #define USE_NATIVE_MUTEX_ON_MAC 0
34
35 #if defined(WEBRTC_MAC) && !USE_NATIVE_MUTEX_ON_MAC
36 #include <dispatch/dispatch.h>
37 #endif
38
32 #if (!defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)) 39 #if (!defined(NDEBUG) || defined(DCHECK_ALWAYS_ON))
33 #define CS_DEBUG_CHECKS 1 40 #define CS_DEBUG_CHECKS 1
34 #endif 41 #endif
35 42
36 #if CS_DEBUG_CHECKS 43 #if CS_DEBUG_CHECKS
37 #define CS_DEBUG_CODE(x) x 44 #define CS_DEBUG_CODE(x) x
38 #else // !CS_DEBUG_CHECKS 45 #else // !CS_DEBUG_CHECKS
39 #define CS_DEBUG_CODE(x) 46 #define CS_DEBUG_CODE(x)
40 #endif // !CS_DEBUG_CHECKS 47 #endif // !CS_DEBUG_CHECKS
41 48
(...skipping 13 matching lines...) Expand all
55 62
56 // Use only for RTC_DCHECKing. 63 // Use only for RTC_DCHECKing.
57 bool CurrentThreadIsOwner() const; 64 bool CurrentThreadIsOwner() const;
58 // Use only for RTC_DCHECKing. 65 // Use only for RTC_DCHECKing.
59 bool IsLocked() const; 66 bool IsLocked() const;
60 67
61 private: 68 private:
62 #if defined(WEBRTC_WIN) 69 #if defined(WEBRTC_WIN)
63 mutable CRITICAL_SECTION crit_; 70 mutable CRITICAL_SECTION crit_;
64 #elif defined(WEBRTC_POSIX) 71 #elif defined(WEBRTC_POSIX)
72 #if defined(WEBRTC_MAC) && !USE_NATIVE_MUTEX_ON_MAC
73 // Number of times the lock has been locked + number of threads waiting.
74 // TODO(tommi): We could use this number and subtract the recursion count
75 // to find places where we have multiple threads contending on the same lock.
76 mutable volatile int lock_queue_;
77 // |recursion_| represents the recursion count + 1 for the thread that owns
78 // the lock. Only modified by the thread that owns the lock.
79 mutable int recursion_;
80 // Used to signal a single waiting thread when the lock becomes available.
81 mutable dispatch_semaphore_t semaphore_;
82 // The thread that currently holds the lock. Required to handle recursion.
83 mutable pthread_t owning_thread_;
84 #else
65 mutable pthread_mutex_t mutex_; 85 mutable pthread_mutex_t mutex_;
86 #endif
66 CS_DEBUG_CODE(mutable pthread_t thread_); 87 CS_DEBUG_CODE(mutable pthread_t thread_);
67 CS_DEBUG_CODE(mutable int recursion_count_); 88 CS_DEBUG_CODE(mutable int recursion_count_);
68 #endif 89 #endif
69 }; 90 };
70 91
71 // CritScope, for serializing execution through a scope. 92 // CritScope, for serializing execution through a scope.
72 class SCOPED_LOCKABLE CritScope { 93 class SCOPED_LOCKABLE CritScope {
73 public: 94 public:
74 explicit CritScope(const CriticalSection* cs) EXCLUSIVE_LOCK_FUNCTION(cs); 95 explicit CritScope(const CriticalSection* cs) EXCLUSIVE_LOCK_FUNCTION(cs);
75 ~CritScope() UNLOCK_FUNCTION(); 96 ~CritScope() UNLOCK_FUNCTION();
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 explicit GlobalLockScope(GlobalLockPod* lock) EXCLUSIVE_LOCK_FUNCTION(lock); 144 explicit GlobalLockScope(GlobalLockPod* lock) EXCLUSIVE_LOCK_FUNCTION(lock);
124 ~GlobalLockScope() UNLOCK_FUNCTION(); 145 ~GlobalLockScope() UNLOCK_FUNCTION();
125 private: 146 private:
126 GlobalLockPod* const lock_; 147 GlobalLockPod* const lock_;
127 RTC_DISALLOW_COPY_AND_ASSIGN(GlobalLockScope); 148 RTC_DISALLOW_COPY_AND_ASSIGN(GlobalLockScope);
128 }; 149 };
129 150
130 } // namespace rtc 151 } // namespace rtc
131 152
132 #endif // WEBRTC_BASE_CRITICALSECTION_H_ 153 #endif // WEBRTC_BASE_CRITICALSECTION_H_
OLDNEW
« no previous file with comments | « no previous file | webrtc/base/criticalsection.cc » ('j') | webrtc/base/criticalsection.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698