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

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