summaryrefslogtreecommitdiff
path: root/mysys/thr_mutex.c
diff options
context:
space:
mode:
authorMichael Widenius <monty@askmonty.org>2009-02-15 12:58:34 +0200
committerMichael Widenius <monty@askmonty.org>2009-02-15 12:58:34 +0200
commita8fdaa6f2c5b2e302bffb069be3475772ca20f48 (patch)
treeb5c9560ec7346f7af6a5904ad344fdbb8020849c /mysys/thr_mutex.c
parent115efe100dbc1393bce964fa1370e50cfef71d18 (diff)
parentf7a24d72dc7a86341da4634f6d1a71f1ea77000b (diff)
downloadmariadb-git-a8fdaa6f2c5b2e302bffb069be3475772ca20f48.tar.gz
Merge with base MySQL 5.1
Contains fixes for test cases Changed release tag to beta configure.in: change release tag to beta
Diffstat (limited to 'mysys/thr_mutex.c')
-rw-r--r--mysys/thr_mutex.c67
1 files changed, 65 insertions, 2 deletions
diff --git a/mysys/thr_mutex.c b/mysys/thr_mutex.c
index 4f19f5d79c4..cc6bdab2522 100644
--- a/mysys/thr_mutex.c
+++ b/mysys/thr_mutex.c
@@ -19,7 +19,11 @@
#if defined(TARGET_OS_LINUX) && !defined (__USE_UNIX98)
#define __USE_UNIX98 /* To get rw locks under Linux */
#endif
-#if defined(THREAD) && defined(SAFE_MUTEX)
+#ifdef SAFE_MUTEX
+#define SAFE_MUTEX_DEFINED
+#endif
+
+#if defined(THREAD)
#undef SAFE_MUTEX /* Avoid safe_mutex redefinitions */
#include "mysys_priv.h"
#include "my_static.h"
@@ -41,6 +45,13 @@
#endif
#endif /* DO_NOT_REMOVE_THREAD_WRAPPERS */
+#ifdef PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP
+pthread_mutexattr_t my_fast_mutexattr;
+#endif
+#ifdef PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP
+pthread_mutexattr_t my_errorcheck_mutexattr;
+#endif
+#ifdef SAFE_MUTEX_DEFINED
static pthread_mutex_t THR_LOCK_mutex;
static ulong safe_mutex_count= 0; /* Number of mutexes created */
static ulong safe_mutex_id= 0;
@@ -60,7 +71,58 @@ static my_bool remove_from_used_mutex(safe_mutex_deadlock_t *locked_mutex,
safe_mutex_t *mutex);
static void print_deadlock_warning(safe_mutex_t *new_mutex,
safe_mutex_t *conflicting_mutex);
+#endif
+
+
+/* Initialize all mutex handling */
+
+void my_mutex_init()
+{
+ /* Initialize mutex attributes */
+#ifdef PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP
+ /*
+ Set mutex type to "fast" a.k.a "adaptive"
+
+ In this case the thread may steal the mutex from some other thread
+ that is waiting for the same mutex. This will save us some
+ context switches but may cause a thread to 'starve forever' while
+ waiting for the mutex (not likely if the code within the mutex is
+ short).
+ */
+ pthread_mutexattr_init(&my_fast_mutexattr);
+ pthread_mutexattr_settype(&my_fast_mutexattr,
+ PTHREAD_MUTEX_ADAPTIVE_NP);
+#endif
+#ifdef PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP
+ /*
+ Set mutex type to "errorcheck"
+ */
+ pthread_mutexattr_init(&my_errorcheck_mutexattr);
+ pthread_mutexattr_settype(&my_errorcheck_mutexattr,
+ PTHREAD_MUTEX_ERRORCHECK);
+#endif
+
+#if defined(SAFE_MUTEX_DEFINED)
+ safe_mutex_global_init();
+#elif defined(MY_PTHREAD_FASTMUTEX)
+ fastmutex_global_init();
+#endif
+}
+
+void my_mutex_end()
+{
+#ifdef PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP
+ pthread_mutexattr_destroy(&my_fast_mutexattr);
+#endif
+#ifdef PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP
+ pthread_mutexattr_destroy(&my_errorcheck_mutexattr);
+#endif
+}
+
+
+/* Initialize safe_mutex handling */
+#ifdef SAFE_MUTEX_DEFINED
void safe_mutex_global_init(void)
{
pthread_mutex_init(&THR_LOCK_mutex,MY_MUTEX_INIT_FAST);
@@ -865,4 +927,5 @@ void fastmutex_global_init(void)
#endif
}
-#endif /* defined(THREAD) && defined(MY_PTHREAD_FASTMUTEX) && !defined(SAFE_MUTEX) */
+#endif /* SAFE_MUTEX_DEFINED */
+#endif /* THREAD */