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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | webrtc/base/criticalsection.cc » ('j') | webrtc/base/criticalsection.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/base/criticalsection.h
diff --git a/webrtc/base/criticalsection.h b/webrtc/base/criticalsection.h
index cc54eca1f0d4e7ddbbf9d5d201fdb83575950480..3b45fe4c6ca845565ea6d77c967421b2cb828d72 100644
--- a/webrtc/base/criticalsection.h
+++ b/webrtc/base/criticalsection.h
@@ -29,6 +29,13 @@
#include <pthread.h>
#endif
+// See notes in the 'Performance' unit test for the effects of this flag.
+#define USE_NATIVE_MUTEX_ON_MAC 0
+
+#if defined(WEBRTC_MAC) && !USE_NATIVE_MUTEX_ON_MAC
+#include <dispatch/dispatch.h>
+#endif
+
#if (!defined(NDEBUG) || defined(DCHECK_ALWAYS_ON))
#define CS_DEBUG_CHECKS 1
#endif
@@ -62,7 +69,21 @@ class LOCKABLE CriticalSection {
#if defined(WEBRTC_WIN)
mutable CRITICAL_SECTION crit_;
#elif defined(WEBRTC_POSIX)
+#if defined(WEBRTC_MAC) && !USE_NATIVE_MUTEX_ON_MAC
+ // Number of times the lock has been locked + number of threads waiting.
+ // TODO(tommi): We could use this number and subtract the recursion count
+ // to find places where we have multiple threads contending on the same lock.
+ mutable volatile int lock_queue_;
+ // |recursion_| represents the recursion count + 1 for the thread that owns
+ // the lock. Only modified by the thread that owns the lock.
+ mutable int recursion_;
+ // Used to signal a single waiting thread when the lock becomes available.
+ mutable dispatch_semaphore_t semaphore_;
+ // The thread that currently holds the lock. Required to handle recursion.
+ mutable pthread_t owning_thread_;
+#else
mutable pthread_mutex_t mutex_;
+#endif
CS_DEBUG_CODE(mutable pthread_t thread_);
CS_DEBUG_CODE(mutable int recursion_count_);
#endif
« 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