summaryrefslogtreecommitdiff
path: root/mysys/thr_mutex.c
diff options
context:
space:
mode:
authorunknown <knielsen@knielsen-hq.org>2009-06-09 17:08:46 +0200
committerunknown <knielsen@knielsen-hq.org>2009-06-09 17:08:46 +0200
commitbb9a3f0c2b46491ec3234f8a9df8612f88469b90 (patch)
treecea8e6b16a29446b7bd775be7707bb616b7c18f7 /mysys/thr_mutex.c
parenta03c9ff55f7de5d32cbc1905fd0652ad64602891 (diff)
downloadmariadb-git-bb9a3f0c2b46491ec3234f8a9df8612f88469b90.tar.gz
XtraDB after-merge fixes.
Fixes to get the test suite to run without failures. mysql-test/r/information_schema.result: Additional variables available now. Sort output to avoid depending on engine order. mysql-test/r/information_schema_all_engines.result: More variables now. mysql-test/r/innodb-autoinc.result: Avoid picking up pbxt variables in result mysql-test/r/innodb-index.result: Save state to not corrupt following testcases. Suppress an expected warning. mysql-test/r/innodb-zip.result: Work around a problem with dependency on zlib version mysql-test/r/innodb.result: Checksums have changed in Maria. Save and restore server state to not corrupt following testcases. mysql-test/r/innodb_bug36169.result: Save and restore server state to not corrupt following testcases. mysql-test/r/innodb_xtradb_bug317074.result: Save and restore server state to not corrupt following testcases. mysql-test/r/row-checksum-old.result: Update result file mysql-test/r/row-checksum.result: Update result file mysql-test/t/information_schema.test: Sort output to avoid depending on engine order. mysql-test/t/innodb-analyze.test: Save and restore server state to not corrupt following testcases. mysql-test/t/innodb-autoinc.test: Save and restore server state to not corrupt following testcases. mysql-test/t/innodb-index.test: Save state to not corrupt following testcases. Suppress an expected warning. mysql-test/t/innodb-zip.test: Work around a problem with dependency on zlib version mysql-test/t/innodb.test: Save and restore server state to not corrupt following testcases. Update --replace statements for new mysql-test-run mysql-test/t/innodb_bug34300.test: Save and restore server state to not corrupt following testcases. mysql-test/t/innodb_bug36169.test: Save and restore server state to not corrupt following testcases. mysql-test/t/innodb_bug36172.test: Save and restore server state to not corrupt following testcases. mysql-test/t/innodb_xtradb_bug317074.test: Save and restore server state to not corrupt following testcases. mysql-test/t/partition_innodb.test: Fix regexps to work with new SHOW INNODB STATUS output. mysys/thr_mutex.c: Initialize mutex deadlock detection lazily. This allows to test XtraDB, which initializes huge amounts of mutexes without using any but a few of them. storage/xtradb/ibuf/ibuf0ibuf.c: Fix problem where value of INNODB_IBUF_MAX_SIZE would depend on the alignment of memory allocated by the buffer pool. storage/xtradb/include/sync0rw.h: Fix XtraDB to compile without GCC atomic operation intrinsics (performance may suffer when they are not available though). storage/xtradb/include/sync0rw.ic: Fix XtraDB to compile without GCC atomic operation intrinsics (performance may suffer when they are not available though). storage/xtradb/include/univ.i: Fix for MariaDB storage/xtradb/setup.sh: Remove no longer needed file from XtraDB. storage/xtradb/srv/srv0start.c: Fix for MariaDB
Diffstat (limited to 'mysys/thr_mutex.c')
-rw-r--r--mysys/thr_mutex.c63
1 files changed, 33 insertions, 30 deletions
diff --git a/mysys/thr_mutex.c b/mysys/thr_mutex.c
index 80f21e53473..c46b68761db 100644
--- a/mysys/thr_mutex.c
+++ b/mysys/thr_mutex.c
@@ -149,6 +149,35 @@ static inline void remove_from_active_list(safe_mutex_t *mp)
mp->prev= mp->next= 0;
}
+/*
+ We initialise the hashes for deadlock detection lazily.
+ This greatly helps with performance when lots of mutexes are initiased but
+ only a few of them are actually used (eg. XtraDB).
+*/
+static int safe_mutex_lazy_init_deadlock_detection(safe_mutex_t *mp)
+{
+ if (!my_multi_malloc(MY_FAE | MY_WME,
+ &mp->locked_mutex, sizeof(*mp->locked_mutex),
+ &mp->used_mutex, sizeof(*mp->used_mutex), NullS))
+ {
+ return 1; /* Error */
+ }
+
+ pthread_mutex_lock(&THR_LOCK_mutex);
+ mp->id= ++safe_mutex_id;
+ pthread_mutex_unlock(&THR_LOCK_mutex);
+ hash_init(mp->locked_mutex, &my_charset_bin,
+ 1000,
+ offsetof(safe_mutex_deadlock_t, id),
+ sizeof(mp->id),
+ 0, 0, HASH_UNIQUE);
+ hash_init(mp->used_mutex, &my_charset_bin,
+ 1000,
+ offsetof(safe_mutex_t, id),
+ sizeof(mp->id),
+ 0, 0, HASH_UNIQUE);
+ return 0;
+}
int safe_mutex_init(safe_mutex_t *mp,
const pthread_mutexattr_t *attr __attribute__((unused)),
@@ -167,35 +196,8 @@ int safe_mutex_init(safe_mutex_t *mp,
mp->line= line;
/* Skip the very common '&' prefix from the autogenerated name */
mp->name= name[0] == '&' ? name + 1 : name;
+ /* Deadlock detection is initialised only lazily, on first use. */
- if (safe_mutex_deadlock_detector && !( my_flags & MYF_NO_DEADLOCK_DETECTION))
- {
- if (!my_multi_malloc(MY_FAE | MY_WME,
- &mp->locked_mutex, sizeof(*mp->locked_mutex),
- &mp->used_mutex, sizeof(*mp->used_mutex), NullS))
- {
- /* Disable deadlock handling for this mutex */
- my_flags|= MYF_NO_DEADLOCK_DETECTION;
- }
- else
- {
- pthread_mutex_lock(&THR_LOCK_mutex);
- mp->id= ++safe_mutex_id;
- pthread_mutex_unlock(&THR_LOCK_mutex);
- hash_init(mp->locked_mutex, &my_charset_bin,
- 1000,
- offsetof(safe_mutex_deadlock_t, id),
- sizeof(mp->id),
- 0, 0, HASH_UNIQUE);
- hash_init(mp->used_mutex, &my_charset_bin,
- 1000,
- offsetof(safe_mutex_t, id),
- sizeof(mp->id),
- 0, 0, HASH_UNIQUE);
- }
- }
- else
- my_flags|= MYF_NO_DEADLOCK_DETECTION;
mp->create_flags= my_flags;
#ifdef SAFE_MUTEX_DETECT_DESTROY
@@ -310,7 +312,8 @@ int safe_mutex_lock(safe_mutex_t *mp, myf my_flags, const char *file,
/* Deadlock detection */
mp->prev= mp->next= 0;
- if (!(mp->active_flags & (MYF_TRY_LOCK | MYF_NO_DEADLOCK_DETECTION)))
+ if (!(mp->active_flags & (MYF_TRY_LOCK | MYF_NO_DEADLOCK_DETECTION)) &&
+ (mp->used_mutex != NULL || !safe_mutex_lazy_init_deadlock_detection(mp)))
{
safe_mutex_t **mutex_in_use= my_thread_var_mutex_in_use();
@@ -643,7 +646,7 @@ int safe_mutex_destroy(safe_mutex_t *mp, const char *file, uint line)
void safe_mutex_free_deadlock_data(safe_mutex_t *mp)
{
/* Free all entries that points to this one */
- if (!(mp->create_flags & MYF_NO_DEADLOCK_DETECTION))
+ if (!(mp->create_flags & MYF_NO_DEADLOCK_DETECTION) && mp->used_mutex != NULL)
{
pthread_mutex_lock(&THR_LOCK_mutex);
my_hash_iterate(mp->used_mutex,