OLD | NEW |
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 Loading... |
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 10 matching lines...) Expand all Loading... |
52 | 59 |
53 // Use only for RTC_DCHECKing. | 60 // Use only for RTC_DCHECKing. |
54 bool CurrentThreadIsOwner() const; | 61 bool CurrentThreadIsOwner() const; |
55 // Use only for RTC_DCHECKing. | 62 // Use only for RTC_DCHECKing. |
56 bool IsLocked() const; | 63 bool IsLocked() const; |
57 | 64 |
58 private: | 65 private: |
59 #if defined(WEBRTC_WIN) | 66 #if defined(WEBRTC_WIN) |
60 CRITICAL_SECTION crit_; | 67 CRITICAL_SECTION crit_; |
61 #elif defined(WEBRTC_POSIX) | 68 #elif defined(WEBRTC_POSIX) |
| 69 #if defined(WEBRTC_MAC) && !USE_NATIVE_MUTEX_ON_MAC |
| 70 // Number of times the lock has been locked + number of threads waiting. |
| 71 // TODO(tommi): We could use this number and subtract the recursion count |
| 72 // to find places where we have multiple threads contending on the same lock. |
| 73 volatile int lock_queue_; |
| 74 // |recursion_| represents the recursion count + 1 for the thread that owns |
| 75 // the lock. Only modified by the thread that owns the lock. |
| 76 int recursion_; |
| 77 // Used to signal a single waiting thread when the lock becomes available. |
| 78 dispatch_semaphore_t semaphore_; |
| 79 // The thread that currently holds the lock. Required to handle recursion. |
| 80 pthread_t owning_thread_; |
| 81 #else |
62 pthread_mutex_t mutex_; | 82 pthread_mutex_t mutex_; |
| 83 #endif |
63 CS_DEBUG_CODE(pthread_t thread_); | 84 CS_DEBUG_CODE(pthread_t thread_); |
64 CS_DEBUG_CODE(int recursion_count_); | 85 CS_DEBUG_CODE(int recursion_count_); |
65 #endif | 86 #endif |
66 }; | 87 }; |
67 | 88 |
68 // CritScope, for serializing execution through a scope. | 89 // CritScope, for serializing execution through a scope. |
69 class SCOPED_LOCKABLE CritScope { | 90 class SCOPED_LOCKABLE CritScope { |
70 public: | 91 public: |
71 explicit CritScope(CriticalSection* cs) EXCLUSIVE_LOCK_FUNCTION(cs); | 92 explicit CritScope(CriticalSection* cs) EXCLUSIVE_LOCK_FUNCTION(cs); |
72 ~CritScope() UNLOCK_FUNCTION(); | 93 ~CritScope() UNLOCK_FUNCTION(); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 explicit GlobalLockScope(GlobalLockPod* lock) EXCLUSIVE_LOCK_FUNCTION(lock); | 141 explicit GlobalLockScope(GlobalLockPod* lock) EXCLUSIVE_LOCK_FUNCTION(lock); |
121 ~GlobalLockScope() UNLOCK_FUNCTION(); | 142 ~GlobalLockScope() UNLOCK_FUNCTION(); |
122 private: | 143 private: |
123 GlobalLockPod* const lock_; | 144 GlobalLockPod* const lock_; |
124 RTC_DISALLOW_COPY_AND_ASSIGN(GlobalLockScope); | 145 RTC_DISALLOW_COPY_AND_ASSIGN(GlobalLockScope); |
125 }; | 146 }; |
126 | 147 |
127 } // namespace rtc | 148 } // namespace rtc |
128 | 149 |
129 #endif // WEBRTC_BASE_CRITICALSECTION_H_ | 150 #endif // WEBRTC_BASE_CRITICALSECTION_H_ |
OLD | NEW |