diff options
-rw-r--r-- | mysys/lf_alloc-pin.c | 7 | ||||
-rw-r--r-- | storage/perfschema/pfs_instr.cc | 49 |
2 files changed, 35 insertions, 21 deletions
diff --git a/mysys/lf_alloc-pin.c b/mysys/lf_alloc-pin.c index 22887d17c07..7af87bca111 100644 --- a/mysys/lf_alloc-pin.c +++ b/mysys/lf_alloc-pin.c @@ -211,13 +211,16 @@ void _lf_pinbox_put_pins(LF_PINS *pins) LF_PINBOX *pinbox= pins->pinbox; uint32 top_ver, nr; nr= pins->link; -#ifdef MY_LF_EXTRA_DEBUG + +#ifndef DBUG_OFF { + /* This thread should not hold any pin. */ int i; for (i= 0; i < LF_PINBOX_PINS; i++) DBUG_ASSERT(pins->pin[i] == 0); } -#endif +#endif /* DBUG_OFF */ + /* XXX this will deadlock if other threads will wait for the caller to do something after _lf_pinbox_put_pins(), diff --git a/storage/perfschema/pfs_instr.cc b/storage/perfschema/pfs_instr.cc index a877ea61198..c83628cb7cd 100644 --- a/storage/perfschema/pfs_instr.cc +++ b/storage/perfschema/pfs_instr.cc @@ -1,4 +1,4 @@ -/* Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. +/* Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -802,6 +802,22 @@ void destroy_thread(PFS_thread *pfs) } /** + Get the hash pins for @filename_hash. + @param thread The running thread. + @returns The LF_HASH pins for the thread. +*/ +LF_PINS* get_filename_hash_pins(PFS_thread *thread) +{ + if (unlikely(thread->m_filename_hash_pins == NULL)) + { + if (! filename_hash_inited) + return NULL; + thread->m_filename_hash_pins= lf_hash_get_pins(&filename_hash); + } + return thread->m_filename_hash_pins; +} + +/** Find or create instrumentation for a file instance by file name. @param thread the executing instrumented thread @param klass the file class @@ -816,23 +832,13 @@ find_or_create_file(PFS_thread *thread, PFS_file_class *klass, PFS_file *pfs; PFS_scan scan; - if (! filename_hash_inited) + LF_PINS *pins= get_filename_hash_pins(thread); + if (unlikely(pins == NULL)) { - /* File instrumentation can be turned off. */ file_lost++; return NULL; } - if (unlikely(thread->m_filename_hash_pins == NULL)) - { - thread->m_filename_hash_pins= lf_hash_get_pins(&filename_hash); - if (unlikely(thread->m_filename_hash_pins == NULL)) - { - file_lost++; - return NULL; - } - } - char safe_buffer[FN_REFLEN]; const char *safe_filename; @@ -904,7 +910,7 @@ find_or_create_file(PFS_thread *thread, PFS_file_class *klass, /* Append the unresolved file name to the resolved path */ char *ptr= buffer + strlen(buffer); char *buf_end= &buffer[sizeof(buffer)-1]; - if (buf_end > ptr) + if ((buf_end > ptr) && (*(ptr-1) != FN_LIBCHAR)) *ptr++= FN_LIBCHAR; if (buf_end > ptr) strncpy(ptr, safe_filename + dirlen, buf_end - ptr); @@ -918,16 +924,18 @@ find_or_create_file(PFS_thread *thread, PFS_file_class *klass, const uint retry_max= 3; search: entry= reinterpret_cast<PFS_file**> - (lf_hash_search(&filename_hash, thread->m_filename_hash_pins, + (lf_hash_search(&filename_hash, pins, normalized_filename, normalized_length)); if (entry && (entry != MY_ERRPTR)) { pfs= *entry; pfs->m_file_stat.m_open_count++; - lf_hash_search_unpin(thread->m_filename_hash_pins); + lf_hash_search_unpin(pins); return pfs; } + lf_hash_search_unpin(pins); + /* filename is not constant, just using it for noise on create */ uint random= randomized_index(filename, file_max); @@ -954,7 +962,7 @@ search: reset_single_stat_link(&pfs->m_wait_stat); int res; - res= lf_hash_insert(&filename_hash, thread->m_filename_hash_pins, + res= lf_hash_insert(&filename_hash, pins, &pfs); if (likely(res == 0)) { @@ -1006,9 +1014,12 @@ void release_file(PFS_file *pfs) void destroy_file(PFS_thread *thread, PFS_file *pfs) { DBUG_ASSERT(thread != NULL); - DBUG_ASSERT(thread->m_filename_hash_pins != NULL); DBUG_ASSERT(pfs != NULL); - lf_hash_delete(&filename_hash, thread->m_filename_hash_pins, + + LF_PINS *pins= get_filename_hash_pins(thread); + DBUG_ASSERT(pins != NULL); + + lf_hash_delete(&filename_hash, pins, pfs->m_filename, pfs->m_filename_length); pfs->m_lock.allocated_to_free(); } |