]> git.ipfire.org Git - thirdparty/glibc.git/blobdiff - nptl/pthread_rwlock_trywrlock.c
Add adaptive elision to rwlocks
[thirdparty/glibc.git] / nptl / pthread_rwlock_trywrlock.c
index 106f157c1dd861e1ba03e6ccc1e4471c13a835d3..0291fc9e3c4c8d50c554f136bc402ed6c742a3a0 100644 (file)
@@ -19,6 +19,7 @@
 #include <errno.h>
 #include "pthreadP.h"
 #include <lowlevellock.h>
+#include <elide.h>
 
 
 int
@@ -26,6 +27,12 @@ __pthread_rwlock_trywrlock (pthread_rwlock_t *rwlock)
 {
   int result = EBUSY;
 
+  if (ELIDE_TRYLOCK (rwlock->__data.__rwelision,
+                    rwlock->__data.__lock == 0
+                    && rwlock->__data.__nr_readers == 0
+                    && rwlock->__data.__writer, 1))
+    return 0;
+
   lll_lock (rwlock->__data.__lock, rwlock->__data.__shared);
 
   if (rwlock->__data.__writer == 0 && rwlock->__data.__nr_readers == 0)