aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndi Kleen <ak@linux.intel.com>2014-03-31 08:07:46 -0700
committerAndi Kleen <ak@linux.intel.com>2014-06-13 13:15:28 -0700
commit8491ed6d70b60e4c75cdcfde10ae759898547b08 (patch)
treef26bd7e65ec2a860474297d5c8b87d49193ca4f2 /nptl/pthread_rwlock_wrlock.c
parentAdd a fast path for C rd/wrlock v2 (diff)
downloadglibc-8491ed6d70b60e4c75cdcfde10ae759898547b08.tar.gz
glibc-8491ed6d70b60e4c75cdcfde10ae759898547b08.tar.bz2
glibc-8491ed6d70b60e4c75cdcfde10ae759898547b08.zip
Add adaptive elision to rwlocks
This patch relies on the C version of the rwlocks posted earlier. With C rwlocks it is very straight forward to do adaptive elision using TSX. It is based on the infrastructure added earlier for mutexes, but uses its own elision macros. The macros are fairly general purpose and could be used for other elision purposes too. This version is much cleaner than the earlier assembler based version, and in particular implements adaptation which makes it safer. I changed the behavior slightly to not require any changes in the test suite and fully conform to all expected behaviors (generally at the cost of not eliding in various situations). In particular this means the timedlock variants are not elided. Nested trylock aborts.
Diffstat (limited to 'nptl/pthread_rwlock_wrlock.c')
-rw-r--r--nptl/pthread_rwlock_wrlock.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/nptl/pthread_rwlock_wrlock.c b/nptl/pthread_rwlock_wrlock.c
index de54e51432..91ad82a1be 100644
--- a/nptl/pthread_rwlock_wrlock.c
+++ b/nptl/pthread_rwlock_wrlock.c
@@ -22,6 +22,7 @@
#include <pthread.h>
#include <pthreadP.h>
#include <stap-probe.h>
+#include <elide.h>
/* Acquire write lock for RWLOCK. */
@@ -91,6 +92,12 @@ __pthread_rwlock_wrlock (pthread_rwlock_t *rwlock)
{
LIBC_PROBE (wrlock_entry, 1, rwlock);
+ if (ELIDE_LOCK (rwlock->__data.__rwelision,
+ rwlock->__data.__lock == 0
+ && rwlock->__data.__writer == 0
+ && rwlock->__data.__nr_readers == 0))
+ return 0;
+
/* Make sure we are alone. */
lll_lock (rwlock->__data.__lock, rwlock->__data.__shared);