aboutsummaryrefslogtreecommitdiffstats
path: root/include/pthread.h
diff options
context:
space:
mode:
authorKris Kennaway <kris@FreeBSD.org>2007-10-29 21:01:47 +0000
committerKris Kennaway <kris@FreeBSD.org>2007-10-29 21:01:47 +0000
commit2017a7cdfe8f1a0e38b76e8e8871fe90df07b8f7 (patch)
tree123bb16d6371107a5d220b0407c7bdd0e6d6cade /include/pthread.h
parent539976ffdf2923d2ef4f3d76f7b441df0883240f (diff)
downloadsrc-2017a7cdfe8f1a0e38b76e8e8871fe90df07b8f7.tar.gz
src-2017a7cdfe8f1a0e38b76e8e8871fe90df07b8f7.zip
Add a new "non-portable" mutex type, PTHREAD_MUTEX_ADAPTIVE_NP. This
is also implemented in glibc and is used by a number of existing applications (mysql, firefox, etc). This mutex type is a default mutex with the additional property that it spins briefly when attempting to acquire a contested lock, doing trylock operations in userland before entering the kernel to block if eventually unsuccessful. The expectation is that applications requesting this mutex type know that the mutex is likely to be only held for very brief periods, so it is faster to spin in userland and probably succeed in acquiring the mutex, than to enter the kernel and sleep, only to be woken up almost immediately. This can help significantly in certain cases when pthread mutexes are heavily contended and held for brief durations (such as mysql). Spin up to 200 times before entering the kernel, which represents only a few us on modern CPUs. No performance degradation was observed with this value and it is sufficient to avoid a large performance drop in mysql performance in the heavily contended pthread mutex case. The libkse implementation is a NOP. Reviewed by: jeff MFC after: 3 days
Notes
Notes: svn path=/head/; revision=173154
Diffstat (limited to 'include/pthread.h')
-rw-r--r--include/pthread.h2
1 files changed, 2 insertions, 0 deletions
diff --git a/include/pthread.h b/include/pthread.h
index ee864fdc4f19..361b45ce91e0 100644
--- a/include/pthread.h
+++ b/include/pthread.h
@@ -98,6 +98,7 @@
* Static initialization values.
*/
#define PTHREAD_MUTEX_INITIALIZER NULL
+#define PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP NULL
#define PTHREAD_COND_INITIALIZER NULL
#define PTHREAD_RWLOCK_INITIALIZER NULL
@@ -128,6 +129,7 @@ enum pthread_mutextype {
PTHREAD_MUTEX_ERRORCHECK = 1, /* Default POSIX mutex */
PTHREAD_MUTEX_RECURSIVE = 2, /* Recursive mutex */
PTHREAD_MUTEX_NORMAL = 3, /* No error checking */
+ PTHREAD_MUTEX_ADAPTIVE_NP = 4, /* Adaptive mutex, spins briefly before blocking on lock */
PTHREAD_MUTEX_TYPE_MAX
};