e8c659d74e
Add elision paths to the basic mutex locks. The normal path has a check for RTM and upgrades the lock to RTM when available. Trylocks cannot automatically upgrade, so they check for elision every time. We use a 4 byte value in the mutex to store the lock elision adaptation state. This is separate from the adaptive spin state and uses a separate field. Condition variables currently do not support elision. Recursive mutexes and condition variables may be supported at some point, but are not in the current implementation. Also "trylock" will not automatically enable elision unless some other lock call has been already called on the lock. This version does not use IFUNC, so it means every lock has one additional check for elision. Benchmarking showed the overhead to be negligible.
22 lines
752 B
C
22 lines
752 B
C
#include <pthreadP.h>
|
|
|
|
#define LLL_MUTEX_LOCK(mutex) \
|
|
lll_cond_lock ((mutex)->__data.__lock, PTHREAD_MUTEX_PSHARED (mutex))
|
|
|
|
/* Not actually elided so far. Needed? */
|
|
#define LLL_MUTEX_LOCK_ELISION(mutex) \
|
|
({ lll_cond_lock ((mutex)->__data.__lock, PTHREAD_MUTEX_PSHARED (mutex)); 0; })
|
|
|
|
#define LLL_MUTEX_TRYLOCK(mutex) \
|
|
lll_cond_trylock ((mutex)->__data.__lock)
|
|
#define LLL_MUTEX_TRYLOCK_ELISION(mutex) LLL_MUTEX_TRYLOCK(mutex)
|
|
|
|
#define LLL_ROBUST_MUTEX_LOCK(mutex, id) \
|
|
lll_robust_cond_lock ((mutex)->__data.__lock, id, \
|
|
PTHREAD_ROBUST_MUTEX_PSHARED (mutex))
|
|
#define __pthread_mutex_lock __pthread_mutex_cond_lock
|
|
#define __pthread_mutex_lock_full __pthread_mutex_cond_lock_full
|
|
#define NO_INCR
|
|
|
|
#include <nptl/pthread_mutex_lock.c>
|