Skip to content

Commit 56328cc

Browse files
committed
Bug#18991366 SAFE_HASH::MUTEX (MF_KEYCACHES.C) IS NOT INSTRUMENTED
Before this fix, the rwlock used in the SAFE_HASH implementation was not instrumented for the performance schema. With this fix, the rwlock is now instrumented. Also fixed the misleading variable name.
1 parent 89bca01 commit 56328cc

File tree

3 files changed

+23
-11
lines changed

3 files changed

+23
-11
lines changed

mysys/mf_keycaches.c

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
1+
/* Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License as published by
@@ -29,7 +29,7 @@
2929
/*****************************************************************************
3030
General functions to handle SAFE_HASH objects.
3131
32-
A SAFE_HASH object is used to store the hash, the mutex and default value
32+
A SAFE_HASH object is used to store the hash, the lock and default value
3333
needed by the rest of the key cache code.
3434
This is a separate struct to make it easy to later reuse the code for other
3535
purposes
@@ -53,7 +53,7 @@ typedef struct st_safe_hash_entry
5353

5454
typedef struct st_safe_hash_with_default
5555
{
56-
native_rw_lock_t mutex;
56+
mysql_rwlock_t lock;
5757
HASH hash;
5858
uchar *default_value;
5959
SAFE_HASH_ENTRY *root;
@@ -113,7 +113,7 @@ static my_bool safe_hash_init(SAFE_HASH *hash, uint elements,
113113
hash->default_value= 0;
114114
DBUG_RETURN(1);
115115
}
116-
native_rw_init(&hash->mutex);
116+
mysql_rwlock_init(key_SAFE_HASH_lock, &hash->lock);
117117
hash->default_value= default_value;
118118
hash->root= 0;
119119
DBUG_RETURN(0);
@@ -136,7 +136,7 @@ static void safe_hash_free(SAFE_HASH *hash)
136136
if (hash->default_value)
137137
{
138138
my_hash_free(&hash->hash);
139-
native_rw_destroy(&hash->mutex);
139+
mysql_rwlock_destroy(&hash->lock);
140140
hash->default_value=0;
141141
}
142142
}
@@ -149,9 +149,9 @@ static uchar *safe_hash_search(SAFE_HASH *hash, const uchar *key, uint length)
149149
{
150150
uchar *result;
151151
DBUG_ENTER("safe_hash_search");
152-
native_rw_rdlock(&hash->mutex);
152+
mysql_rwlock_rdlock(&hash->lock);
153153
result= my_hash_search(&hash->hash, key, length);
154-
native_rw_unlock(&hash->mutex);
154+
mysql_rwlock_unlock(&hash->lock);
155155
if (!result)
156156
result= hash->default_value;
157157
else
@@ -189,7 +189,7 @@ static my_bool safe_hash_set(SAFE_HASH *hash, const uchar *key, uint length,
189189
DBUG_ENTER("safe_hash_set");
190190
DBUG_PRINT("enter",("key: %.*s data: 0x%lx", length, key, (long) data));
191191

192-
native_rw_wrlock(&hash->mutex);
192+
mysql_rwlock_wrlock(&hash->lock);
193193
entry= (SAFE_HASH_ENTRY*) my_hash_search(&hash->hash, key, length);
194194

195195
if (data == hash->default_value)
@@ -240,7 +240,7 @@ static my_bool safe_hash_set(SAFE_HASH *hash, const uchar *key, uint length,
240240
}
241241

242242
end:
243-
native_rw_unlock(&hash->mutex);
243+
mysql_rwlock_unlock(&hash->lock);
244244
DBUG_RETURN(error);
245245
}
246246

@@ -265,7 +265,7 @@ static void safe_hash_change(SAFE_HASH *hash, uchar *old_data, uchar *new_data)
265265
SAFE_HASH_ENTRY *entry, *next;
266266
DBUG_ENTER("safe_hash_set");
267267

268-
native_rw_wrlock(&hash->mutex);
268+
mysql_rwlock_wrlock(&hash->lock);
269269

270270
for (entry= hash->root ; entry ; entry= next)
271271
{
@@ -283,7 +283,7 @@ static void safe_hash_change(SAFE_HASH *hash, uchar *old_data, uchar *new_data)
283283
}
284284
}
285285

286-
native_rw_unlock(&hash->mutex);
286+
mysql_rwlock_unlock(&hash->lock);
287287
DBUG_VOID_RETURN;
288288
}
289289

mysys/my_init.c

+10
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,13 @@ static PSI_mutex_info all_mysys_mutexes[]=
468468
{ &key_THR_LOCK_myisam_mmap, "THR_LOCK_myisam_mmap", PSI_FLAG_GLOBAL}
469469
};
470470

471+
PSI_rwlock_key key_SAFE_HASH_lock;
472+
473+
static PSI_rwlock_info all_mysys_rwlocks[]=
474+
{
475+
{ &key_SAFE_HASH_lock, "SAFE_HASH::lock", 0}
476+
};
477+
471478
PSI_cond_key key_IO_CACHE_SHARE_cond,
472479
key_IO_CACHE_SHARE_cond_writer, key_my_thread_var_suspend,
473480
key_THR_COND_threads;
@@ -540,6 +547,9 @@ void my_init_mysys_psi_keys()
540547
count= sizeof(all_mysys_mutexes)/sizeof(all_mysys_mutexes[0]);
541548
mysql_mutex_register(category, all_mysys_mutexes, count);
542549

550+
count= sizeof(all_mysys_rwlocks)/sizeof(all_mysys_rwlocks[0]);
551+
mysql_rwlock_register(category, all_mysys_rwlocks, count);
552+
543553
count= sizeof(all_mysys_conds)/sizeof(all_mysys_conds[0]);
544554
mysql_cond_register(category, all_mysys_conds, count);
545555

mysys/mysys_priv.h

+2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ extern PSI_mutex_key key_BITMAP_mutex, key_IO_CACHE_append_buffer_lock,
3434
key_THR_LOCK_open, key_THR_LOCK_threads,
3535
key_TMPDIR_mutex, key_THR_LOCK_myisam_mmap;
3636

37+
extern PSI_rwlock_key key_SAFE_HASH_lock;
38+
3739
extern PSI_cond_key key_IO_CACHE_SHARE_cond,
3840
key_IO_CACHE_SHARE_cond_writer, key_my_thread_var_suspend,
3941
key_THR_COND_threads;

0 commit comments

Comments
 (0)