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

Unified Diff: base/synchronization/lock_impl_posix.cc

Issue 2887263002: Switch to unfair locks on macOS for better performance (?)
Patch Set: Created 3 years, 7 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 | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/synchronization/lock_impl_posix.cc
diff --git a/base/synchronization/lock_impl_posix.cc b/base/synchronization/lock_impl_posix.cc
index e54595b87f10a353647d4a0ee40aa30d2a649780..fe5d21cf0d46a2e717e0baadf4a534eff06e26a3 100644
--- a/base/synchronization/lock_impl_posix.cc
+++ b/base/synchronization/lock_impl_posix.cc
@@ -11,6 +11,10 @@
#include "base/logging.h"
#include "base/synchronization/lock.h"
+#if defined(OS_MACOSX)
+#include <pthread_spis.h>
+#endif
+
namespace base {
namespace internal {
@@ -42,6 +46,11 @@ LockImpl::LockImpl() {
rv = pthread_mutexattr_settype(&mta, PTHREAD_MUTEX_ERRORCHECK);
DCHECK_EQ(rv, 0) << ". " << strerror(rv);
#endif
+#if defined(OS_MACOSX)
+ // macOS defaults to fair locks which can be orders of magnitude slower in the
+ // contention case, so default to first fit, which avoids queuing.
+ pthread_mutexattr_setpolicy_np(&mta, _PTHREAD_MUTEX_POLICY_FIRSTFIT);
+#endif
rv = pthread_mutex_init(&native_handle_, &mta);
DCHECK_EQ(rv, 0) << ". " << strerror(rv);
rv = pthread_mutexattr_destroy(&mta);
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698