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

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: 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 5b3eaf56840cd1698701ac1669ccca9b3763c0b4..ddbf2bfd4aeb1c73c5faf39a6022b728506e30b4 100644
--- a/webrtc/base/criticalsection.h
+++ b/webrtc/base/criticalsection.h
@@ -29,6 +29,10 @@
#include <pthread.h>
#endif
+#if defined(WEBRTC_MAC)
+#include <dispatch/dispatch.h>
+#endif
+
#if (!defined(NDEBUG) || defined(DCHECK_ALWAYS_ON))
#define CS_DEBUG_CHECKS 1
#endif
@@ -59,7 +63,21 @@ class LOCKABLE CriticalSection {
#if defined(WEBRTC_WIN)
CRITICAL_SECTION crit_;
#elif defined(WEBRTC_POSIX)
+#if defined(WEBRTC_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.
+ 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.
+ int recursion_;
+ // Used to signal a single waiting thread when the lock becomes available.
+ dispatch_semaphore_t semaphore_;
+ // The thread that currently holds the lock. Required to handle recursion.
+ pthread_t owning_thread_;
+#else
pthread_mutex_t mutex_;
+#endif
CS_DEBUG_CODE(pthread_t thread_);
CS_DEBUG_CODE(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