diff options
76 files changed, 4888 insertions, 597 deletions
diff --git a/Makefile.am b/Makefile.am index c208b5b6df1..fd55ec099fa 100644 --- a/Makefile.am +++ b/Makefile.am @@ -269,11 +269,12 @@ test-full-qa: # API_PREPROCESSOR_HEADER = $(top_srcdir)/include/mysql/plugin.h \ - $(top_srcdir)/include/mysql.h + $(top_srcdir)/include/mysql.h \ + $(top_srcdir)/include/mysql/psi/psi_abi_v1.h \ + $(top_srcdir)/include/mysql/psi/psi_abi_v2.h -TEST_PREPROCESSOR_HEADER = $(top_srcdir)/include/mysql/plugin.h \ - $(top_srcdir)/sql/mysql_priv.h \ - $(top_srcdir)/include/mysql.h +TEST_PREPROCESSOR_HEADER = $(API_PREPROCESSOR_HEADER) \ + $(top_srcdir)/sql/mysql_priv.h # # Rules for checking that the abi/api has not changed. diff --git a/include/Makefile.am b/include/Makefile.am index fff162474a5..579eff1afad 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -1,4 +1,4 @@ -# Copyright (C) 2000-2006 MySQL AB +# Copyright (C) 2000-2006 MySQL AB, 2009 Sun Microsystems, Inc # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Library General Public @@ -24,6 +24,8 @@ pkginclude_HEADERS = $(HEADERS_ABI) my_dbug.h m_string.h my_sys.h \ my_xml.h mysql_embed.h mysql/services.h \ mysql/service_my_snprintf.h mysql/service_thd_alloc.h \ my_pthread.h my_no_pthread.h \ + mysql/psi/psi.h mysql/psi/mysql_thread.h \ + mysql/psi/mysql_file.h \ decimal.h errmsg.h my_global.h my_net.h \ my_getopt.h sslopt-longopts.h my_dir.h \ sslopt-vars.h sslopt-case.h sql_common.h keycache.h \ @@ -38,13 +40,15 @@ noinst_HEADERS = config-win.h config-netware.h lf.h my_bit.h \ my_aes.h my_tree.h my_trie.h hash.h thr_alarm.h \ thr_lock.h t_ctype.h violite.h my_md5.h base64.h \ my_handler.h my_time.h service_versions.h \ - my_rdtsc.h \ + my_rdtsc.h mysql/psi/psi_abi_v1.h mysql/psi/psi_abi_v2.h \ my_vle.h my_user.h my_atomic.h atomic/nolock.h \ atomic/rwlock.h atomic/x86-gcc.h atomic/generic-msvc.h \ atomic/gcc_builtins.h my_libwrap.h my_stacktrace.h \ atomic/solaris.h -EXTRA_DIST = mysql.h.pp mysql/plugin.h.pp probes_mysql.d.base +EXTRA_DIST = mysql.h.pp mysql/plugin.h.pp probes_mysql.d.base \ + mysql/psi/psi_abi_v1.h.pp \ + mysql/psi/psi_abi_v2.h.pp # Remove built files and the symlinked directories CLEANFILES = $(BUILT_SOURCES) readline openssl probes_mysql.d probes_mysql_nodtrace.h diff --git a/include/heap.h b/include/heap.h index 4a1c7d419ed..27aefb5beda 100644 --- a/include/heap.h +++ b/include/heap.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2000,2004 MySQL AB +/* Copyright (C) 2000-2004 MySQL AB, 2009 Sun Microsystems, Inc 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 @@ -148,7 +148,7 @@ typedef struct st_heap_share char * name; /* Name of "memory-file" */ #ifdef THREAD THR_LOCK lock; - pthread_mutex_t intern_lock; /* Locking for use with _locking */ + mysql_mutex_t intern_lock; /* Locking for use with _locking */ #endif my_bool delete_on_close; LIST open_list; diff --git a/include/my_global.h b/include/my_global.h index f95c8aa2441..79d1ea7891c 100644 --- a/include/my_global.h +++ b/include/my_global.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2003 MySQL AB +/* Copyright (C) 2000-2003 MySQL AB, 2009 Sun Microsystems, Inc 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 @@ -83,6 +83,16 @@ #endif #endif /* _WIN32... */ +#ifdef EMBEDDED_LIBRARY +#ifdef WITH_PERFSCHEMA_STORAGE_ENGINE +#undef WITH_PERFSCHEMA_STORAGE_ENGINE +#endif +#endif /* EMBEDDED_LIBRARY */ + +#ifdef WITH_PERFSCHEMA_STORAGE_ENGINE +#define HAVE_PSI_INTERFACE +#endif /* WITH_PERFSCHEMA_STORAGE_ENGINE */ + /* Make it easier to add conditionl code for windows */ #ifdef __WIN__ #define IF_WIN(A,B) (A) diff --git a/include/my_no_pthread.h b/include/my_no_pthread.h index 31c1bf2b6ac..995fc5e1774 100644 --- a/include/my_no_pthread.h +++ b/include/my_no_pthread.h @@ -1,7 +1,7 @@ #ifndef MY_NO_PTHREAD_INCLUDED #define MY_NO_PTHREAD_INCLUDED -/* Copyright (C) 2000 MySQL AB +/* Copyright (C) 2000 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -48,5 +48,16 @@ #define rw_unlock(A) #define rwlock_destroy(A) +#define mysql_mutex_init(A, B, C) do {} while (0) +#define mysql_mutex_lock(A) do {} while (0) +#define mysql_mutex_unlock(A) do {} while (0) +#define mysql_mutex_destroy(A) do {} while (0) + +#define mysql_rwlock_init(A, B, C) do {} while (0) +#define mysql_rwlock_rdlock(A) do {} while (0) +#define mysql_rwlock_wrlock(A) do {} while (0) +#define mysql_rwlock_unlock(A) do {} while (0) +#define mysql_rwlock_destroy(A) do {} while (0) + #endif #endif /* MY_NO_PTHREAD_INCLUDED */ diff --git a/include/my_pthread.h b/include/my_pthread.h index 3b95e2adb73..c4d4e3d7adf 100644 --- a/include/my_pthread.h +++ b/include/my_pthread.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2000 MySQL AB +/* Copyright (C) 2000-2008 MySQL AB, 2008-2009 Sun Microsystems, Inc. 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 @@ -99,7 +99,7 @@ struct timespec { int win_pthread_mutex_trylock(pthread_mutex_t *mutex); -int pthread_create(pthread_t *,pthread_attr_t *,pthread_handler,void *); +int pthread_create(pthread_t *, const pthread_attr_t *, pthread_handler, void *); int pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *attr); int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex); int pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex, @@ -137,8 +137,8 @@ int pthread_join(pthread_t thread, void **value_ptr); #define pthread_mutex_init(A,B) (InitializeCriticalSection(A),0) #define pthread_mutex_lock(A) (EnterCriticalSection(A),0) #define pthread_mutex_trylock(A) win_pthread_mutex_trylock((A)) -#define pthread_mutex_unlock(A) LeaveCriticalSection(A) -#define pthread_mutex_destroy(A) DeleteCriticalSection(A) +#define pthread_mutex_unlock(A) (LeaveCriticalSection(A), 0) +#define pthread_mutex_destroy(A) (DeleteCriticalSection(A), 0) #define pthread_kill(A,B) pthread_dummy((A) ? 0 : ESRCH) @@ -630,6 +630,10 @@ extern int pthread_dummy(int); #endif #endif +#include <mysql/psi/mysql_thread.h> + +#define INSTRUMENT_ME 0 + struct st_my_thread_var { int thr_errno; diff --git a/include/my_sys.h b/include/my_sys.h index bbbc89cb9f8..5c1dd062355 100644 --- a/include/my_sys.h +++ b/include/my_sys.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2003 MySQL AB +/* Copyright (C) 2000-2003 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -1021,5 +1021,15 @@ void netware_reg_user(const char *ip, const char *user, const char *application); #endif +#include <mysql/psi/psi.h> + +#ifdef HAVE_PSI_INTERFACE +extern MYSQL_PLUGIN_IMPORT struct PSI_bootstrap *PSI_hook; +void my_init_mysys_psi_keys(void); +#endif + +struct st_mysql_file; +extern struct st_mysql_file *mysql_stdin; + C_MODE_END #endif /* _my_sys_h */ diff --git a/include/myisam.h b/include/myisam.h index 2df7ccf6dfa..194f0dd806a 100644 --- a/include/myisam.h +++ b/include/myisam.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2000 MySQL AB +/* Copyright (C) 2000 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -433,7 +433,7 @@ typedef struct st_mi_check_param const char *op_name; enum_mi_stats_method stats_method; #ifdef THREAD - pthread_mutex_t print_msg_mutex; + mysql_mutex_t print_msg_mutex; my_bool need_print_msg_lock; #endif } MI_CHECK; @@ -460,8 +460,8 @@ typedef struct st_sort_info /* sync things */ uint got_error, threads_running; #ifdef THREAD - pthread_mutex_t mutex; - pthread_cond_t cond; + mysql_mutex_t mutex; + mysql_cond_t cond; #endif } SORT_INFO; diff --git a/include/myisammrg.h b/include/myisammrg.h index 31ce3fa47b8..3277510705b 100644 --- a/include/myisammrg.h +++ b/include/myisammrg.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2000 MySQL AB +/* Copyright (C) 2000 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -75,7 +75,7 @@ typedef struct st_myrg_info LIST open_list; QUEUE by_key; ulong *rec_per_key_part; /* for sql optimizing */ - pthread_mutex_t mutex; + mysql_mutex_t mutex; } MYRG_INFO; diff --git a/include/mysql/psi/mysql_file.h b/include/mysql/psi/mysql_file.h new file mode 100644 index 00000000000..18220a8dd4e --- /dev/null +++ b/include/mysql/psi/mysql_file.h @@ -0,0 +1,1398 @@ +/* Copyright (C) 2008-2009 Sun Microsystems, Inc + + 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 + the Free Software Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + +#ifndef MYSQL_FILE_H +#define MYSQL_FILE_H + +/* For strlen() */ +#include <string.h> +/* For MY_STAT */ +#include <my_dir.h> + +/** + @file mysql/psi/mysql_file.h + Instrumentation helpers for mysys file io. + This header file provides the necessary declarations + to use the mysys file API with the performance schema instrumentation. + In some compilers (SunStudio), 'static inline' functions, when declared + but not used, are not optimized away (because they are unused) by default, + so that including a static inline function from a header file does + create unwanted dependencies, causing unresolved symbols at link time. + Other compilers, like gcc, optimize these dependencies by default. + + Since the instrumented APIs declared here are wrapper on top + of mysys file io APIs, including mysql/psi/mysql_file.h assumes that + the dependency on my_sys already exists. +*/ + +#include "mysql/psi/psi.h" + +/** + @defgroup File_instrumentation File Instrumentation + @ingroup Instrumentation_interface + @{ +*/ + +/** + @def mysql_file_fgets(P1, P2, F) + Instrumented fgets. + @c mysql_file_fgets is a replacement for @c fgets. +*/ +#ifdef HAVE_PSI_INTERFACE + #define mysql_file_fgets(P1, P2, F) \ + inline_mysql_file_fgets(__FILE__, __LINE__, P1, P2, F) +#else + #define mysql_file_fgets(P1, P2, F) \ + inline_mysql_file_fgets(P1, P2, F) +#endif + +/** + @def mysql_file_fgetc(F) + Instrumented fgetc. + @c mysql_file_fgetc is a replacement for @c fgetc. +*/ +#ifdef HAVE_PSI_INTERFACE + #define mysql_file_fgetc(F) inline_mysql_file_fgetc(__FILE__, __LINE__, F) +#else + #define mysql_file_fgetc(F) inline_mysql_file_fgetc(F) +#endif + +/** + @def mysql_file_fputs(P1, F) + Instrumented fputs. + @c mysql_file_fputs is a replacement for @c fputs. +*/ +#ifdef HAVE_PSI_INTERFACE + #define mysql_file_fputs(P1, F) \ + inline_mysql_file_fputs(__FILE__, __LINE__, P1, F) +#else + #define mysql_file_fputs(P1, F)\ + inline_mysql_file_fputs(P1, F) +#endif + +/** + @def mysql_file_fputc(P1, F) + Instrumented fputc. + @c mysql_file_fputc is a replacement for @c fputc. +*/ +#ifdef HAVE_PSI_INTERFACE + #define mysql_file_fputc(P1, F) \ + inline_mysql_file_fputc(__FILE__, __LINE__, P1, F) +#else + #define mysql_file_fputc(P1, F) \ + inline_mysql_file_fputc(P1, F) +#endif + +/** + @def mysql_file_fprintf + Instrumented fprintf. + @c mysql_file_fprintf is a replacement for @c fprintf. +*/ +#define mysql_file_fprintf inline_mysql_file_fprintf + +/** + @def mysql_file_vfprintf(F, P1, P2) + Instrumented vfprintf. + @c mysql_file_vfprintf is a replacement for @c vfprintf. +*/ +#ifdef HAVE_PSI_INTERFACE + #define mysql_file_vfprintf(F, P1, P2) \ + inline_mysql_file_vfprintf(__FILE__, __LINE__, F, P1, P2) +#else + #define mysql_file_vfprintf(F, P1, P2) \ + inline_mysql_file_vfprintf(F, P1, P2) +#endif + +/** + @def mysql_file_fflush(F, P1, P2) + Instrumented fflush. + @c mysql_file_fflush is a replacement for @c fflush. +*/ +#ifdef HAVE_PSI_INTERFACE + #define mysql_file_fflush(F) \ + inline_mysql_file_fflush(__FILE__, __LINE__, F) +#else + #define mysql_file_fflush(F) \ + inline_mysql_file_fflush(F) +#endif + +/** + @def mysql_file_feof(F) + Instrumented feof. + @c mysql_file_feof is a replacement for @c feof. +*/ +#define mysql_file_feof(F) inline_mysql_file_feof(F) + +/** + @def mysql_file_fstat(FN, S, FL) + Instrumented fstat. + @c mysql_file_fstat is a replacement for @c my_fstat. +*/ +#ifdef HAVE_PSI_INTERFACE + #define mysql_file_fstat(FN, S, FL) \ + inline_mysql_file_fstat(__FILE__, __LINE__, FN, S, FL) +#else + #define mysql_file_fstat(FN, S, FL) \ + inline_mysql_file_fstat(FN, S, FL) +#endif + +/** + @def mysql_file_stat(K, FN, S, FL) + Instrumented stat. + @c mysql_file_stat is a replacement for @c my_stat. +*/ +#ifdef HAVE_PSI_INTERFACE + #define mysql_file_stat(K, FN, S, FL) \ + inline_mysql_file_stat(K, __FILE__, __LINE__, FN, S, FL) +#else + #define mysql_file_stat(K, FN, S, FL) \ + inline_mysql_file_stat(FN, S, FL) +#endif + +/** + @def mysql_file_chsize(F, P1, P2, P3) + Instrumented chsize. + @c mysql_file_chsize is a replacement for @c my_chsize. +*/ +#ifdef HAVE_PSI_INTERFACE + #define mysql_file_chsize(F, P1, P2, P3) \ + inline_mysql_file_chsize(__FILE__, __LINE__, F, P1, P2, P3) +#else + #define mysql_file_chsize(F, P1, P2, P3) \ + inline_mysql_file_chsize(F, P1, P2, P3) +#endif + +/** + @def mysql_file_fopen(K, N, F1, F2) + Instrumented fopen. + @c mysql_file_fopen is a replacement for @c my_fopen. +*/ +#ifdef HAVE_PSI_INTERFACE + #define mysql_file_fopen(K, N, F1, F2) \ + inline_mysql_file_fopen(K, __FILE__, __LINE__, N, F1, F2) +#else + #define mysql_file_fopen(K, N, F1, F2) \ + inline_mysql_file_fopen(N, F1, F2) +#endif + +/** + @def mysql_file_fclose(FD, FL) + Instrumented fclose. + @c mysql_file_fclose is a replacement for @c my_fclose. + Without the instrumentation, this call will have the same behavior as the + undocumented and possibly platform specific my_fclose(NULL, ...) behavior. + With the instrumentation, mysql_fclose(NULL, ...) will safely return 0, + which is an extension compared to my_fclose and is therefore compliant. + mysql_fclose is on purpose *not* implementing + @code DBUG_ASSERT(file != NULL) @endcode, + since doing so could introduce regressions. +*/ +#ifdef HAVE_PSI_INTERFACE + #define mysql_file_fclose(FD, FL) \ + inline_mysql_file_fclose(__FILE__, __LINE__, FD, FL) +#else + #define mysql_file_fclose(FD, FL) \ + inline_mysql_file_fclose(FD, FL) +#endif + +/** + @def mysql_file_fread(FD, P1, P2, P3) + Instrumented fread. + @c mysql_file_fread is a replacement for @c my_fread. +*/ +#ifdef HAVE_PSI_INTERFACE + #define mysql_file_fread(FD, P1, P2, P3) \ + inline_mysql_file_fread(__FILE__, __LINE__, FD, P1, P2, P3) +#else + #define mysql_file_fread(FD, P1, P2, P3) \ + inline_mysql_file_fread(FD, P1, P2, P3) +#endif + +/** + @def mysql_file_fwrite(FD, P1, P2, P3) + Instrumented fwrite. + @c mysql_file_fwrite is a replacement for @c my_fwrite. +*/ +#ifdef HAVE_PSI_INTERFACE + #define mysql_file_fwrite(FD, P1, P2, P3) \ + inline_mysql_file_fwrite(__FILE__, __LINE__, FD, P1, P2, P3) +#else + #define mysql_file_fwrite(FD, P1, P2, P3) \ + inline_mysql_file_fwrite(FD, P1, P2, P3) +#endif + +/** + @def mysql_file_fseek(FD, P, W, F) + Instrumented fseek. + @c mysql_file_fseek is a replacement for @c my_fseek. +*/ +#ifdef HAVE_PSI_INTERFACE + #define mysql_file_fseek(FD, P, W, F) \ + inline_mysql_file_fseek(__FILE__, __LINE__, FD, P, W, F) +#else + #define mysql_file_fseek(FD, P, W, F) \ + inline_mysql_file_fseek(FD, P, W, F) +#endif + +/** + @def mysql_file_ftell(FD, F) + Instrumented ftell. + @c mysql_file_ftell is a replacement for @c my_ftell. +*/ +#ifdef HAVE_PSI_INTERFACE + #define mysql_file_ftell(FD, F) \ + inline_mysql_file_ftell(__FILE__, __LINE__, FD, F) +#else + #define mysql_file_ftell(FD, F) \ + inline_mysql_file_ftell(FD, F) +#endif + +/** + @def mysql_file_create(K, N, F1, F2, F3) + Instrumented create. + @c mysql_file_create is a replacement for @c my_create. +*/ +#ifdef HAVE_PSI_INTERFACE + #define mysql_file_create(K, N, F1, F2, F3) \ + inline_mysql_file_create(K, __FILE__, __LINE__, N, F1, F2, F3) +#else + #define mysql_file_create(K, N, F1, F2, F3) \ + inline_mysql_file_create(N, F1, F2, F3) +#endif + +/** + @def mysql_file_create_temp(K, T, D, P, M, F) + Instrumented create_temp_file. + @c mysql_file_create_temp is a replacement for @c create_temp_file. +*/ +#ifdef HAVE_PSI_INTERFACE + #define mysql_file_create_temp(K, T, D, P, M, F) \ + inline_mysql_file_create_temp(K, T, D, P, M, F) +#else + #define mysql_file_create_temp(K, T, D, P, M, F) \ + inline_mysql_file_create_temp(T, D, P, M, F) +#endif + +/** + @def mysql_file_open(K, N, F1, F2) + Instrumented open. + @c mysql_file_open is a replacement for @c my_open. +*/ +#ifdef HAVE_PSI_INTERFACE + #define mysql_file_open(K, N, F1, F2) \ + inline_mysql_file_open(K, __FILE__, __LINE__, N, F1, F2) +#else + #define mysql_file_open(K, N, F1, F2) \ + inline_mysql_file_open(N, F1, F2) +#endif + +/** + @def mysql_file_close(FD, F) + Instrumented close. + @c mysql_file_close is a replacement for @c my_close. +*/ +#ifdef HAVE_PSI_INTERFACE + #define mysql_file_close(FD, F) \ + inline_mysql_file_close(__FILE__, __LINE__, FD, F) +#else + #define mysql_file_close(FD, F) \ + inline_mysql_file_close(FD, F) +#endif + +/** + @def mysql_file_read(FD, B, S, F) + Instrumented read. + @c mysql_read is a replacement for @c my_read. +*/ +#ifdef HAVE_PSI_INTERFACE + #define mysql_file_read(FD, B, S, F) \ + inline_mysql_file_read(__FILE__, __LINE__, FD, B, S, F) +#else + #define mysql_file_read(FD, B, S, F) \ + inline_mysql_file_read(FD, B, S, F) +#endif + +/** + @def mysql_file_write(FD, B, S, F) + Instrumented write. + @c mysql_file_write is a replacement for @c my_write. +*/ +#ifdef HAVE_PSI_INTERFACE + #define mysql_file_write(FD, B, S, F) \ + inline_mysql_file_write(__FILE__, __LINE__, FD, B, S, F) +#else + #define mysql_file_write(FD, B, S, F) \ + inline_mysql_file_write(FD, B, S, F) +#endif + +/** + @def mysql_file_pread(FD, B, S, O, F) + Instrumented pread. + @c mysql_pread is a replacement for @c my_pread. +*/ +#ifdef HAVE_PSI_INTERFACE + #define mysql_file_pread(FD, B, S, O, F) \ + inline_mysql_file_pread(__FILE__, __LINE__, FD, B, S, O, F) +#else + #define mysql_file_pread(FD, B, S, O, F) \ + inline_mysql_file_pread(FD, B, S, O, F) +#endif + +/** + @def mysql_file_pwrite(FD, B, S, O, F) + Instrumented pwrite. + @c mysql_file_pwrite is a replacement for @c my_pwrite. +*/ +#ifdef HAVE_PSI_INTERFACE + #define mysql_file_pwrite(FD, B, S, O, F) \ + inline_mysql_file_pwrite(__FILE__, __LINE__, FD, B, S, O, F) +#else + #define mysql_file_pwrite(FD, B, S, O, F) \ + inline_mysql_file_pwrite(FD, B, S, O, F) +#endif + +/** + @def mysql_file_seek(FD, P, W, F) + Instrumented seek. + @c mysql_file_seek is a replacement for @c my_seek. +*/ +#ifdef HAVE_PSI_INTERFACE + #define mysql_file_seek(FD, P, W, F) \ + inline_mysql_file_seek(__FILE__, __LINE__, FD, P, W, F) +#else + #define mysql_file_seek(FD, P, W, F) \ + inline_mysql_file_seek(FD, P, W, F) +#endif + +/** + @def mysql_file_tell(FD, F) + Instrumented tell. + @c mysql_file_tell is a replacement for @c my_tell. +*/ +#ifdef HAVE_PSI_INTERFACE + #define mysql_file_tell(FD, F) \ + inline_mysql_file_tell(__FILE__, __LINE__, FD, F) +#else + #define mysql_file_tell(FD, F) \ + inline_mysql_file_tell(FD, F) +#endif + +/** + @def mysql_file_delete(K, P1, P2) + Instrumented delete. + @c mysql_file_delete is a replacement for @c my_delete. +*/ +#ifdef HAVE_PSI_INTERFACE + #define mysql_file_delete(K, P1, P2) \ + inline_mysql_file_delete(K, __FILE__, __LINE__, P1, P2) +#else + #define mysql_file_delete(K, P1, P2) \ + inline_mysql_file_delete(P1, P2) +#endif + +/** + @def mysql_file_rename(K, P1, P2, P3) + Instrumented rename. + @c mysql_file_rename is a replacement for @c my_rename. +*/ +#ifdef HAVE_PSI_INTERFACE + #define mysql_file_rename(K, P1, P2, P3) \ + inline_mysql_file_rename(K, __FILE__, __LINE__, P1, P2, P3) +#else + #define mysql_file_rename(K, P1, P2, P3) \ + inline_mysql_file_rename(P1, P2, P3) +#endif + +/** + @def mysql_file_create_with_symlink(K, P1, P2, P3, P4, P5) + Instrumented create with symbolic link. + @c mysql_file_create_with_symlink is a replacement + for @c my_create_with_symlink. +*/ +#ifdef HAVE_PSI_INTERFACE + #define mysql_file_create_with_symlink(K, P1, P2, P3, P4, P5) \ + inline_mysql_file_create_with_symlink(K, __FILE__, __LINE__, \ + P1, P2, P3, P4, P5) +#else + #define mysql_file_create_with_symlink(K, P1, P2, P3, P4, P5) \ + inline_mysql_file_create_with_symlink(P1, P2, P3, P4, P5) +#endif + +/** + @def mysql_file_delete_with_symlink(K, P1, P2) + Instrumented delete with symbolic link. + @c mysql_file_delete_with_symlink is a replacement + for @c my_delete_with_symlink. +*/ +#ifdef HAVE_PSI_INTERFACE + #define mysql_file_delete_with_symlink(K, P1, P2) \ + inline_mysql_file_delete_with_symlink(K, __FILE__, __LINE__, P1, P2) +#else + #define mysql_file_delete_with_symlink(K, P1, P2) \ + inline_mysql_file_delete_with_symlink(P1, P2) +#endif + +/** + @def mysql_file_rename_with_symlink(K, P1, P2, P3) + Instrumented rename with symbolic link. + @c mysql_file_rename_with_symlink is a replacement + for @c my_rename_with_symlink. +*/ +#ifdef HAVE_PSI_INTERFACE + #define mysql_file_rename_with_symlink(K, P1, P2, P3) \ + inline_mysql_file_rename_with_symlink(K, __FILE__, __LINE__, P1, P2, P3) +#else + #define mysql_file_rename_with_symlink(K, P1, P2, P3) \ + inline_mysql_file_rename_with_symlink(P1, P2, P3) +#endif + +/** + @def mysql_file_sync(P1, P2) + Instrumented file sync. + @c mysql_file_sync is a replacement for @c my_sync. +*/ +#ifdef HAVE_PSI_INTERFACE + #define mysql_file_sync(P1, P2) \ + inline_mysql_file_sync(__FILE__, __LINE__, P1, P2) +#else + #define mysql_file_sync(P1, P2) \ + inline_mysql_file_sync(P1, P2) +#endif + +/** + An instrumented FILE structure. + @sa MYSQL_FILE +*/ +struct st_mysql_file +{ + /** The real file. */ + FILE *m_file; + /** + The instrumentation hook. + Note that this hook is not conditionally defined, + for binary compatibility of the @c MYSQL_FILE interface. + */ + struct PSI_file *m_psi; +}; + +/** + Type of an instrumented file. + @c MYSQL_FILE is a drop-in replacement for @c FILE. + @sa mysql_file_open +*/ +typedef struct st_mysql_file MYSQL_FILE; + +static inline char * +inline_mysql_file_fgets( +#ifdef HAVE_PSI_INTERFACE + const char *src_file, uint src_line, +#endif + char *str, int size, MYSQL_FILE *file) +{ + char *result; +#ifdef HAVE_PSI_INTERFACE + struct PSI_file_locker *locker= NULL; + if (likely(PSI_server && file->m_psi)) + { + locker= PSI_server->get_thread_file_stream_locker(file->m_psi, + PSI_FILE_READ); + if (likely(locker != NULL)) + PSI_server->start_file_wait(locker, (size_t) size, src_file, src_line); + } +#endif + result= fgets(str, size, file->m_file); +#ifdef HAVE_PSI_INTERFACE + if (likely(locker != NULL)) + PSI_server->end_file_wait(locker, result ? strlen(result) : 0); +#endif + return result; +} + +static inline int +inline_mysql_file_fgetc( +#ifdef HAVE_PSI_INTERFACE + const char *src_file, uint src_line, +#endif + MYSQL_FILE *file) +{ + int result; +#ifdef HAVE_PSI_INTERFACE + struct PSI_file_locker *locker= NULL; + if (likely(PSI_server && file->m_psi)) + { + locker= PSI_server->get_thread_file_stream_locker(file->m_psi, + PSI_FILE_READ); + if (likely(locker != NULL)) + PSI_server->start_file_wait(locker, (size_t) 1, src_file, src_line); + } +#endif + result= fgetc(file->m_file); +#ifdef HAVE_PSI_INTERFACE + if (likely(locker != NULL)) + PSI_server->end_file_wait(locker, (size_t) 1); +#endif + return result; +} + +static inline int +inline_mysql_file_fputs( +#ifdef HAVE_PSI_INTERFACE + const char *src_file, uint src_line, +#endif + const char *str, MYSQL_FILE *file) +{ + int result; +#ifdef HAVE_PSI_INTERFACE + struct PSI_file_locker *locker= NULL; + size_t bytes= 0; + if (likely(PSI_server && file->m_psi)) + { + locker= PSI_server->get_thread_file_stream_locker(file->m_psi, + PSI_FILE_WRITE); + if (likely(locker != NULL)) + { + bytes= str ? strlen(str) : 0; + PSI_server->start_file_wait(locker, bytes, src_file, src_line); + } + } +#endif + result= fputs(str, file->m_file); +#ifdef HAVE_PSI_INTERFACE + if (likely(locker != NULL)) + PSI_server->end_file_wait(locker, bytes); +#endif + return result; +} + +static inline int +inline_mysql_file_fputc( +#ifdef HAVE_PSI_INTERFACE + const char *src_file, uint src_line, +#endif + char c, MYSQL_FILE *file) +{ + int result; +#ifdef HAVE_PSI_INTERFACE + struct PSI_file_locker *locker= NULL; + if (likely(PSI_server && file->m_psi)) + { + locker= PSI_server->get_thread_file_stream_locker(file->m_psi, + PSI_FILE_WRITE); + if (likely(locker != NULL)) + PSI_server->start_file_wait(locker, (size_t) 1, src_file, src_line); + } +#endif + result= fputc(c, file->m_file); +#ifdef HAVE_PSI_INTERFACE + if (likely(locker != NULL)) + PSI_server->end_file_wait(locker, (size_t) 1); +#endif + return result; +} + +static inline int +inline_mysql_file_fprintf(MYSQL_FILE *file, const char *format, ...) +{ + /* + TODO: figure out how to pass src_file and src_line from the caller. + */ + int result; + va_list args; +#ifdef HAVE_PSI_INTERFACE + struct PSI_file_locker *locker= NULL; + if (likely(PSI_server && file->m_psi)) + { + locker= PSI_server->get_thread_file_stream_locker(file->m_psi, + PSI_FILE_WRITE); + if (likely(locker != NULL)) + PSI_server->start_file_wait(locker, (size_t) 0, __FILE__, __LINE__); + } +#endif + va_start(args, format); + result= vfprintf(file->m_file, format, args); + va_end(args); +#ifdef HAVE_PSI_INTERFACE + if (likely(locker != NULL)) + PSI_server->end_file_wait(locker, (size_t) result); +#endif + return result; +} + +static inline int +inline_mysql_file_vfprintf( +#ifdef HAVE_PSI_INTERFACE + const char *src_file, uint src_line, +#endif + MYSQL_FILE *file, const char *format, va_list args) +{ + int result; +#ifdef HAVE_PSI_INTERFACE + struct PSI_file_locker *locker= NULL; + if (likely(PSI_server && file->m_psi)) + { + locker= PSI_server->get_thread_file_stream_locker(file->m_psi, + PSI_FILE_WRITE); + if (likely(locker != NULL)) + PSI_server->start_file_wait(locker, (size_t) 0, src_file, src_line); + } +#endif + result= vfprintf(file->m_file, format, args); +#ifdef HAVE_PSI_INTERFACE + if (likely(locker != NULL)) + PSI_server->end_file_wait(locker, (size_t) result); +#endif + return result; +} + +static inline int +inline_mysql_file_fflush( +#ifdef HAVE_PSI_INTERFACE + const char *src_file, uint src_line, +#endif + MYSQL_FILE *file) +{ + int result; +#ifdef HAVE_PSI_INTERFACE + struct PSI_file_locker *locker= NULL; + if (likely(PSI_server && file->m_psi)) + { + locker= PSI_server->get_thread_file_stream_locker(file->m_psi, + PSI_FILE_FLUSH); + if (likely(locker != NULL)) + PSI_server->start_file_wait(locker, (size_t) 0, src_file, src_line); + } +#endif + result= fflush(file->m_file); +#ifdef HAVE_PSI_INTERFACE + if (likely(locker != NULL)) + PSI_server->end_file_wait(locker, (size_t) 0); +#endif + return result; +} + +static inline int inline_mysql_file_feof(MYSQL_FILE *file) +{ + /* Not instrumented, there is no wait involved */ + return feof(file->m_file); +} + +static inline int +inline_mysql_file_fstat( +#ifdef HAVE_PSI_INTERFACE + const char *src_file, uint src_line, +#endif + int filenr, MY_STAT *stat_area, myf flags) +{ + int result; +#ifdef HAVE_PSI_INTERFACE + struct PSI_file_locker *locker= NULL; + if (likely(PSI_server != NULL)) + { + locker= PSI_server->get_thread_file_descriptor_locker(filenr, + PSI_FILE_FSTAT); + if (likely(locker != NULL)) + PSI_server->start_file_wait(locker, (size_t) 0, src_file, src_line); + } +#endif + result= my_fstat(filenr, stat_area, flags); +#ifdef HAVE_PSI_INTERFACE + if (likely(locker != NULL)) + PSI_server->end_file_wait(locker, (size_t) 0); +#endif + return result; +} + +static inline MY_STAT * +inline_mysql_file_stat( +#ifdef HAVE_PSI_INTERFACE + PSI_file_key key, const char *src_file, uint src_line, +#endif + const char *path, MY_STAT *stat_area, myf flags) +{ + MY_STAT *result; +#ifdef HAVE_PSI_INTERFACE + struct PSI_file_locker *locker= NULL; + if (likely(PSI_server != NULL)) + { + locker= PSI_server->get_thread_file_name_locker(key, PSI_FILE_STAT, + path, &locker); + if (likely(locker != NULL)) + PSI_server->start_file_open_wait(locker, src_file, src_line); + } +#endif + result= my_stat(path, stat_area, flags); +#ifdef HAVE_PSI_INTERFACE + if (likely(locker != NULL)) + PSI_server->end_file_wait(locker, (size_t) 0); +#endif + return result; +} + +static inline int +inline_mysql_file_chsize( +#ifdef HAVE_PSI_INTERFACE + const char *src_file, uint src_line, +#endif + File file, my_off_t newlength, int filler, myf flags) +{ + int result; +#ifdef HAVE_PSI_INTERFACE + struct PSI_file_locker *locker= NULL; + if (likely(PSI_server != NULL)) + { + locker= PSI_server->get_thread_file_descriptor_locker(file, + PSI_FILE_CHSIZE); + if (likely(locker != NULL)) + PSI_server->start_file_wait(locker, (size_t) newlength, src_file, + src_line); + } +#endif + result= my_chsize(file, newlength, filler, flags); +#ifdef HAVE_PSI_INTERFACE + if (likely(locker != NULL)) + PSI_server->end_file_wait(locker, (size_t) newlength); +#endif + return result; +} + +static inline MYSQL_FILE* +inline_mysql_file_fopen( +#ifdef HAVE_PSI_INTERFACE + PSI_file_key key, const char *src_file, uint src_line, +#endif + const char *filename, int flags, myf myFlags) +{ + MYSQL_FILE *that; + that= (MYSQL_FILE*) my_malloc(sizeof(MYSQL_FILE), MYF(MY_WME)); + if (likely(that != NULL)) + { + that->m_psi= NULL; + { +#ifdef HAVE_PSI_INTERFACE + struct PSI_file_locker *locker= NULL; + if (likely(PSI_server != NULL)) + { + locker= PSI_server->get_thread_file_name_locker + (key, PSI_FILE_STREAM_OPEN, filename, that); + if (likely(locker != NULL)) + that->m_psi= PSI_server->start_file_open_wait(locker, src_file, + src_line); + } +#endif + that->m_file= my_fopen(filename, flags, myFlags); +#ifdef HAVE_PSI_INTERFACE + if (likely(locker != NULL)) + PSI_server->end_file_open_wait(locker); +#endif + if (unlikely(that->m_file == NULL)) + { + my_free(that, MYF(0)); + return NULL; + } + } + } + return that; +} + +static inline int +inline_mysql_file_fclose( +#ifdef HAVE_PSI_INTERFACE + const char *src_file, uint src_line, +#endif + MYSQL_FILE *file, myf flags) +{ + int result= 0; + if (likely(file != NULL)) + { +#ifdef HAVE_PSI_INTERFACE + struct PSI_file_locker *locker= NULL; + DBUG_ASSERT(file != NULL); + if (likely(PSI_server && file->m_psi)) + { + locker= PSI_server->get_thread_file_stream_locker(file->m_psi, + PSI_FILE_STREAM_CLOSE); + if (likely(locker != NULL)) + PSI_server->start_file_wait(locker, (size_t) 0, src_file, src_line); + } +#endif + result= my_fclose(file->m_file, flags); +#ifdef HAVE_PSI_INTERFACE + if (likely(locker != NULL)) + PSI_server->end_file_wait(locker, (size_t) 0); +#endif + my_free(file, MYF(0)); + } + return result; +} + +static inline size_t +inline_mysql_file_fread( +#ifdef HAVE_PSI_INTERFACE + const char *src_file, uint src_line, +#endif + MYSQL_FILE *file, uchar *buffer, size_t count, myf flags) +{ + size_t result= 0; +#ifdef HAVE_PSI_INTERFACE + struct PSI_file_locker *locker= NULL; + if (likely(PSI_server && file->m_psi)) + { + locker= PSI_server->get_thread_file_stream_locker(file->m_psi, + PSI_FILE_READ); + if (likely(locker != NULL)) + PSI_server->start_file_wait(locker, count, src_file, src_line); + } +#endif + result= my_fread(file->m_file, buffer, count, flags); +#ifdef HAVE_PSI_INTERFACE + if (likely(locker != NULL)) + { + size_t bytes_read; + if (flags & (MY_NABP | MY_FNABP)) + bytes_read= (result == 0) ? count : 0; + else + bytes_read= (result != MY_FILE_ERROR) ? result : 0; + PSI_server->end_file_wait(locker, bytes_read); + } +#endif + return result; +} + +static inline size_t +inline_mysql_file_fwrite( +#ifdef HAVE_PSI_INTERFACE + const char *src_file, uint src_line, +#endif + MYSQL_FILE *file, const uchar *buffer, size_t count, myf flags) +{ + size_t result= 0; +#ifdef HAVE_PSI_INTERFACE + struct PSI_file_locker *locker= NULL; + if (likely(PSI_server && file->m_psi)) + { + locker= PSI_server->get_thread_file_stream_locker(file->m_psi, + PSI_FILE_WRITE); + if (likely(locker != NULL)) + PSI_server->start_file_wait(locker, count, src_file, src_line); + } +#endif + result= my_fwrite(file->m_file, buffer, count, flags); +#ifdef HAVE_PSI_INTERFACE + if (likely(locker != NULL)) + { + size_t bytes_written; + if (flags & (MY_NABP | MY_FNABP)) + bytes_written= (result == 0) ? count : 0; + else + bytes_written= (result != MY_FILE_ERROR) ? result : 0; + PSI_server->end_file_wait(locker, bytes_written); + } +#endif + return result; +} + +static inline my_off_t +inline_mysql_file_fseek( +#ifdef HAVE_PSI_INTERFACE + const char *src_file, uint src_line, +#endif + MYSQL_FILE *file, my_off_t pos, int whence, myf flags) +{ + my_off_t result; +#ifdef HAVE_PSI_INTERFACE + struct PSI_file_locker *locker= NULL; + if (likely(PSI_server && file->m_psi)) + { + locker= PSI_server->get_thread_file_stream_locker(file->m_psi, + PSI_FILE_SEEK); + if (likely(locker != NULL)) + PSI_server->start_file_wait(locker, (size_t) 0, src_file, src_line); + } +#endif + result= my_fseek(file->m_file, pos, whence, flags); +#ifdef HAVE_PSI_INTERFACE + if (likely(locker != NULL)) + PSI_server->end_file_wait(locker, (size_t) 0); +#endif + return result; +} + +static inline my_off_t +inline_mysql_file_ftell( +#ifdef HAVE_PSI_INTERFACE + const char *src_file, uint src_line, +#endif + MYSQL_FILE *file, myf flags) +{ + my_off_t result; +#ifdef HAVE_PSI_INTERFACE + struct PSI_file_locker *locker= NULL; + if (likely(PSI_server && file->m_psi)) + { + locker= PSI_server->get_thread_file_stream_locker(file->m_psi, + PSI_FILE_TELL); + if (likely(locker != NULL)) + PSI_server->start_file_wait(locker, (size_t) 0, src_file, src_line); + } +#endif + result= my_ftell(file->m_file, flags); +#ifdef HAVE_PSI_INTERFACE + if (likely(locker != NULL)) + PSI_server->end_file_wait(locker, (size_t) 0); +#endif + return result; +} + +static inline File +inline_mysql_file_create( +#ifdef HAVE_PSI_INTERFACE + PSI_file_key key, const char *src_file, uint src_line, +#endif + const char *filename, int create_flags, int access_flags, myf myFlags) +{ + File file; +#ifdef HAVE_PSI_INTERFACE + struct PSI_file_locker *locker= NULL; + if (likely(PSI_server != NULL)) + { + locker= PSI_server->get_thread_file_name_locker(key, PSI_FILE_CREATE, + filename, &locker); + if (likely(locker != NULL)) + PSI_server->start_file_open_wait(locker, src_file, src_line); + } +#endif + file= my_create(filename, create_flags, access_flags, myFlags); +#ifdef HAVE_PSI_INTERFACE + if (likely(locker != NULL)) + PSI_server->end_file_open_wait_and_bind_to_descriptor(locker, file); +#endif + return file; +} + +static inline File +inline_mysql_file_create_temp( +#ifdef HAVE_PSI_INTERFACE + PSI_file_key key, +#endif + char *to, const char *dir, const char *pfx, int mode, myf myFlags) +{ + File file; + /* + TODO: This event is instrumented, but not timed. + The problem is that the file name is now known + before the create_temp_file call. + */ + file= create_temp_file(to, dir, pfx, mode, myFlags); +#ifdef HAVE_PSI_INTERFACE + if (likely(PSI_server != NULL)) + PSI_server->create_file(key, to, file); +#endif + return file; +} + +static inline File +inline_mysql_file_open( +#ifdef HAVE_PSI_INTERFACE + PSI_file_key key, const char *src_file, uint src_line, +#endif + const char *filename, int flags, myf myFlags) +{ + File file; +#ifdef HAVE_PSI_INTERFACE + struct PSI_file_locker *locker= NULL; + if (likely(PSI_server != NULL)) + { + locker= PSI_server->get_thread_file_name_locker(key, PSI_FILE_OPEN, + filename, &locker); + if (likely(locker != NULL)) + PSI_server->start_file_open_wait(locker, src_file, src_line); + } +#endif + file= my_open(filename, flags, myFlags); +#ifdef HAVE_PSI_INTERFACE + if (likely(locker != NULL)) + PSI_server->end_file_open_wait_and_bind_to_descriptor(locker, file); +#endif + return file; +} + +static inline int +inline_mysql_file_close( +#ifdef HAVE_PSI_INTERFACE + const char *src_file, uint src_line, +#endif + File file, myf flags) +{ + int result; +#ifdef HAVE_PSI_INTERFACE + struct PSI_file_locker *locker= NULL; + if (likely(PSI_server != NULL)) + { + locker= PSI_server->get_thread_file_descriptor_locker(file, + PSI_FILE_CLOSE); + if (likely(locker != NULL)) + PSI_server->start_file_wait(locker, (size_t) 0, src_file, src_line); + } +#endif + result= my_close(file, flags); +#ifdef HAVE_PSI_INTERFACE + if (likely(locker != NULL)) + PSI_server->end_file_wait(locker, (size_t) 0); +#endif + return result; +} + +static inline size_t +inline_mysql_file_read( +#ifdef HAVE_PSI_INTERFACE + const char *src_file, uint src_line, +#endif + File file, uchar *buffer, size_t count, myf flags) +{ + size_t result= 0; +#ifdef HAVE_PSI_INTERFACE + struct PSI_file_locker *locker= NULL; + if (likely(PSI_server != NULL)) + { + locker= PSI_server->get_thread_file_descriptor_locker(file, + PSI_FILE_READ); + if (likely(locker != NULL)) + PSI_server->start_file_wait(locker, count, src_file, src_line); + } +#endif + result= my_read(file, buffer, count, flags); +#ifdef HAVE_PSI_INTERFACE + if (likely(locker != NULL)) + { + size_t bytes_read; + if (flags & (MY_NABP | MY_FNABP)) + bytes_read= (result == 0) ? count : 0; + else + bytes_read= (result != MY_FILE_ERROR) ? result : 0; + PSI_server->end_file_wait(locker, bytes_read); + } +#endif + return result; +} + +static inline size_t +inline_mysql_file_write( +#ifdef HAVE_PSI_INTERFACE + const char *src_file, uint src_line, +#endif + File file, const uchar *buffer, size_t count, myf flags) +{ + size_t result; +#ifdef HAVE_PSI_INTERFACE + struct PSI_file_locker *locker= NULL; + if (likely(PSI_server != NULL)) + { + locker= PSI_server->get_thread_file_descriptor_locker(file, + PSI_FILE_WRITE); + if (likely(locker != NULL)) + PSI_server->start_file_wait(locker, count, src_file, src_line); + } +#endif + result= my_write(file, buffer, count, flags); +#ifdef HAVE_PSI_INTERFACE + if (likely(locker != NULL)) + { + size_t bytes_written; + if (flags & (MY_NABP | MY_FNABP)) + bytes_written= (result == 0) ? count : 0; + else + bytes_written= (result != MY_FILE_ERROR) ? result : 0; + PSI_server->end_file_wait(locker, bytes_written); + } +#endif + return result; +} + +static inline size_t +inline_mysql_file_pread( +#ifdef HAVE_PSI_INTERFACE + const char *src_file, uint src_line, +#endif + File file, uchar *buffer, size_t count, my_off_t offset, myf flags) +{ + size_t result; +#ifdef HAVE_PSI_INTERFACE + struct PSI_file_locker *locker= NULL; + if (likely(PSI_server != NULL)) + { + locker= PSI_server->get_thread_file_descriptor_locker(file, PSI_FILE_READ); + if (likely(locker != NULL)) + PSI_server->start_file_wait(locker, count, src_file, src_line); + } +#endif + result= my_pread(file, buffer, count, offset, flags); +#ifdef HAVE_PSI_INTERFACE + if (likely(locker != NULL)) + { + size_t bytes_read; + if (flags & (MY_NABP | MY_FNABP)) + bytes_read= (result == 0) ? count : 0; + else + bytes_read= (result != MY_FILE_ERROR) ? result : 0; + PSI_server->end_file_wait(locker, bytes_read); + } +#endif + return result; +} + +static inline size_t +inline_mysql_file_pwrite( +#ifdef HAVE_PSI_INTERFACE + const char *src_file, uint src_line, +#endif + File file, const uchar *buffer, size_t count, my_off_t offset, myf flags) +{ + size_t result; +#ifdef HAVE_PSI_INTERFACE + struct PSI_file_locker *locker= NULL; + if (likely(PSI_server != NULL)) + { + locker= PSI_server->get_thread_file_descriptor_locker(file, + PSI_FILE_WRITE); + if (likely(locker != NULL)) + PSI_server->start_file_wait(locker, count, src_file, src_line); + } +#endif + result= my_pwrite(file, buffer, count, offset, flags); +#ifdef HAVE_PSI_INTERFACE + if (likely(locker != NULL)) + { + size_t bytes_written; + if (flags & (MY_NABP | MY_FNABP)) + bytes_written= (result == 0) ? count : 0; + else + bytes_written= (result != MY_FILE_ERROR) ? result : 0; + PSI_server->end_file_wait(locker, bytes_written); + } +#endif + return result; +} + +static inline my_off_t +inline_mysql_file_seek( +#ifdef HAVE_PSI_INTERFACE + const char *src_file, uint src_line, +#endif + File file, my_off_t pos, int whence, myf flags) +{ + my_off_t result; +#ifdef HAVE_PSI_INTERFACE + struct PSI_file_locker *locker= NULL; + if (likely(PSI_server != NULL)) + { + locker= PSI_server->get_thread_file_descriptor_locker(file, PSI_FILE_SEEK); + if (likely(locker != NULL)) + PSI_server->start_file_wait(locker, (size_t) 0, src_file, src_line); + } +#endif + result= my_seek(file, pos, whence, flags); +#ifdef HAVE_PSI_INTERFACE + if (likely(locker != NULL)) + PSI_server->end_file_wait(locker, (size_t) 0); +#endif + return result; +} + +static inline my_off_t +inline_mysql_file_tell( +#ifdef HAVE_PSI_INTERFACE + const char *src_file, uint src_line, +#endif + File file, myf flags) +{ + my_off_t result; +#ifdef HAVE_PSI_INTERFACE + struct PSI_file_locker *locker= NULL; + if (likely(PSI_server != NULL)) + { + locker= PSI_server->get_thread_file_descriptor_locker(file, PSI_FILE_TELL); + if (likely(locker != NULL)) + PSI_server->start_file_wait(locker, (size_t) 0, src_file, src_line); + } +#endif + result= my_tell(file, flags); +#ifdef HAVE_PSI_INTERFACE + if (likely(locker != NULL)) + PSI_server->end_file_wait(locker, (size_t) 0); +#endif + return result; +} + +static inline int +inline_mysql_file_delete( +#ifdef HAVE_PSI_INTERFACE + PSI_file_key key, const char *src_file, uint src_line, +#endif + const char *name, myf flags) +{ + int result; +#ifdef HAVE_PSI_INTERFACE + struct PSI_file_locker *locker= NULL; + if (likely(PSI_server != NULL)) + { + locker= PSI_server->get_thread_file_name_locker(key, PSI_FILE_DELETE, + name, &locker); + if (likely(locker != NULL)) + PSI_server->start_file_wait(locker, (size_t) 0, src_file, src_line); + } +#endif + result= my_delete(name, flags); +#ifdef HAVE_PSI_INTERFACE + if (likely(locker != NULL)) + PSI_server->end_file_wait(locker, (size_t) 0); +#endif + return result; +} + +static inline int +inline_mysql_file_rename( +#ifdef HAVE_PSI_INTERFACE + PSI_file_key key, const char *src_file, uint src_line, +#endif + const char *from, const char *to, myf flags) +{ + int result; +#ifdef HAVE_PSI_INTERFACE + struct PSI_file_locker *locker= NULL; + if (likely(PSI_server != NULL)) + { + locker= PSI_server->get_thread_file_name_locker(key, PSI_FILE_RENAME, + to, &locker); + if (likely(locker != NULL)) + PSI_server->start_file_wait(locker, (size_t) 0, src_file, src_line); + } +#endif + result= my_rename(from, to, flags); +#ifdef HAVE_PSI_INTERFACE + if (likely(locker != NULL)) + PSI_server->end_file_wait(locker, (size_t) 0); +#endif + return result; +} + +static inline File +inline_mysql_file_create_with_symlink( +#ifdef HAVE_PSI_INTERFACE + PSI_file_key key, const char *src_file, uint src_line, +#endif + const char *linkname, const char *filename, int create_flags, + int access_flags, myf flags) +{ + File file; +#ifdef HAVE_PSI_INTERFACE + struct PSI_file_locker *locker= NULL; + if (likely(PSI_server != NULL)) + { + locker= PSI_server->get_thread_file_name_locker(key, PSI_FILE_CREATE, + filename, &locker); + if (likely(locker != NULL)) + PSI_server->start_file_open_wait(locker, src_file, src_line); + } +#endif + file= my_create_with_symlink(linkname, filename, create_flags, access_flags, + flags); +#ifdef HAVE_PSI_INTERFACE + if (likely(locker != NULL)) + PSI_server->end_file_open_wait_and_bind_to_descriptor(locker, file); +#endif + return file; +} + +static inline int +inline_mysql_file_delete_with_symlink( +#ifdef HAVE_PSI_INTERFACE + PSI_file_key key, const char *src_file, uint src_line, +#endif + const char *name, myf flags) +{ + int result; +#ifdef HAVE_PSI_INTERFACE + struct PSI_file_locker *locker= NULL; + if (likely(PSI_server != NULL)) + { + locker= PSI_server->get_thread_file_name_locker(key, PSI_FILE_DELETE, + name, &locker); + if (likely(locker != NULL)) + PSI_server->start_file_wait(locker, (size_t) 0, src_file, src_line); + } +#endif + result= my_delete_with_symlink(name, flags); +#ifdef HAVE_PSI_INTERFACE + if (likely(locker != NULL)) + PSI_server->end_file_wait(locker, (size_t) 0); +#endif + return result; +} + +static inline int +inline_mysql_file_rename_with_symlink( +#ifdef HAVE_PSI_INTERFACE + PSI_file_key key, const char *src_file, uint src_line, +#endif + const char *from, const char *to, myf flags) +{ + int result; +#ifdef HAVE_PSI_INTERFACE + struct PSI_file_locker *locker= NULL; + if (likely(PSI_server != NULL)) + { + locker= PSI_server->get_thread_file_name_locker(key, PSI_FILE_RENAME, + to, &locker); + if (likely(locker != NULL)) + PSI_server->start_file_wait(locker, (size_t) 0, src_file, src_line); + } +#endif + result= my_rename_with_symlink(from, to, flags); +#ifdef HAVE_PSI_INTERFACE + if (likely(locker != NULL)) + PSI_server->end_file_wait(locker, (size_t) 0); +#endif + return result; +} + +static inline int +inline_mysql_file_sync( +#ifdef HAVE_PSI_INTERFACE + const char *src_file, uint src_line, +#endif + File fd, myf flags) +{ + int result= 0; +#ifdef HAVE_PSI_INTERFACE + struct PSI_file_locker *locker= NULL; + if (likely(PSI_server != NULL)) + { + locker= PSI_server->get_thread_file_descriptor_locker(fd, PSI_FILE_SYNC); + if (likely(locker != NULL)) + PSI_server->start_file_wait(locker, (size_t) 0, src_file, src_line); + } +#endif + result= my_sync(fd, flags); +#ifdef HAVE_PSI_INTERFACE + if (likely(locker != NULL)) + PSI_server->end_file_wait(locker, (size_t) 0); +#endif + return result; +} + +/** @} (end of group File_instrumentation) */ + +#endif + diff --git a/include/mysql/psi/mysql_thread.h b/include/mysql/psi/mysql_thread.h new file mode 100644 index 00000000000..18c4daa0cf2 --- /dev/null +++ b/include/mysql/psi/mysql_thread.h @@ -0,0 +1,884 @@ +/* Copyright (C) 2008-2009 Sun Microsystems, Inc + + 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 + the Free Software Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + +#ifndef MYSQL_THREAD_H +#define MYSQL_THREAD_H + +/** + @file mysql/psi/mysql_thread.h + Instrumentation helpers for mysys threads, mutexes, + read write locks and conditions. + This header file provides the necessary declarations + to use the mysys thread API with the performance schema instrumentation. + In some compilers (SunStudio), 'static inline' functions, when declared + but not used, are not optimized away (because they are unused) by default, + so that including a static inline function from a header file does + create unwanted dependencies, causing unresolved symbols at link time. + Other compilers, like gcc, optimize these dependencies by default. + + Since the instrumented APIs declared here are wrapper on top + of my_pthread / safemutex / etc APIs, + including mysql/psi/mysql_thread.h assumes that + the dependency on my_pthread and safemutex already exists. +*/ +/* + Note: there are several orthogonal dimensions here. + + Dimension 1: Instrumentation + HAVE_PSI_INTERFACE is defined when the instrumentation is compiled in. + This may happen both in debug or production builds. + + Dimension 2: Debug + SAFE_MUTEX is defined when debug is compiled in. + This may happen both with and without instrumentation. + + Dimension 3: Platform + Mutexes are implemented with one of: + - the pthread library + - fast mutexes + - window apis + This is implemented by various macro definitions in my_pthread.h + + This causes complexity with '#ifdef'-ery that can't be avoided. +*/ + +#include "mysql/psi/psi.h" + +/** + @defgroup Thread_instrumentation Thread Instrumentation + @ingroup Instrumentation_interface + @{ +*/ + +/** + An instrumented mutex structure. + @sa mysql_mutex_t +*/ +struct st_mysql_mutex +{ + /** The real mutex. */ + pthread_mutex_t m_mutex; + /** + The instrumentation hook. + Note that this hook is not conditionally defined, + for binary compatibility of the @c mysql_mutex_t interface. + */ + struct PSI_mutex *m_psi; +}; + +/** + Type of an instrumented mutex. + @c mysql_mutex_t is a drop-in replacement for @c pthread_mutex_t. + @sa mysql_mutex_assert_owner + @sa mysql_mutex_assert_not_owner + @sa mysql_mutex_init + @sa mysql_mutex_lock + @sa mysql_mutex_unlock + @sa mysql_mutex_destroy +*/ +typedef struct st_mysql_mutex mysql_mutex_t; + +/** + An instrumented rwlock structure. + @sa mysql_rwlock_t +*/ +struct st_mysql_rwlock +{ + /** The real rwlock */ + rw_lock_t m_rwlock; + /** + The instrumentation hook. + Note that this hook is not conditionally defined, + for binary compatibility of the @c mysql_rwlock_t interface. + */ + struct PSI_rwlock *m_psi; +}; + +/** + Type of an instrumented rwlock. + @c mysql_rwlock_t is a drop-in replacement for @c pthread_rwlock_t. + @sa mysql_rwlock_init + @sa mysql_rwlock_rdlock + @sa mysql_rwlock_tryrdlock + @sa mysql_rwlock_wrlock + @sa mysql_rwlock_trywrlock + @sa mysql_rwlock_unlock + @sa mysql_rwlock_destroy +*/ +typedef struct st_mysql_rwlock mysql_rwlock_t; + +/** + An instrumented cond structure. + @sa mysql_cond_t +*/ +struct st_mysql_cond +{ + /** The real condition */ + pthread_cond_t m_cond; + /** + The instrumentation hook. + Note that this hook is not conditionally defined, + for binary compatibility of the @c mysql_cond_t interface. + */ + struct PSI_cond *m_psi; +}; + +/** + Type of an instrumented condition. + @c mysql_cond_t is a drop-in replacement for @c pthread_cond_t. + @sa mysql_cond_init + @sa mysql_cond_wait + @sa mysql_cond_timedwait + @sa mysql_cond_signal + @sa mysql_cond_broadcast + @sa mysql_cond_destroy +*/ +typedef struct st_mysql_cond mysql_cond_t; + +/* + Consider the following code: + static inline void foo() { bar(); } + when foo() is never called. + + With gcc, foo() is a local static function, so the dependencies + are optimized away at compile time, and there is no dependency on bar(). + With other compilers (HP, Sun Studio), the function foo() implementation + is compiled, and bar() needs to be present to link. + + Due to the existing header dependencies in MySQL code, this header file + is sometime used when it is not needed, which in turn cause link failures + on some platforms. + The proper fix would be to cut these extra dependencies in the calling code. + DISABLE_MYSQL_THREAD_H is a work around to limit dependencies. +*/ +#ifndef DISABLE_MYSQL_THREAD_H + +/** + @def mysql_mutex_assert_owner(M) + Wrapper, to use safe_mutex_assert_owner with instrumented mutexes. + @c mysql_mutex_assert_owner is a drop-in replacement + for @c safe_mutex_assert_owner. +*/ +#define mysql_mutex_assert_owner(M) \ + safe_mutex_assert_owner(&(M)->m_mutex) + +/** + @def mysql_mutex_assert_not_owner(M) + Wrapper, to use safe_mutex_assert_not_owner with instrumented mutexes. + @c mysql_mutex_assert_not_owner is a drop-in replacement + for @c safe_mutex_assert_not_owner. +*/ +#define mysql_mutex_assert_not_owner(M) \ + safe_mutex_assert_not_owner(&(M)->m_mutex) + +/** + @def mysql_mutex_init(K, M, A) + Instrumented mutex_init. + @c mysql_mutex_init is a replacement for @c pthread_mutex_init. + @param K The PSI_mutex_key for this instrumented mutex + @param M The mutex to initialize + @param A Mutex attributes +*/ + +#ifdef HAVE_PSI_INTERFACE + #ifdef SAFE_MUTEX + #define mysql_mutex_init(K, M, A) \ + inline_mysql_mutex_init(K, M, A, __FILE__, __LINE__) + #else + #define mysql_mutex_init(K, M, A) \ + inline_mysql_mutex_init(K, M, A) + #endif +#else + #ifdef SAFE_MUTEX + #define mysql_mutex_init(K, M, A) \ + inline_mysql_mutex_init(M, A, __FILE__, __LINE__) + #else + #define mysql_mutex_init(K, M, A) \ + inline_mysql_mutex_init(M, A) + #endif +#endif + +/** + @def mysql_mutex_destroy(M) + Instrumented mutex_destroy. + @c mysql_mutex_destroy is a drop-in replacement + for @c pthread_mutex_destroy. +*/ +#ifdef SAFE_MUTEX + #define mysql_mutex_destroy(M) \ + inline_mysql_mutex_destroy(M, __FILE__, __LINE__) +#else + #define mysql_mutex_destroy(M) \ + inline_mysql_mutex_destroy(M) +#endif + +/** + @def mysql_mutex_lock(M) + Instrumented mutex_lock. + @c mysql_mutex_lock is a drop-in replacement for @c pthread_mutex_lock. + @param M The mutex to lock +*/ + +#if defined(SAFE_MUTEX) || defined (HAVE_PSI_INTERFACE) + #define mysql_mutex_lock(M) \ + inline_mysql_mutex_lock(M, __FILE__, __LINE__) +#else + #define mysql_mutex_lock(M) \ + inline_mysql_mutex_lock(M) +#endif + +/** + @def mysql_mutex_trylock(M) + Instrumented mutex_lock. + @c mysql_mutex_trylock is a drop-in replacement + for @c pthread_mutex_trylock. +*/ + +#if defined(SAFE_MUTEX) || defined (HAVE_PSI_INTERFACE) + #define mysql_mutex_trylock(M) \ + inline_mysql_mutex_trylock(M, __FILE__, __LINE__) +#else + #define mysql_mutex_trylock(M) \ + inline_mysql_mutex_trylock(M) +#endif + +/** + @def mysql_mutex_unlock(M) + Instrumented mutex_unlock. + @c mysql_mutex_unlock is a drop-in replacement for @c pthread_mutex_unlock. +*/ +#ifdef SAFE_MUTEX + #define mysql_mutex_unlock(M) \ + inline_mysql_mutex_unlock(M, __FILE__, __LINE__) +#else + #define mysql_mutex_unlock(M) \ + inline_mysql_mutex_unlock(M) +#endif + +/** + @def mysql_rwlock_init(K, RW) + Instrumented rwlock_init. + @c mysql_rwlock_init is a replacement for @c pthread_rwlock_init. + Note that pthread_rwlockattr_t is not supported in MySQL. + @param K The PSI_rwlock_key for this instrumented rwlock + @param RW The rwlock to initialize +*/ +#ifdef HAVE_PSI_INTERFACE + #define mysql_rwlock_init(K, RW) inline_mysql_rwlock_init(K, RW) +#else + #define mysql_rwlock_init(K, RW) inline_mysql_rwlock_init(RW) +#endif + +/** + @def mysql_rwlock_destroy(RW) + Instrumented rwlock_destroy. + @c mysql_rwlock_destroy is a drop-in replacement + for @c pthread_rwlock_destroy. +*/ +#define mysql_rwlock_destroy(RW) inline_mysql_rwlock_destroy(RW) + +/** + @def mysql_rwlock_rdlock(RW) + Instrumented rwlock_rdlock. + @c mysql_rwlock_rdlock is a drop-in replacement + for @c pthread_rwlock_rdlock. +*/ +#ifdef HAVE_PSI_INTERFACE + #define mysql_rwlock_rdlock(RW) \ + inline_mysql_rwlock_rdlock(RW, __FILE__, __LINE__) +#else + #define mysql_rwlock_rdlock(RW) \ + inline_mysql_rwlock_rdlock(RW) +#endif + +/** + @def mysql_rwlock_wrlock(RW) + Instrumented rwlock_wrlock. + @c mysql_rwlock_wrlock is a drop-in replacement + for @c pthread_rwlock_wrlock. +*/ +#ifdef HAVE_PSI_INTERFACE + #define mysql_rwlock_wrlock(RW) \ + inline_mysql_rwlock_wrlock(RW, __FILE__, __LINE__) +#else + #define mysql_rwlock_wrlock(RW) \ + inline_mysql_rwlock_wrlock(RW) +#endif + +/** + @def mysql_rwlock_tryrdlock(RW) + Instrumented rwlock_tryrdlock. + @c mysql_rwlock_tryrdlock is a drop-in replacement + for @c pthread_rwlock_tryrdlock. +*/ +#ifdef HAVE_PSI_INTERFACE + #define mysql_rwlock_tryrdlock(RW) \ + inline_mysql_rwlock_tryrdlock(RW, __FILE__, __LINE__) +#else + #define mysql_rwlock_tryrdlock(RW) \ + inline_mysql_rwlock_tryrdlock(RW) +#endif + +/** + @def mysql_rwlock_trywrlock(RW) + Instrumented rwlock_trywrlock. + @c mysql_rwlock_trywrlock is a drop-in replacement + for @c pthread_rwlock_trywrlock. +*/ +#ifdef HAVE_PSI_INTERFACE + #define mysql_rwlock_trywrlock(RW) \ + inline_mysql_rwlock_trywrlock(RW, __FILE__, __LINE__) +#else + #define mysql_rwlock_trywrlock(RW) \ + inline_mysql_rwlock_trywrlock(RW) +#endif + +/** + @def mysql_rwlock_unlock(RW) + Instrumented rwlock_unlock. + @c mysql_rwlock_unlock is a drop-in replacement + for @c pthread_rwlock_unlock. +*/ +#define mysql_rwlock_unlock(RW) inline_mysql_rwlock_unlock(RW) + +/** + @def mysql_cond_init(K, C, A) + Instrumented rwlock_init. + @c mysql_cond_init is a replacement for @c pthread_cond_init. + @param C The cond to initialize + @param K The PSI_cond_key for this instrumented cond + @param A Condition attributes +*/ +#ifdef HAVE_PSI_INTERFACE + #define mysql_cond_init(K, C, A) inline_mysql_cond_init(K, C, A) +#else + #define mysql_cond_init(K, C, A) inline_mysql_cond_init(C, A) +#endif + +/** + @def mysql_cond_destroy(C) + Instrumented cond_destroy. + @c mysql_cond_destroy is a drop-in replacement for @c pthread_cond_destroy. +*/ +#define mysql_cond_destroy(C) inline_mysql_cond_destroy(C) + +/** + @def mysql_cond_wait(C) + Instrumented cond_wait. + @c mysql_cond_wait is a drop-in replacement for @c pthread_cond_wait. +*/ +#ifdef HAVE_PSI_INTERFACE + #define mysql_cond_wait(C, M) \ + inline_mysql_cond_wait(C, M, __FILE__, __LINE__) +#else + #define mysql_cond_wait(C, M) \ + inline_mysql_cond_wait(C, M) +#endif + +/** + @def mysql_cond_timedwait(C, M, W) + Instrumented cond_timedwait. + @c mysql_cond_timedwait is a drop-in replacement + for @c pthread_cond_timedwait. +*/ +#ifdef HAVE_PSI_INTERFACE + #define mysql_cond_timedwait(C, M, W) \ + inline_mysql_cond_timedwait(C, M, W, __FILE__, __LINE__) +#else + #define mysql_cond_timedwait(C, M, W) \ + inline_mysql_cond_timedwait(C, M, W) +#endif + +/** + @def mysql_cond_signal(C) + Instrumented cond_signal. + @c mysql_cond_signal is a drop-in replacement for @c pthread_cond_signal. +*/ +#define mysql_cond_signal(C) inline_mysql_cond_signal(C) + +/** + @def mysql_cond_broadcast(C) + Instrumented cond_broadcast. + @c mysql_cond_broadcast is a drop-in replacement + for @c pthread_cond_broadcast. +*/ +#define mysql_cond_broadcast(C) inline_mysql_cond_broadcast(C) + + +/** + @def mysql_thread_create(K, P1, P2, P3, P4) + Instrumented pthread_create. + This function creates both the thread instrumentation and a thread. + @c mysql_thread_create is a replacement for @c pthread_create. + The parameter P4 (or, if it is NULL, P1) will be used as the + instrumented thread "indentity". + Providing a P1 / P4 parameter with a different value for each call + will on average improve performances, since this thread identity value + is used internally to randomize access to data and prevent contention. + This is optional, and the improvement is not guaranteed, only statistical. + @param K The PSI_thread_key for this instrumented thread + @param P1 pthread_create parameter 1 + @param P2 pthread_create parameter 2 + @param P3 pthread_create parameter 3 + @param P4 pthread_create parameter 4 +*/ +#ifdef HAVE_PSI_INTERFACE + #define mysql_thread_create(K, P1, P2, P3, P4) \ + inline_mysql_thread_create(K, P1, P2, P3, P4) +#else + #define mysql_thread_create(K, P1, P2, P3, P4) \ + pthread_create(P1, P2, P3, P4) +#endif + +/** + @def mysql_thread_set_psi_id(I) + Set the thread indentifier for the instrumentation. + @param I The thread identifier +*/ +#ifdef HAVE_PSI_INTERFACE + #define mysql_thread_set_psi_id(I) inline_mysql_thread_set_psi_id(I) +#else + #define mysql_thread_set_psi_id(I) do {} while (0) +#endif + +static inline int inline_mysql_mutex_init( +#ifdef HAVE_PSI_INTERFACE + PSI_mutex_key key, +#endif + mysql_mutex_t *that, + const pthread_mutexattr_t *attr +#ifdef SAFE_MUTEX + , const char *src_file, uint src_line +#endif + ) +{ +#ifdef HAVE_PSI_INTERFACE + that->m_psi= PSI_server ? PSI_server->init_mutex(key, &that->m_mutex) + : NULL; +#else + that->m_psi= NULL; +#endif +#ifdef SAFE_MUTEX + return safe_mutex_init(&that->m_mutex, attr, src_file, src_line); +#else + return pthread_mutex_init(&that->m_mutex, attr); +#endif +} + +static inline int inline_mysql_mutex_destroy( + mysql_mutex_t *that +#ifdef SAFE_MUTEX + , const char *src_file, uint src_line +#endif + ) +{ +#ifdef HAVE_PSI_INTERFACE + if (likely(PSI_server && that->m_psi)) + { + PSI_server->destroy_mutex(that->m_psi); + that->m_psi= NULL; + } +#endif +#ifdef SAFE_MUTEX + return safe_mutex_destroy(&that->m_mutex, src_file, src_line); +#else + return pthread_mutex_destroy(&that->m_mutex); +#endif +} + +static inline int inline_mysql_mutex_lock( + mysql_mutex_t *that +#if defined(SAFE_MUTEX) || defined (HAVE_PSI_INTERFACE) + , const char *src_file, uint src_line +#endif + ) +{ + int result; +#ifdef HAVE_PSI_INTERFACE + struct PSI_mutex_locker *locker= NULL; + if (likely(PSI_server && that->m_psi)) + { + locker= PSI_server->get_thread_mutex_locker(that->m_psi, PSI_MUTEX_LOCK); + if (likely(locker != NULL)) + PSI_server->start_mutex_wait(locker, src_file, src_line); + } +#endif +#ifdef SAFE_MUTEX + result= safe_mutex_lock(&that->m_mutex, FALSE, src_file, src_line); +#else + result= pthread_mutex_lock(&that->m_mutex); +#endif +#ifdef HAVE_PSI_INTERFACE + if (likely(locker != NULL)) + PSI_server->end_mutex_wait(locker, result); +#endif + return result; +} + +static inline int inline_mysql_mutex_trylock( + mysql_mutex_t *that +#if defined(SAFE_MUTEX) || defined (HAVE_PSI_INTERFACE) + , const char *src_file, uint src_line +#endif + ) +{ + int result; +#ifdef HAVE_PSI_INTERFACE + struct PSI_mutex_locker *locker= NULL; + if (likely(PSI_server && that->m_psi)) + { + locker= PSI_server->get_thread_mutex_locker(that->m_psi, PSI_MUTEX_TRYLOCK); + if (likely(locker != NULL)) + PSI_server->start_mutex_wait(locker, src_file, src_line); + } +#endif +#ifdef SAFE_MUTEX + result= safe_mutex_lock(&that->m_mutex, TRUE, src_file, src_line); +#else + result= pthread_mutex_trylock(&that->m_mutex); +#endif +#ifdef HAVE_PSI_INTERFACE + if (likely(locker != NULL)) + PSI_server->end_mutex_wait(locker, result); +#endif + return result; +} + +static inline int inline_mysql_mutex_unlock( + mysql_mutex_t *that +#ifdef SAFE_MUTEX + , const char *src_file, uint src_line +#endif + ) +{ + int result; +#ifdef HAVE_PSI_INTERFACE + struct PSI_thread *thread; + if (likely(PSI_server && that->m_psi)) + { + thread= PSI_server->get_thread(); + if (likely(thread != NULL)) + PSI_server->unlock_mutex(thread, that->m_psi); + } +#endif +#ifdef SAFE_MUTEX + result= safe_mutex_unlock(&that->m_mutex, src_file, src_line); +#else + result= pthread_mutex_unlock(&that->m_mutex); +#endif + return result; +} + +static inline int inline_mysql_rwlock_init( +#ifdef HAVE_PSI_INTERFACE + PSI_rwlock_key key, +#endif + mysql_rwlock_t *that) +{ +#ifdef HAVE_PSI_INTERFACE + that->m_psi= (PSI_server ? PSI_server->init_rwlock(key, &that->m_rwlock) + : NULL); +#else + that->m_psi= NULL; +#endif + /* + pthread_rwlockattr_t is not used in MySQL. + */ + return my_rwlock_init(&that->m_rwlock, NULL); +} + +static inline int inline_mysql_rwlock_destroy( + mysql_rwlock_t *that) +{ +#ifdef HAVE_PSI_INTERFACE + if (likely(PSI_server && that->m_psi)) + { + PSI_server->destroy_rwlock(that->m_psi); + that->m_psi= NULL; + } +#endif + return rwlock_destroy(&that->m_rwlock); +} + +static inline int inline_mysql_rwlock_rdlock( + mysql_rwlock_t *that +#ifdef HAVE_PSI_INTERFACE + , const char *src_file, uint src_line +#endif + ) +{ + int result; +#ifdef HAVE_PSI_INTERFACE + struct PSI_rwlock_locker *locker= NULL; + if (likely(PSI_server && that->m_psi)) + { + locker= PSI_server->get_thread_rwlock_locker(that->m_psi, + PSI_RWLOCK_READLOCK); + if (likely(locker != NULL)) + PSI_server->start_rwlock_rdwait(locker, src_file, src_line); + } +#endif + result= rw_rdlock(&that->m_rwlock); +#ifdef HAVE_PSI_INTERFACE + if (likely(locker != NULL)) + PSI_server->end_rwlock_rdwait(locker, result); +#endif + return result; +} + +static inline int inline_mysql_rwlock_wrlock( + mysql_rwlock_t *that +#ifdef HAVE_PSI_INTERFACE + , const char *src_file, uint src_line +#endif + ) +{ + int result; +#ifdef HAVE_PSI_INTERFACE + struct PSI_rwlock_locker *locker= NULL; + if (likely(PSI_server && that->m_psi)) + { + locker= PSI_server->get_thread_rwlock_locker(that->m_psi, + PSI_RWLOCK_WRITELOCK); + if (likely(locker != NULL)) + PSI_server->start_rwlock_wrwait(locker, src_file, src_line); + } +#endif + result= rw_wrlock(&that->m_rwlock); +#ifdef HAVE_PSI_INTERFACE + if (likely(locker != NULL)) + PSI_server->end_rwlock_wrwait(locker, result); +#endif + return result; +} + +static inline int inline_mysql_rwlock_tryrdlock( + mysql_rwlock_t *that +#ifdef HAVE_PSI_INTERFACE + , const char *src_file, uint src_line +#endif + ) +{ + int result; +#ifdef HAVE_PSI_INTERFACE + struct PSI_rwlock_locker *locker= NULL; + if (likely(PSI_server && that->m_psi)) + { + locker= PSI_server->get_thread_rwlock_locker(that->m_psi, + PSI_RWLOCK_TRYREADLOCK); + if (likely(locker != NULL)) + PSI_server->start_rwlock_rdwait(locker, src_file, src_line); + } +#endif + result= rw_tryrdlock(&that->m_rwlock); +#ifdef HAVE_PSI_INTERFACE + if (likely(locker != NULL)) + PSI_server->end_rwlock_rdwait(locker, result); +#endif + return result; +} + +static inline int inline_mysql_rwlock_trywrlock( + mysql_rwlock_t *that +#ifdef HAVE_PSI_INTERFACE + , const char *src_file, uint src_line +#endif + ) +{ + int result; +#ifdef HAVE_PSI_INTERFACE + struct PSI_rwlock_locker *locker= NULL; + if (likely(PSI_server && that->m_psi)) + { + locker= PSI_server->get_thread_rwlock_locker(that->m_psi, + PSI_RWLOCK_TRYWRITELOCK); + if (likely(locker != NULL)) + PSI_server->start_rwlock_wrwait(locker, src_file, src_line); + } +#endif + result= rw_trywrlock(&that->m_rwlock); +#ifdef HAVE_PSI_INTERFACE + if (likely(locker != NULL)) + PSI_server->end_rwlock_wrwait(locker, result); +#endif + return result; +} + +static inline int inline_mysql_rwlock_unlock( + mysql_rwlock_t *that) +{ + int result; +#ifdef HAVE_PSI_INTERFACE + struct PSI_thread *thread; + if (likely(PSI_server && that->m_psi)) + { + thread= PSI_server->get_thread(); + if (likely(thread != NULL)) + PSI_server->unlock_rwlock(thread, that->m_psi); + } +#endif + result= rw_unlock(&that->m_rwlock); + return result; +} + +static inline int inline_mysql_cond_init( +#ifdef HAVE_PSI_INTERFACE + PSI_cond_key key, +#endif + mysql_cond_t *that, + const pthread_condattr_t *attr) +{ +#ifdef HAVE_PSI_INTERFACE + that->m_psi= (PSI_server ? PSI_server->init_cond(key, &that->m_cond) + : NULL); +#else + that->m_psi= NULL; +#endif + return pthread_cond_init(&that->m_cond, attr); +} + +static inline int inline_mysql_cond_destroy( + mysql_cond_t *that) +{ +#ifdef HAVE_PSI_INTERFACE + if (likely(PSI_server && that->m_psi)) + { + PSI_server->destroy_cond(that->m_psi); + that->m_psi= NULL; + } +#endif + return pthread_cond_destroy(&that->m_cond); +} + +static inline int inline_mysql_cond_wait( + mysql_cond_t *that, + mysql_mutex_t *mutex +#ifdef HAVE_PSI_INTERFACE + , const char *src_file, uint src_line +#endif + ) +{ + int result; +#ifdef HAVE_PSI_INTERFACE + struct PSI_cond_locker *locker= NULL; + if (likely(PSI_server && that->m_psi)) + { + locker= PSI_server->get_thread_cond_locker(that->m_psi, mutex->m_psi, + PSI_COND_WAIT); + if (likely(locker != NULL)) + PSI_server->start_cond_wait(locker, src_file, src_line); + } +#endif + result= pthread_cond_wait(&that->m_cond, &mutex->m_mutex); +#ifdef HAVE_PSI_INTERFACE + if (likely(locker != NULL)) + PSI_server->end_cond_wait(locker, result); +#endif + return result; +} + +static inline int inline_mysql_cond_timedwait( + mysql_cond_t *that, + mysql_mutex_t *mutex, + struct timespec *abstime +#ifdef HAVE_PSI_INTERFACE + , const char *src_file, uint src_line +#endif + ) +{ + int result; +#ifdef HAVE_PSI_INTERFACE + struct PSI_cond_locker *locker= NULL; + if (likely(PSI_server && that->m_psi)) + { + locker= PSI_server->get_thread_cond_locker(that->m_psi, mutex->m_psi, + PSI_COND_TIMEDWAIT); + if (likely(locker != NULL)) + PSI_server->start_cond_wait(locker, src_file, src_line); + } +#endif + result= pthread_cond_timedwait(&that->m_cond, &mutex->m_mutex, abstime); +#ifdef HAVE_PSI_INTERFACE + if (likely(locker != NULL)) + PSI_server->end_cond_wait(locker, result); +#endif + return result; +} + +static inline int inline_mysql_cond_signal( + mysql_cond_t *that) +{ + int result; +#ifdef HAVE_PSI_INTERFACE + struct PSI_thread *thread; + if (likely(PSI_server && that->m_psi)) + { + thread= PSI_server->get_thread(); + if (likely(thread != NULL)) + PSI_server->signal_cond(thread, that->m_psi); + } +#endif + result= pthread_cond_signal(&that->m_cond); + return result; +} + +static inline int inline_mysql_cond_broadcast( + mysql_cond_t *that) +{ + int result; +#ifdef HAVE_PSI_INTERFACE + struct PSI_thread *thread; + if (likely(PSI_server && that->m_psi)) + { + thread= PSI_server->get_thread(); + if (likely(thread != NULL)) + PSI_server->broadcast_cond(thread, that->m_psi); + } +#endif + result= pthread_cond_broadcast(&that->m_cond); + return result; +} + +#ifdef HAVE_PSI_INTERFACE +static inline int inline_mysql_thread_create( + PSI_thread_key key, + pthread_t *thread, const pthread_attr_t *attr, + void *(*start_routine)(void*), void *arg) +{ + int result; + if (likely(PSI_server != NULL)) + result= PSI_server->spawn_thread(key, thread, attr, start_routine, arg); + else + result= pthread_create(thread, attr, start_routine, arg); + return result; +} + +static inline void inline_mysql_thread_set_psi_id(ulong id) +{ + if (likely(PSI_server != NULL)) + { + struct PSI_thread *psi= PSI_server->get_thread(); + if (likely(psi != NULL)) + PSI_server->set_thread_id(psi, id); + } +} +#endif + +#endif /* DISABLE_MYSQL_THREAD_H */ + +/** @} (end of group Thread_instrumentation) */ + +#endif + diff --git a/include/mysql/psi/psi.h b/include/mysql/psi/psi.h new file mode 100644 index 00000000000..a9277cd18bd --- /dev/null +++ b/include/mysql/psi/psi.h @@ -0,0 +1,1086 @@ +/* Copyright (C) 2008-2009 Sun Microsystems, Inc + + 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 + the Free Software Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + +#ifndef MYSQL_PERFORMANCE_SCHEMA_INTERFACE_H +#define MYSQL_PERFORMANCE_SCHEMA_INTERFACE_H + +#ifndef _global_h +/* + Make sure a .c or .cc file contains an include to my_global.h first. + When this include is missing, all the #ifdef HAVE_XXX have no effect, + and the resulting binary won't build, or won't link, + or will crash at runtime + since various structures will have different binary definitions. +*/ +#error "You must include my_global.h in the code for the build to be correct." +#endif + +C_MODE_START + +/** + @file mysql/psi/psi.h + Performance schema instrumentation interface. + + @defgroup Instrumentation_interface Instrumentation Interface + @ingroup Performance_schema + @{ +*/ + +/** + Interface for an instrumented mutex. + This is an opaque structure. +*/ +struct PSI_mutex; + +/** + Interface for an instrumented rwlock. + This is an opaque structure. +*/ +struct PSI_rwlock; + +/** + Interface for an instrumented condition. + This is an opaque structure. +*/ +struct PSI_cond; + +/** + Interface for an instrumented table share. + This is an opaque structure. +*/ +struct PSI_table_share; + +/** + Interface for an instrumented table handle. + This is an opaque structure. +*/ +struct PSI_table; + +/** + Interface for an instrumented thread. + This is an opaque structure. +*/ +struct PSI_thread; + +/** + Interface for an instrumented file handle. + This is an opaque structure. +*/ +struct PSI_file; + +/** Entry point for the performance schema interface. */ +struct PSI_bootstrap +{ + /** + ABI interface finder. + Calling this method with an interface version number returns either + an instance of the ABI for this version, or NULL. + @param version the interface version number to find + @return a versioned interface (PSI_v1, PSI_v2 or PSI) + @sa PSI_VERSION_1 + @sa PSI_v1 + @sa PSI_VERSION_2 + @sa PSI_v2 + @sa PSI_CURRENT_VERSION + @sa PSI + */ + void* (*get_interface)(int version); +}; + +#ifdef HAVE_PSI_INTERFACE + +/** + @def PSI_VERSION_1 + Performance Schema Interface number for version 1. + This version is supported. +*/ +#define PSI_VERSION_1 1 + +/** + @def PSI_VERSION_2 + Performance Schema Interface number for version 2. + This version is not implemented, it's a placeholder. +*/ +#define PSI_VERSION_2 2 + +/** + @def PSI_CURRENT_VERSION + Performance Schema Interface number for the most recent version. + The most current version is @c PSI_VERSION_1 +*/ +#define PSI_CURRENT_VERSION 1 + +#ifndef USE_PSI_2 +#ifndef USE_PSI_1 +#define USE_PSI_1 +#endif +#endif + +/** + Interface for an instrumented mutex operation. + This is an opaque structure. +*/ +struct PSI_mutex_locker; + +/** + Interface for an instrumented rwlock operation. + This is an opaque structure. +*/ + +struct PSI_rwlock_locker; +/** + Interface for an instrumented condition operation. + This is an opaque structure. +*/ + +struct PSI_cond_locker; + +/** + Interface for an instrumented file operation. + This is an opaque structure. +*/ +struct PSI_file_locker; + +/** Operation performed on an instrumented mutex. */ +enum PSI_mutex_operation +{ + /** Lock. */ + PSI_MUTEX_LOCK= 0, + /** Lock attempt. */ + PSI_MUTEX_TRYLOCK= 1 +}; + +/** Operation performed on an instrumented rwlock. */ +enum PSI_rwlock_operation +{ + /** Read lock. */ + PSI_RWLOCK_READLOCK= 0, + /** Write lock. */ + PSI_RWLOCK_WRITELOCK= 1, + /** Read lock attempt. */ + PSI_RWLOCK_TRYREADLOCK= 2, + /** Write lock attempt. */ + PSI_RWLOCK_TRYWRITELOCK= 3 +}; + +/** Operation performed on an instrumented condition. */ +enum PSI_cond_operation +{ + /** Wait. */ + PSI_COND_WAIT= 0, + /** Wait, with timeout. */ + PSI_COND_TIMEDWAIT= 1 +}; + +/** Operation performed on an instrumented file. */ +enum PSI_file_operation +{ + /** File creation, as in @c create(). */ + PSI_FILE_CREATE= 0, + /** Temporary file creation, as in @c create_temp_file(). */ + PSI_FILE_CREATE_TMP= 1, + /** File open, as in @c open(). */ + PSI_FILE_OPEN= 2, + /** File open, as in @c fopen(). */ + PSI_FILE_STREAM_OPEN= 3, + /** File close, as in @c close(). */ + PSI_FILE_CLOSE= 4, + /** File close, as in @c fclose(). */ + PSI_FILE_STREAM_CLOSE= 5, + /** + Generic file read, such as @c fgets(), @c fgetc(), @c fread(), @c read(), + @c pread(). + */ + PSI_FILE_READ= 6, + /** + Generic file write, such as @c fputs(), @c fputc(), @c fprintf(), + @c vfprintf(), @c fwrite(), @c write(), @c pwrite(). + */ + PSI_FILE_WRITE= 7, + /** Generic file seek, such as @c fseek() or @c seek(). */ + PSI_FILE_SEEK= 8, + /** Generic file tell, such as @c ftell() or @c tell(). */ + PSI_FILE_TELL= 9, + /** File flush, as in @c fflush(). */ + PSI_FILE_FLUSH= 10, + /** File stat, as in @c stat(). */ + PSI_FILE_STAT= 11, + /** File stat, as in @c fstat(). */ + PSI_FILE_FSTAT= 12, + /** File chsize, as in @c my_chsize(). */ + PSI_FILE_CHSIZE= 13, + /** File delete, such as @c my_delete() or @c my_delete_with_symlink(). */ + PSI_FILE_DELETE= 14, + /** File rename, such as @c my_rename() or @c my_rename_with_symlink(). */ + PSI_FILE_RENAME= 15, + /** File sync, as in @c fsync() or @c my_sync(). */ + PSI_FILE_SYNC= 16 +}; + +/** + Interface for an instrumented table operation. + This is an opaque structure. +*/ +struct PSI_table_locker; + +/** + Instrumented mutex key. + To instrument a mutex, a mutex key must be obtained using @c register_mutex. + Using a zero key always disable the instrumentation. +*/ +typedef unsigned int PSI_mutex_key; + +/** + Instrumented rwlock key. + To instrument a rwlock, a rwlock key must be obtained + using @c register_rwlock. + Using a zero key always disable the instrumentation. +*/ +typedef unsigned int PSI_rwlock_key; + +/** + Instrumented cond key. + To instrument a condition, a condition key must be obtained + using @c register_cond. + Using a zero key always disable the instrumentation. +*/ +typedef unsigned int PSI_cond_key; + +/** + Instrumented thread key. + To instrument a thread, a thread key must be obtained + using @c register_thread. + Using a zero key always disable the instrumentation. +*/ +typedef unsigned int PSI_thread_key; + +/** + Instrumented file key. + To instrument a file, a file key must be obtained using @c register_file. + Using a zero key always disable the instrumentation. +*/ +typedef unsigned int PSI_file_key; + +/** + @def USE_PSI_1 + Define USE_PSI_1 to use the interface version 1. +*/ + +/** + @def USE_PSI_2 + Define USE_PSI_2 to use the interface version 2. +*/ + +/** + @def HAVE_PSI_1 + Define HAVE_PSI_1 if the interface version 1 needs to be compiled in. +*/ + +/** + @def HAVE_PSI_2 + Define HAVE_PSI_2 if the interface version 2 needs to be compiled in. +*/ + +/** + Global flag. + This flag indicate that an instrumentation point is a global variable, + or a singleton. +*/ +#define PSI_FLAG_GLOBAL (1 << 0) + +#ifdef USE_PSI_1 +#define HAVE_PSI_1 +#endif + +#ifdef HAVE_PSI_1 + +/** + @defgroup Group_PSI_v1 Application Binary Interface, version 1 + @ingroup Instrumentation_interface + @{ +*/ + +/** + Mutex information. + @since PSI_VERSION_1 + This structure is used to register an instrumented mutex. +*/ +struct PSI_mutex_info_v1 +{ + /** + Pointer to the key assigned to the registered mutex. + */ + PSI_mutex_key *m_key; + /** + The name of the mutex to register. + */ + const char *m_name; + /** + The flags of the mutex to register. + @sa PSI_FLAG_GLOBAL + */ + int m_flags; +}; + +/** + Rwlock information. + @since PSI_VERSION_1 + This structure is used to register an instrumented rwlock. +*/ +struct PSI_rwlock_info_v1 +{ + /** + Pointer to the key assigned to the registered rwlock. + */ + PSI_rwlock_key *m_key; + /** + The name of the rwlock to register. + */ + const char *m_name; + /** + The flags of the rwlock to register. + @sa PSI_FLAG_GLOBAL + */ + int m_flags; +}; + +/** + Condition information. + @since PSI_VERSION_1 + This structure is used to register an instrumented cond. +*/ +struct PSI_cond_info_v1 +{ + /** + Pointer to the key assigned to the registered cond. + */ + PSI_cond_key *m_key; + /** + The name of the cond to register. + */ + const char *m_name; + /** + The flags of the cond to register. + @sa PSI_FLAG_GLOBAL + */ + int m_flags; +}; + +/** + Thread instrument information. + @since PSI_VERSION_1 + This structure is used to register an instrumented thread. +*/ +struct PSI_thread_info_v1 +{ + /** + Pointer to the key assigned to the registered thread. + */ + PSI_thread_key *m_key; + /** + The name of the thread instrument to register. + */ + const char *m_name; + /** + The flags of the thread to register. + @sa PSI_FLAG_GLOBAL + */ + int m_flags; +}; + +/** + File instrument information. + @since PSI_VERSION_1 + This structure is used to register an instrumented file. +*/ +struct PSI_file_info_v1 +{ + /** + Pointer to the key assigned to the registered file. + */ + PSI_file_key *m_key; + /** + The name of the file instrument to register. + */ + const char *m_name; + /** + The flags of the file instrument to register. + @sa PSI_FLAG_GLOBAL + */ + int m_flags; +}; + +/* Using typedef to make reuse between PSI_v1 and PSI_v2 easier later. */ + +/** + Mutex registration API. + @param category a category name (typically a plugin name) + @param info an array of mutex info to register + @param count the size of the info array +*/ +typedef void (*register_mutex_v1_t) + (const char *category, struct PSI_mutex_info_v1 *info, int count); + +/** + Rwlock registration API. + @param category a category name (typically a plugin name) + @param info an array of rwlock info to register + @param count the size of the info array +*/ +typedef void (*register_rwlock_v1_t) + (const char *category, struct PSI_rwlock_info_v1 *info, int count); + +/** + Cond registration API. + @param category a category name (typically a plugin name) + @param info an array of cond info to register + @param count the size of the info array +*/ +typedef void (*register_cond_v1_t) + (const char *category, struct PSI_cond_info_v1 *info, int count); + +/** + Thread registration API. + @param category a category name (typically a plugin name) + @param info an array of thread info to register + @param count the size of the info array +*/ +typedef void (*register_thread_v1_t) + (const char *category, struct PSI_thread_info_v1 *info, int count); + +/** + File registration API. + @param category a category name (typically a plugin name) + @param info an array of file info to register + @param count the size of the info array +*/ +typedef void (*register_file_v1_t) + (const char *category, struct PSI_file_info_v1 *info, int count); + +/** + Mutex instrumentation initialisation API. + @param key the registered mutex key + @param identity the address of the mutex itself + @return an instrumented mutex +*/ +typedef struct PSI_mutex* (*init_mutex_v1_t) + (PSI_mutex_key key, const void *identity); + +/** + Mutex instrumentation destruction API. + @param mutex the mutex to destroy +*/ +typedef void (*destroy_mutex_v1_t)(struct PSI_mutex *mutex); + +/** + Rwlock instrumentation initialisation API. + @param key the registered rwlock key + @param identity the address of the rwlock itself + @return an instrumented rwlock +*/ +typedef struct PSI_rwlock* (*init_rwlock_v1_t) + (PSI_rwlock_key key, const void *identity); + +/** + Rwlock instrumentation destruction API. + @param rwlock the rwlock to destroy +*/ +typedef void (*destroy_rwlock_v1_t)(struct PSI_rwlock *rwlock); + +/** + Cond instrumentation initialisation API. + @param key the registered key + @param identity the address of the rwlock itself + @return an instrumented cond +*/ +typedef struct PSI_cond* (*init_cond_v1_t) + (PSI_cond_key key, const void *identity); + +/** + Cond instrumentation destruction API. + @param cond the rcond to destroy +*/ +typedef void (*destroy_cond_v1_t)(struct PSI_cond *cond); + +/** + Acquire a table info by name. + @param schema_name name of the table schema + @param schema_name_length length of schema_name + @param table_name name of the table + @param table_name_length length of table_name + @param identity table identity pointer, typically the table share + @return a table info, or NULL if the table is not instrumented +*/ +typedef struct PSI_table_share* (*get_table_share_v1_t) + (const char *schema_name, int schema_name_length, const char *table_name, + int table_name_length, const void *identity); + +/** + Release a table share. + @param info the table share to release +*/ +typedef void (*release_table_share_v1_t)(struct PSI_table_share *share); + +/** + Open an instrumentation table handle. + @param share the table to open + @param identity table handle identity + @return a table handle, or NULL +*/ +typedef struct PSI_table* (*open_table_v1_t) + (struct PSI_table_share *share, const void *identity); + +/** + Close an instrumentation table handle. + Note that the table handle is invalid after this call. + @param table the table handle to close +*/ +typedef void (*close_table_v1_t)(struct PSI_table *table); + +/** + Create a file instrumentation for a created file. + This method does not create the file itself, but is used to notify the + instrumentation interface that a file was just created. + @param key the file instrumentation key for this file + @param name the file name + @param file the file handle +*/ +typedef void (*create_file_v1_t)(PSI_file_key key, const char *name, + File file); + +/** + Spawn a thread. + This method creates a new thread, with instrumentation. + @param key the instrumentation key for this thread + @param thread the resulting thread + @param attr the thread attributes + @param start_routine the thread start routine + @param arg the thread start routine argument +*/ +typedef int (*spawn_thread_v1_t)(PSI_thread_key key, + pthread_t *thread, + const pthread_attr_t *attr, + void *(*start_routine)(void*), void *arg); + +/** + Create instrumentation for a thread. + @param key the registered key + @param identity an address typical of the thread + @return an instrumented thread +*/ +typedef struct PSI_thread* (*new_thread_v1_t) + (PSI_thread_key key, const void *identity, ulong thread_id); + +/** + Assign an id to an instrumented thread. + @param thread the instrumented thread + @param id the id to assign +*/ +typedef void (*set_thread_id_v1_t)(struct PSI_thread *thread, + unsigned long id); + +/** + Get the instrumentation for the running thread. + For this function to return a result, + the thread instrumentation must have been attached to the + running thread using @c set_thread() + @return the instrumentation for the running thread +*/ +typedef struct PSI_thread* (*get_thread_v1_t)(void); + +/** + Attach a thread instrumentation to the running thread. + In case of thread pools, this method should be called when + a worker thread picks a work item and runs it. + Also, this method should be called if the instrumented code does not + keep the pointer returned by @c new_thread() and relies on @c get_thread() + instead. + @param thread the thread instrumentation +*/ +typedef void (*set_thread_v1_t)(struct PSI_thread *thread); + +/** Delete the current thread instrumentation. */ +typedef void (*delete_current_thread_v1_t)(void); + +/** + Get a mutex instrumentation locker. + @param mutex the instrumented mutex to lock + @return a mutex locker, or NULL +*/ +typedef struct PSI_mutex_locker* (*get_thread_mutex_locker_v1_t) + (struct PSI_mutex *mutex, enum PSI_mutex_operation op); + +/** + Get a rwlock instrumentation locker. + @param rwlock the instrumented rwlock to lock + @return a rwlock locker, or NULL +*/ +typedef struct PSI_rwlock_locker* (*get_thread_rwlock_locker_v1_t) + (struct PSI_rwlock *rwlock, enum PSI_rwlock_operation op); + +/** + Get a cond instrumentation locker. + @param cond the instrumented condition to wait on + @param mutex the instrumented mutex associated with the condition + @return a condition locker, or NULL +*/ +typedef struct PSI_cond_locker* (*get_thread_cond_locker_v1_t) + (struct PSI_cond *cond, struct PSI_mutex *mutex, + enum PSI_cond_operation op); + +/** + Get a table instrumentation locker. + @param table the instrumented table to lock + @return a table locker, or NULL +*/ +typedef struct PSI_table_locker* (*get_thread_table_locker_v1_t) + (struct PSI_table *table); + +/** + Get a file instrumentation locker, for opening or creating a file. + @param key the file instrumentation key + @param op the operation to perform + @param name the file name + @param identity a pointer representative of this file. + @return a file locker, or NULL +*/ +typedef struct PSI_file_locker* (*get_thread_file_name_locker_v1_t) + (PSI_file_key key, enum PSI_file_operation op, const char *name, + const void *identity); + +/** + Get a file stream instrumentation locker. + @param file the file stream to access + @param op the operation to perform + @return a file locker, or NULL +*/ +typedef struct PSI_file_locker* (*get_thread_file_stream_locker_v1_t) + (struct PSI_file *file, enum PSI_file_operation op); + +/** + Get a file instrumentation locker. + @param file the file descriptor to access + @param op the operation to perform + @return a file locker, or NULL +*/ +typedef struct PSI_file_locker* (*get_thread_file_descriptor_locker_v1_t) + (File file, enum PSI_file_operation op); + +/** + Record a mutex instrumentation unlock event. + @param thread the running thread instrumentation + @param mutex the mutex instrumentation +*/ +typedef void (*unlock_mutex_v1_t) + (struct PSI_thread *thread, struct PSI_mutex *mutex); + +/** + Record a rwlock instrumentation unlock event. + @param thread the running thread instrumentation + @param rwlock the rwlock instrumentation +*/ +typedef void (*unlock_rwlock_v1_t) + (struct PSI_thread *thread, struct PSI_rwlock *rwlock); + +/** + Record a condition instrumentation signal event. + @param thread the running thread instrumentation + @param cond the cond instrumentation +*/ +typedef void (*signal_cond_v1_t) + (struct PSI_thread *thread, struct PSI_cond *cond); + +/** + Record a condition instrumentation broadcast event. + @param thread the running thread instrumentation + @param cond the cond instrumentation +*/ +typedef void (*broadcast_cond_v1_t) + (struct PSI_thread *thread, struct PSI_cond *cond); + +/** + Record a mutex instrumentation wait start event. + @param locker a thread locker for the running thread +*/ +typedef void (*start_mutex_wait_v1_t) + (struct PSI_mutex_locker *locker, const char *src_file, uint src_line); + +/** + Record a mutex instrumentation wait end event. + @param locker a thread locker for the running thread + @param rc the wait operation return code +*/ +typedef void (*end_mutex_wait_v1_t) + (struct PSI_mutex_locker *locker, int rc); + +/** + Record a rwlock instrumentation read wait start event. + @param locker a thread locker for the running thread + @param must must block: 1 for lock, 0 for trylock +*/ +typedef void (*start_rwlock_rdwait_v1_t) + (struct PSI_rwlock_locker *locker, const char *src_file, uint src_line); + +/** + Record a rwlock instrumentation read wait end event. + @param locker a thread locker for the running thread + @param rc the wait operation return code +*/ +typedef void (*end_rwlock_rdwait_v1_t) + (struct PSI_rwlock_locker *locker, int rc); + +/** + Record a rwlock instrumentation write wait start event. + @param locker a thread locker for the running thread + @param must must block: 1 for lock, 0 for trylock +*/ +typedef void (*start_rwlock_wrwait_v1_t) + (struct PSI_rwlock_locker *locker, const char *src_file, uint src_line); + +/** + Record a rwlock instrumentation write wait end event. + @param locker a thread locker for the running thread + @param rc the wait operation return code +*/ +typedef void (*end_rwlock_wrwait_v1_t) + (struct PSI_rwlock_locker *locker, int rc); + +/** + Record a condition instrumentation wait start event. + @param locker a thread locker for the running thread + @param must must block: 1 for wait, 0 for timedwait +*/ +typedef void (*start_cond_wait_v1_t) + (struct PSI_cond_locker *locker, const char *src_file, uint src_line); + +/** + Record a condition instrumentation wait end event. + @param locker a thread locker for the running thread + @param rc the wait operation return code +*/ +typedef void (*end_cond_wait_v1_t) + (struct PSI_cond_locker *locker, int rc); + +/** + Record a table instrumentation wait start event. + @param locker a table locker for the running thread + @param file the source file name + @param line the source line number +*/ +typedef void (*start_table_wait_v1_t) + (struct PSI_table_locker *locker, const char *src_file, uint src_line); + +/** + Record a table instrumentation wait end event. + @param locker a table locker for the running thread +*/ +typedef void (*end_table_wait_v1_t)(struct PSI_table_locker *locker); + +/** + Start a file instrumentation open operation. + @param locker the file locker + @param op the operation to perform + @param src_file the source file name + @param src_line the source line number + @return an instrumented file handle +*/ +typedef struct PSI_file* (*start_file_open_wait_v1_t) + (struct PSI_file_locker *locker, const char *src_file, uint src_line); + +/** + End a file instrumentation open operation, for file streams. + @param locker the file locker. +*/ +typedef void (*end_file_open_wait_v1_t)(struct PSI_file_locker *locker); + +/** + End a file instrumentation open operation, for non stream files. + @param locker the file locker. + @param file the file number assigned by open() or create() for this file. +*/ +typedef void (*end_file_open_wait_and_bind_to_descriptor_v1_t) + (struct PSI_file_locker *locker, File file); + +/** + Record a file instrumentation start event. + @param locker a file locker for the running thread + @param op file operation to be performed + @param count the number of bytes requested, or 0 if not applicable + @param src_file the source file name + @param src_line the source line number +*/ +typedef void (*start_file_wait_v1_t) + (struct PSI_file_locker *locker, size_t count, + const char *src_file, uint src_line); + +/** + Record a file instrumentation end event. + Note that for file close operations, the instrumented file handle + associated with the file (which was provided to obtain a locker) + is invalid after this call. + @param locker a file locker for the running thread + @param count the number of bytes actually used in the operation, + or 0 if not applicable, or -1 if the operation failed + @sa get_thread_file_name_locker + @sa get_thread_file_stream_locker + @sa get_thread_file_descriptor_locker +*/ +typedef void (*end_file_wait_v1_t) + (struct PSI_file_locker *locker, size_t count); + +/** + Performance Schema Interface, version 1. + @since PSI_VERSION_1 +*/ +struct PSI_v1 +{ + /** @sa register_mutex_v1_t. */ + register_mutex_v1_t register_mutex; + /** @sa register_rwlock_v1_t. */ + register_rwlock_v1_t register_rwlock; + /** @sa register_cond_v1_t. */ + register_cond_v1_t register_cond; + /** @sa register_thread_v1_t. */ + register_thread_v1_t register_thread; + /** @sa register_file_v1_t. */ + register_file_v1_t register_file; + /** @sa init_mutex_v1_t. */ + init_mutex_v1_t init_mutex; + /** @sa destroy_mutex_v1_t. */ + destroy_mutex_v1_t destroy_mutex; + /** @sa init_rwlock_v1_t. */ + init_rwlock_v1_t init_rwlock; + /** @sa destroy_rwlock_v1_t. */ + destroy_rwlock_v1_t destroy_rwlock; + /** @sa init_cond_v1_t. */ + init_cond_v1_t init_cond; + /** @sa destroy_cond_v1_t. */ + destroy_cond_v1_t destroy_cond; + /** @sa get_table_share_v1_t. */ + get_table_share_v1_t get_table_share; + /** @sa release_table_share_v1_t. */ + release_table_share_v1_t release_table_share; + /** @sa open_table_v1_t. */ + open_table_v1_t open_table; + /** @sa close_table_v1_t. */ + close_table_v1_t close_table; + /** @sa create_file_v1_t. */ + create_file_v1_t create_file; + /** @sa spawn_thread_v1_t. */ + spawn_thread_v1_t spawn_thread; + /** @sa new_thread_v1_t. */ + new_thread_v1_t new_thread; + /** @sa set_thread_id_v1_t. */ + set_thread_id_v1_t set_thread_id; + /** @sa get_thread_v1_t. */ + get_thread_v1_t get_thread; + /** @sa set_thread_v1_t. */ + set_thread_v1_t set_thread; + /** @sa delete_current_thread_v1_t. */ + delete_current_thread_v1_t delete_current_thread; + /** @sa get_thread_mutex_locker_v1_t. */ + get_thread_mutex_locker_v1_t get_thread_mutex_locker; + /** @sa get_thread_rwlock_locker_v1_t. */ + get_thread_rwlock_locker_v1_t get_thread_rwlock_locker; + /** @sa get_thread_cond_locker_v1_t. */ + get_thread_cond_locker_v1_t get_thread_cond_locker; + /** @sa get_thread_table_locker_v1_t. */ + get_thread_table_locker_v1_t get_thread_table_locker; + /** @sa get_thread_file_name_locker_v1_t. */ + get_thread_file_name_locker_v1_t get_thread_file_name_locker; + /** @sa get_thread_file_stream_locker_v1_t. */ + get_thread_file_stream_locker_v1_t get_thread_file_stream_locker; + /** @sa get_thread_file_descriptor_locker_v1_t. */ + get_thread_file_descriptor_locker_v1_t get_thread_file_descriptor_locker; + /** @sa unlock_mutex_v1_t. */ + unlock_mutex_v1_t unlock_mutex; + /** @sa unlock_rwlock_v1_t. */ + unlock_rwlock_v1_t unlock_rwlock; + /** @sa signal_cond_v1_t. */ + signal_cond_v1_t signal_cond; + /** @sa broadcast_cond_v1_t. */ + broadcast_cond_v1_t broadcast_cond; + /** @sa start_mutex_wait_v1_t. */ + start_mutex_wait_v1_t start_mutex_wait; + /** @sa end_mutex_wait_v1_t. */ + end_mutex_wait_v1_t end_mutex_wait; + /** @sa start_rwlock_rdwait_v1_t. */ + start_rwlock_rdwait_v1_t start_rwlock_rdwait; + /** @sa end_rwlock_rdwait_v1_t. */ + end_rwlock_rdwait_v1_t end_rwlock_rdwait; + /** @sa start_rwlock_wrwait_v1_t. */ + start_rwlock_wrwait_v1_t start_rwlock_wrwait; + /** @sa end_rwlock_wrwait_v1_t. */ + end_rwlock_wrwait_v1_t end_rwlock_wrwait; + /** @sa start_cond_wait_v1_t. */ + start_cond_wait_v1_t start_cond_wait; + /** @sa end_cond_wait_v1_t. */ + end_cond_wait_v1_t end_cond_wait; + /** @sa start_table_wait_v1_t. */ + start_table_wait_v1_t start_table_wait; + /** @sa end_table_wait_v1_t. */ + end_table_wait_v1_t end_table_wait; + /** @sa start_file_open_wait_v1_t. */ + start_file_open_wait_v1_t start_file_open_wait; + /** @sa end_file_open_wait_v1_t. */ + end_file_open_wait_v1_t end_file_open_wait; + /** @sa end_file_open_wait_and_bind_to_descriptor_v1_t. */ + end_file_open_wait_and_bind_to_descriptor_v1_t + end_file_open_wait_and_bind_to_descriptor; + /** @sa start_file_wait_v1_t. */ + start_file_wait_v1_t start_file_wait; + /** @sa end_file_wait_v1_t. */ + end_file_wait_v1_t end_file_wait; +}; + +/** @} (end of group Group_PSI_v1) */ + +#endif /* HAVE_PSI_1 */ + +#ifdef USE_PSI_2 +#define HAVE_PSI_2 +#endif + +#ifdef HAVE_PSI_2 + +/** + @defgroup Group_PSI_v2 Application Binary Interface, version 2 + @ingroup Instrumentation_interface + @{ +*/ + +/** + Performance Schema Interface, version 2. + This is a placeholder, this interface is not defined yet. + @since PSI_VERSION_2 +*/ +struct PSI_v2 +{ + /** Placeholder */ + int placeholder; + /* ... extended interface ... */ +}; + +/** Placeholder */ +struct PSI_mutex_info_v2 +{ + /** Placeholder */ + int placeholder; +}; + +/** Placeholder */ +struct PSI_rwlock_info_v2 +{ + /** Placeholder */ + int placeholder; +}; + +/** Placeholder */ +struct PSI_cond_info_v2 +{ + /** Placeholder */ + int placeholder; +}; + +/** Placeholder */ +struct PSI_thread_info_v2 +{ + /** Placeholder */ + int placeholder; +}; + +/** Placeholder */ +struct PSI_file_info_v2 +{ + /** Placeholder */ + int placeholder; +}; + +/** @} (end of group Group_PSI_v2) */ + +#endif /* HAVE_PSI_2 */ + +/** + @typedef PSI + The instrumentation interface for the current version. + @sa PSI_CURRENT_VERSION +*/ + +/** + @typedef PSI_mutex_info + The mutex information structure for the current version. +*/ + +/** + @typedef PSI_rwlock_info + The rwlock information structure for the current version. +*/ + +/** + @typedef PSI_cond_info + The cond information structure for the current version. +*/ + +/** + @typedef PSI_thread_info + The thread information structure for the current version. +*/ + +/** + @typedef PSI_file_info + The file information structure for the current version. +*/ + +/* Export the required version */ +#ifdef USE_PSI_1 +typedef struct PSI_v1 PSI; +typedef struct PSI_mutex_info_v1 PSI_mutex_info; +typedef struct PSI_rwlock_info_v1 PSI_rwlock_info; +typedef struct PSI_cond_info_v1 PSI_cond_info; +typedef struct PSI_thread_info_v1 PSI_thread_info; +typedef struct PSI_file_info_v1 PSI_file_info; +#endif + +#ifdef USE_PSI_2 +typedef struct PSI_v2 PSI; +typedef struct PSI_mutex_info_v2 PSI_mutex_info; +typedef struct PSI_rwlock_info_v2 PSI_rwlock_info; +typedef struct PSI_cond_info_v2 PSI_cond_info; +typedef struct PSI_thread_info_v2 PSI_thread_info; +typedef struct PSI_file_info_v2 PSI_file_info; +#endif + +#else /* HAVE_PSI_INTERFACE */ + +/** + Dummy structure, used to declare PSI_server when no instrumentation + is available. + The content does not matter, since PSI_server will be NULL. +*/ +struct PSI_none +{ + int opaque; +}; +typedef struct PSI_none PSI; + +#endif /* HAVE_PSI_INTERFACE */ + +extern MYSQL_PLUGIN_IMPORT PSI *PSI_server; + +/** @} */ + +C_MODE_END +#endif /* MYSQL_PERFORMANCE_SCHEMA_INTERFACE_H */ + diff --git a/include/mysql/psi/psi_abi_v1.h b/include/mysql/psi/psi_abi_v1.h new file mode 100644 index 00000000000..c9dfd031668 --- /dev/null +++ b/include/mysql/psi/psi_abi_v1.h @@ -0,0 +1,26 @@ +/* Copyright (C) 2008-2009 Sun Microsystems, Inc + + 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 + the Free Software Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + +/** + @file mysql/psi/psi_abi_v1.h + ABI check for mysql/psi/psi.h, when using PSI_VERSION_1. + This file is only used to automate detection of changes between versions. + Do not include this file, include mysql/psi/psi.h instead. +*/ +#define USE_PSI_1 +#define HAVE_PSI_INTERFACE +#define _global_h +#include "mysql/psi/psi.h" + diff --git a/include/mysql/psi/psi_abi_v1.h.pp b/include/mysql/psi/psi_abi_v1.h.pp new file mode 100644 index 00000000000..aedf28ba694 --- /dev/null +++ b/include/mysql/psi/psi_abi_v1.h.pp @@ -0,0 +1,242 @@ +#include "mysql/psi/psi.h" +C_MODE_START +struct PSI_mutex; +struct PSI_rwlock; +struct PSI_cond; +struct PSI_table_share; +struct PSI_table; +struct PSI_thread; +struct PSI_file; +struct PSI_bootstrap +{ + void* (*get_interface)(int version); +}; +struct PSI_mutex_locker; +struct PSI_rwlock_locker; +struct PSI_cond_locker; +struct PSI_file_locker; +enum PSI_mutex_operation +{ + PSI_MUTEX_LOCK= 0, + PSI_MUTEX_TRYLOCK= 1 +}; +enum PSI_rwlock_operation +{ + PSI_RWLOCK_READLOCK= 0, + PSI_RWLOCK_WRITELOCK= 1, + PSI_RWLOCK_TRYREADLOCK= 2, + PSI_RWLOCK_TRYWRITELOCK= 3 +}; +enum PSI_cond_operation +{ + PSI_COND_WAIT= 0, + PSI_COND_TIMEDWAIT= 1 +}; +enum PSI_file_operation +{ + PSI_FILE_CREATE= 0, + PSI_FILE_CREATE_TMP= 1, + PSI_FILE_OPEN= 2, + PSI_FILE_STREAM_OPEN= 3, + PSI_FILE_CLOSE= 4, + PSI_FILE_STREAM_CLOSE= 5, + PSI_FILE_READ= 6, + PSI_FILE_WRITE= 7, + PSI_FILE_SEEK= 8, + PSI_FILE_TELL= 9, + PSI_FILE_FLUSH= 10, + PSI_FILE_STAT= 11, + PSI_FILE_FSTAT= 12, + PSI_FILE_CHSIZE= 13, + PSI_FILE_DELETE= 14, + PSI_FILE_RENAME= 15, + PSI_FILE_SYNC= 16 +}; +struct PSI_table_locker; +typedef unsigned int PSI_mutex_key; +typedef unsigned int PSI_rwlock_key; +typedef unsigned int PSI_cond_key; +typedef unsigned int PSI_thread_key; +typedef unsigned int PSI_file_key; +struct PSI_mutex_info_v1 +{ + PSI_mutex_key *m_key; + const char *m_name; + int m_flags; +}; +struct PSI_rwlock_info_v1 +{ + PSI_rwlock_key *m_key; + const char *m_name; + int m_flags; +}; +struct PSI_cond_info_v1 +{ + PSI_cond_key *m_key; + const char *m_name; + int m_flags; +}; +struct PSI_thread_info_v1 +{ + PSI_thread_key *m_key; + const char *m_name; + int m_flags; +}; +struct PSI_file_info_v1 +{ + PSI_file_key *m_key; + const char *m_name; + int m_flags; +}; +typedef void (*register_mutex_v1_t) + (const char *category, struct PSI_mutex_info_v1 *info, int count); +typedef void (*register_rwlock_v1_t) + (const char *category, struct PSI_rwlock_info_v1 *info, int count); +typedef void (*register_cond_v1_t) + (const char *category, struct PSI_cond_info_v1 *info, int count); +typedef void (*register_thread_v1_t) + (const char *category, struct PSI_thread_info_v1 *info, int count); +typedef void (*register_file_v1_t) + (const char *category, struct PSI_file_info_v1 *info, int count); +typedef struct PSI_mutex* (*init_mutex_v1_t) + (PSI_mutex_key key, const void *identity); +typedef void (*destroy_mutex_v1_t)(struct PSI_mutex *mutex); +typedef struct PSI_rwlock* (*init_rwlock_v1_t) + (PSI_rwlock_key key, const void *identity); +typedef void (*destroy_rwlock_v1_t)(struct PSI_rwlock *rwlock); +typedef struct PSI_cond* (*init_cond_v1_t) + (PSI_cond_key key, const void *identity); +typedef void (*destroy_cond_v1_t)(struct PSI_cond *cond); +typedef struct PSI_table_share* (*get_table_share_v1_t) + (const char *schema_name, int schema_name_length, const char *table_name, + int table_name_length, const void *identity); +typedef void (*release_table_share_v1_t)(struct PSI_table_share *share); +typedef struct PSI_table* (*open_table_v1_t) + (struct PSI_table_share *share, const void *identity); +typedef void (*close_table_v1_t)(struct PSI_table *table); +typedef void (*create_file_v1_t)(PSI_file_key key, const char *name, + File file); +typedef int (*spawn_thread_v1_t)(PSI_thread_key key, + pthread_t *thread, + const pthread_attr_t *attr, + void *(*start_routine)(void*), void *arg); +typedef struct PSI_thread* (*new_thread_v1_t) + (PSI_thread_key key, const void *identity, ulong thread_id); +typedef void (*set_thread_id_v1_t)(struct PSI_thread *thread, + unsigned long id); +typedef struct PSI_thread* (*get_thread_v1_t)(void); +typedef void (*set_thread_v1_t)(struct PSI_thread *thread); +typedef void (*delete_current_thread_v1_t)(void); +typedef struct PSI_mutex_locker* (*get_thread_mutex_locker_v1_t) + (struct PSI_mutex *mutex, enum PSI_mutex_operation op); +typedef struct PSI_rwlock_locker* (*get_thread_rwlock_locker_v1_t) + (struct PSI_rwlock *rwlock, enum PSI_rwlock_operation op); +typedef struct PSI_cond_locker* (*get_thread_cond_locker_v1_t) + (struct PSI_cond *cond, struct PSI_mutex *mutex, + enum PSI_cond_operation op); +typedef struct PSI_table_locker* (*get_thread_table_locker_v1_t) + (struct PSI_table *table); +typedef struct PSI_file_locker* (*get_thread_file_name_locker_v1_t) + (PSI_file_key key, enum PSI_file_operation op, const char *name, + const void *identity); +typedef struct PSI_file_locker* (*get_thread_file_stream_locker_v1_t) + (struct PSI_file *file, enum PSI_file_operation op); +typedef struct PSI_file_locker* (*get_thread_file_descriptor_locker_v1_t) + (File file, enum PSI_file_operation op); +typedef void (*unlock_mutex_v1_t) + (struct PSI_thread *thread, struct PSI_mutex *mutex); +typedef void (*unlock_rwlock_v1_t) + (struct PSI_thread *thread, struct PSI_rwlock *rwlock); +typedef void (*signal_cond_v1_t) + (struct PSI_thread *thread, struct PSI_cond *cond); +typedef void (*broadcast_cond_v1_t) + (struct PSI_thread *thread, struct PSI_cond *cond); +typedef void (*start_mutex_wait_v1_t) + (struct PSI_mutex_locker *locker, const char *src_file, uint src_line); +typedef void (*end_mutex_wait_v1_t) + (struct PSI_mutex_locker *locker, int rc); +typedef void (*start_rwlock_rdwait_v1_t) + (struct PSI_rwlock_locker *locker, const char *src_file, uint src_line); +typedef void (*end_rwlock_rdwait_v1_t) + (struct PSI_rwlock_locker *locker, int rc); +typedef void (*start_rwlock_wrwait_v1_t) + (struct PSI_rwlock_locker *locker, const char *src_file, uint src_line); +typedef void (*end_rwlock_wrwait_v1_t) + (struct PSI_rwlock_locker *locker, int rc); +typedef void (*start_cond_wait_v1_t) + (struct PSI_cond_locker *locker, const char *src_file, uint src_line); +typedef void (*end_cond_wait_v1_t) + (struct PSI_cond_locker *locker, int rc); +typedef void (*start_table_wait_v1_t) + (struct PSI_table_locker *locker, const char *src_file, uint src_line); +typedef void (*end_table_wait_v1_t)(struct PSI_table_locker *locker); +typedef struct PSI_file* (*start_file_open_wait_v1_t) + (struct PSI_file_locker *locker, const char *src_file, uint src_line); +typedef void (*end_file_open_wait_v1_t)(struct PSI_file_locker *locker); +typedef void (*end_file_open_wait_and_bind_to_descriptor_v1_t) + (struct PSI_file_locker *locker, File file); +typedef void (*start_file_wait_v1_t) + (struct PSI_file_locker *locker, size_t count, + const char *src_file, uint src_line); +typedef void (*end_file_wait_v1_t) + (struct PSI_file_locker *locker, size_t count); +struct PSI_v1 +{ + register_mutex_v1_t register_mutex; + register_rwlock_v1_t register_rwlock; + register_cond_v1_t register_cond; + register_thread_v1_t register_thread; + register_file_v1_t register_file; + init_mutex_v1_t init_mutex; + destroy_mutex_v1_t destroy_mutex; + init_rwlock_v1_t init_rwlock; + destroy_rwlock_v1_t destroy_rwlock; + init_cond_v1_t init_cond; + destroy_cond_v1_t destroy_cond; + get_table_share_v1_t get_table_share; + release_table_share_v1_t release_table_share; + open_table_v1_t open_table; + close_table_v1_t close_table; + create_file_v1_t create_file; + spawn_thread_v1_t spawn_thread; + new_thread_v1_t new_thread; + set_thread_id_v1_t set_thread_id; + get_thread_v1_t get_thread; + set_thread_v1_t set_thread; + delete_current_thread_v1_t delete_current_thread; + get_thread_mutex_locker_v1_t get_thread_mutex_locker; + get_thread_rwlock_locker_v1_t get_thread_rwlock_locker; + get_thread_cond_locker_v1_t get_thread_cond_locker; + get_thread_table_locker_v1_t get_thread_table_locker; + get_thread_file_name_locker_v1_t get_thread_file_name_locker; + get_thread_file_stream_locker_v1_t get_thread_file_stream_locker; + get_thread_file_descriptor_locker_v1_t get_thread_file_descriptor_locker; + unlock_mutex_v1_t unlock_mutex; + unlock_rwlock_v1_t unlock_rwlock; + signal_cond_v1_t signal_cond; + broadcast_cond_v1_t broadcast_cond; + start_mutex_wait_v1_t start_mutex_wait; + end_mutex_wait_v1_t end_mutex_wait; + start_rwlock_rdwait_v1_t start_rwlock_rdwait; + end_rwlock_rdwait_v1_t end_rwlock_rdwait; + start_rwlock_wrwait_v1_t start_rwlock_wrwait; + end_rwlock_wrwait_v1_t end_rwlock_wrwait; + start_cond_wait_v1_t start_cond_wait; + end_cond_wait_v1_t end_cond_wait; + start_table_wait_v1_t start_table_wait; + end_table_wait_v1_t end_table_wait; + start_file_open_wait_v1_t start_file_open_wait; + end_file_open_wait_v1_t end_file_open_wait; + end_file_open_wait_and_bind_to_descriptor_v1_t + end_file_open_wait_and_bind_to_descriptor; + start_file_wait_v1_t start_file_wait; + end_file_wait_v1_t end_file_wait; +}; +typedef struct PSI_v1 PSI; +typedef struct PSI_mutex_info_v1 PSI_mutex_info; +typedef struct PSI_rwlock_info_v1 PSI_rwlock_info; +typedef struct PSI_cond_info_v1 PSI_cond_info; +typedef struct PSI_thread_info_v1 PSI_thread_info; +typedef struct PSI_file_info_v1 PSI_file_info; +extern MYSQL_PLUGIN_IMPORT PSI *PSI_server; +C_MODE_END diff --git a/include/mysql/psi/psi_abi_v2.h b/include/mysql/psi/psi_abi_v2.h new file mode 100644 index 00000000000..e720c4c2b7c --- /dev/null +++ b/include/mysql/psi/psi_abi_v2.h @@ -0,0 +1,26 @@ +/* Copyright (C) 2008-2009 Sun Microsystems, Inc + + 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 + the Free Software Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + +/** + @file mysql/psi/psi_abi_v1.h + ABI check for mysql/psi/psi.h, when using PSI_VERSION_2. + This file is only used to automate detection of changes between versions. + Do not include this file, include mysql/psi/psi.h instead. +*/ +#define USE_PSI_2 +#define HAVE_PSI_INTERFACE +#define _global_h +#include "mysql/psi/psi.h" + diff --git a/include/mysql/psi/psi_abi_v2.h.pp b/include/mysql/psi/psi_abi_v2.h.pp new file mode 100644 index 00000000000..b32415a59b4 --- /dev/null +++ b/include/mysql/psi/psi_abi_v2.h.pp @@ -0,0 +1,92 @@ +#include "mysql/psi/psi.h" +C_MODE_START +struct PSI_mutex; +struct PSI_rwlock; +struct PSI_cond; +struct PSI_table_share; +struct PSI_table; +struct PSI_thread; +struct PSI_file; +struct PSI_bootstrap +{ + void* (*get_interface)(int version); +}; +struct PSI_mutex_locker; +struct PSI_rwlock_locker; +struct PSI_cond_locker; +struct PSI_file_locker; +enum PSI_mutex_operation +{ + PSI_MUTEX_LOCK= 0, + PSI_MUTEX_TRYLOCK= 1 +}; +enum PSI_rwlock_operation +{ + PSI_RWLOCK_READLOCK= 0, + PSI_RWLOCK_WRITELOCK= 1, + PSI_RWLOCK_TRYREADLOCK= 2, + PSI_RWLOCK_TRYWRITELOCK= 3 +}; +enum PSI_cond_operation +{ + PSI_COND_WAIT= 0, + PSI_COND_TIMEDWAIT= 1 +}; +enum PSI_file_operation +{ + PSI_FILE_CREATE= 0, + PSI_FILE_CREATE_TMP= 1, + PSI_FILE_OPEN= 2, + PSI_FILE_STREAM_OPEN= 3, + PSI_FILE_CLOSE= 4, + PSI_FILE_STREAM_CLOSE= 5, + PSI_FILE_READ= 6, + PSI_FILE_WRITE= 7, + PSI_FILE_SEEK= 8, + PSI_FILE_TELL= 9, + PSI_FILE_FLUSH= 10, + PSI_FILE_STAT= 11, + PSI_FILE_FSTAT= 12, + PSI_FILE_CHSIZE= 13, + PSI_FILE_DELETE= 14, + PSI_FILE_RENAME= 15, + PSI_FILE_SYNC= 16 +}; +struct PSI_table_locker; +typedef unsigned int PSI_mutex_key; +typedef unsigned int PSI_rwlock_key; +typedef unsigned int PSI_cond_key; +typedef unsigned int PSI_thread_key; +typedef unsigned int PSI_file_key; +struct PSI_v2 +{ + int placeholder; +}; +struct PSI_mutex_info_v2 +{ + int placeholder; +}; +struct PSI_rwlock_info_v2 +{ + int placeholder; +}; +struct PSI_cond_info_v2 +{ + int placeholder; +}; +struct PSI_thread_info_v2 +{ + int placeholder; +}; +struct PSI_file_info_v2 +{ + int placeholder; +}; +typedef struct PSI_v2 PSI; +typedef struct PSI_mutex_info_v2 PSI_mutex_info; +typedef struct PSI_rwlock_info_v2 PSI_rwlock_info; +typedef struct PSI_cond_info_v2 PSI_cond_info; +typedef struct PSI_thread_info_v2 PSI_thread_info; +typedef struct PSI_file_info_v2 PSI_file_info; +extern MYSQL_PLUGIN_IMPORT PSI *PSI_server; +C_MODE_END diff --git a/libmysql/Makefile.am b/libmysql/Makefile.am index f67abfd8ac6..681b6fad1ff 100644 --- a/libmysql/Makefile.am +++ b/libmysql/Makefile.am @@ -1,4 +1,4 @@ -# Copyright (C) 2000-2004 MySQL AB +# Copyright (C) 2000-2004 MySQL AB, 2008-2009 Sun Microsystems, Inc. # # This program is free software; you can redistribute it and/or modify # it under the terms of version 2 GNU General Public License as @@ -21,7 +21,9 @@ # This file is public domain and comes with NO WARRANTY of any kind target = libmysqlclient.la -target_defs = -DMYSQL_CLIENT_NO_THREADS -DDONT_USE_RAID @LIB_EXTRA_CCFLAGS@ +target_defs = -DMYSQL_CLIENT_NO_THREADS -DDONT_USE_RAID \ + -DDISABLE_MYSQL_THREAD_H @LIB_EXTRA_CCFLAGS@ + LIBS = @CLIENT_LIBS@ INCLUDES = -I$(top_builddir)/include -I$(top_srcdir)/include \ $(openssl_includes) @ZLIB_INCLUDES@ diff --git a/libmysql/Makefile.shared b/libmysql/Makefile.shared index acc709bfb89..b626d3343ce 100644 --- a/libmysql/Makefile.shared +++ b/libmysql/Makefile.shared @@ -1,4 +1,4 @@ -# Copyright (C) 2000-2004 MySQL AB +# Copyright (C) 2000-2004 MySQL AB, 2008-2009 Sun Microsystems, Inc. # # This program is free software; you can redistribute it and/or modify # it under the terms of version 2 GNU General Public License as @@ -68,7 +68,8 @@ mysysobjects1 = my_init.lo my_static.lo my_malloc.lo my_realloc.lo \ mf_iocache2.lo my_seek.lo my_sleep.lo \ my_pread.lo mf_cache.lo md5.lo sha1.lo \ my_getopt.lo my_gethostbyname.lo my_port.lo \ - my_rename.lo my_chsize.lo my_sync.lo my_getsystime.lo + my_rename.lo my_chsize.lo my_sync.lo \ + my_getsystime.lo my_symlink2.lo mf_same.lo sqlobjects = net.lo sql_cmn_objects = pack.lo client.lo my_time.lo diff --git a/mysys/my_static.c b/mysys/my_static.c index 62caeee89c4..a86fe6c7ab7 100644 --- a/mysys/my_static.c +++ b/mysys/my_static.c @@ -124,3 +124,31 @@ my_bool NEAR my_disable_async_io=0; my_bool NEAR my_disable_flush_key_blocks=0; my_bool NEAR my_disable_symlinks=0; my_bool NEAR mysys_uses_curses=0; + +/* + Note that PSI_hook and PSI_server are unconditionally + (no ifdef HAVE_PSI_INTERFACE) defined. + This is to ensure binary compatibility between the server and plugins, + in the case when: + - the server is not compiled with HAVE_PSI_INTERFACE + - a plugin is compiled with HAVE_PSI_INTERFACE + See the doxygen documentation for the performance schema. +*/ + +/** + Hook for the instrumentation interface. + Code implementing the instrumentation interface should register here. +*/ +struct PSI_bootstrap *PSI_hook= NULL; + +/** + Instance of the instrumentation interface for the MySQL server. + @todo This is currently a global variable, which is handy when + compiling instrumented code that is bundled with the server. + When dynamic plugin are truly supported, this variable will need + to be replaced by a macro, so that each XYZ plugin can have it's own + xyz_psi_server variable, obtained from PSI_bootstrap::get_interface() + with the version used at compile time for plugin XYZ. +*/ +PSI *PSI_server= NULL; + diff --git a/mysys/my_winthread.c b/mysys/my_winthread.c index 9e8458b0799..f3d643975b3 100644 --- a/mysys/my_winthread.c +++ b/mysys/my_winthread.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2000 MySQL AB +/* Copyright (C) 2000 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -63,8 +63,8 @@ static unsigned int __stdcall pthread_start(void *p) } -int pthread_create(pthread_t *thread_id, pthread_attr_t *attr, - pthread_handler func, void *param) +int pthread_create(pthread_t *thread_id, const pthread_attr_t *attr, + pthread_handler func, void *param) { uintptr_t handle; struct thread_start_parameter *par; diff --git a/mysys/mysys_priv.h b/mysys/mysys_priv.h index 4c4d6ea3598..5c5bd6c2908 100644 --- a/mysys/mysys_priv.h +++ b/mysys/mysys_priv.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2000 MySQL AB +/* Copyright (C) 2000 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -26,12 +26,54 @@ #ifdef THREAD #include <my_pthread.h> + +#ifdef HAVE_PSI_INTERFACE + +#if !defined(HAVE_PREAD) && !defined(_WIN32) +extern PSI_mutex_key key_my_file_info_mutex; +#endif /* !defined(HAVE_PREAD) && !defined(_WIN32) */ + +#if !defined(HAVE_LOCALTIME_R) || !defined(HAVE_GMTIME_R) +extern PSI_mutex_key key_LOCK_localtime_r; +#endif /* !defined(HAVE_LOCALTIME_R) || !defined(HAVE_GMTIME_R) */ + +#ifndef HAVE_GETHOSTBYNAME_R +extern PSI_mutex_key key_LOCK_gethostbyname_r; +#endif /* HAVE_GETHOSTBYNAME_R */ + +extern PSI_mutex_key key_BITMAP_mutex, key_IO_CACHE_append_buffer_lock, + key_IO_CACHE_SHARE_mutex, key_KEY_CACHE_cache_lock, key_LOCK_alarm, + key_my_thread_var_mutex, key_THR_LOCK_charset, key_THR_LOCK_heap, + key_THR_LOCK_isam, key_THR_LOCK_lock, key_THR_LOCK_malloc, + key_THR_LOCK_mutex, key_THR_LOCK_myisam, key_THR_LOCK_net, + key_THR_LOCK_open, key_THR_LOCK_threads, key_THR_LOCK_time, + key_TMPDIR_mutex; + +extern PSI_cond_key key_COND_alarm, key_IO_CACHE_SHARE_cond, + key_IO_CACHE_SHARE_cond_writer, key_my_thread_var_suspend, + key_THR_COND_threads; + +#ifdef USE_ALARM_THREAD +extern PSI_thread_key key_thread_alarm; +#endif /* USE_ALARM_THREAD */ + +#endif /* HAVE_PSI_INTERFACE */ + extern pthread_mutex_t THR_LOCK_malloc, THR_LOCK_open, THR_LOCK_keycache; extern pthread_mutex_t THR_LOCK_lock, THR_LOCK_isam, THR_LOCK_net; extern pthread_mutex_t THR_LOCK_charset, THR_LOCK_time; -#else +#else /* THREAD */ #include <my_no_pthread.h> -#endif +#endif /* THREAD */ + +#include <mysql/psi/mysql_file.h> + +#ifdef HAVE_PSI_INTERFACE +#ifdef HUGETLB_USE_PROC_MEMINFO +extern PSI_file_key key_file_proc_meminfo; +#endif /* HUGETLB_USE_PROC_MEMINFO */ +extern PSI_file_key key_file_charset, key_file_cnf; +#endif /* HAVE_PSI_INTERFACE */ /* EDQUOT is used only in 3 C files only in mysys/. If it does not exist on diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h index b6ffcb238b2..48e0d52e2bd 100644 --- a/sql/mysql_priv.h +++ b/sql/mysql_priv.h @@ -1,4 +1,4 @@ -/* Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc. +/* Copyright 2000-2008 MySQL AB, 2008-2009 Sun Microsystems, Inc. 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 @@ -53,6 +53,7 @@ #include "sql_array.h" #include "sql_plugin.h" #include "scheduler.h" +#include <mysql/psi/mysql_file.h> #ifndef __WIN__ #include <netdb.h> #endif diff --git a/sql/sql_class.h b/sql/sql_class.h index 4bfd3e66438..b99c25782e0 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -2098,6 +2098,12 @@ public: proc_info = msg; return old_msg; } + inline const char* enter_cond(mysql_cond_t *cond, mysql_mutex_t *mutex, + const char *msg) + { + /* TO BE REMOVED: temporary helper, to help with merges */ + return enter_cond(&cond->m_cond, &mutex->m_mutex, msg); + } inline void exit_cond(const char* old_msg) { /* diff --git a/storage/archive/ha_archive.cc b/storage/archive/ha_archive.cc index f69b19369b2..2ff4a5daff5 100644 --- a/storage/archive/ha_archive.cc +++ b/storage/archive/ha_archive.cc @@ -1,4 +1,4 @@ -/* Copyright (C) 2003 MySQL AB +/* Copyright (C) 2003 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -95,7 +95,7 @@ */ /* Variables for archive share methods */ -pthread_mutex_t archive_mutex; +mysql_mutex_t archive_mutex; static HASH archive_open_tables; /* The file extension */ @@ -145,6 +145,28 @@ static uchar* archive_get_key(ARCHIVE_SHARE *share, size_t *length, return (uchar*) share->table_name; } +#ifdef HAVE_PSI_INTERFACE +PSI_mutex_key az_key_mutex_archive_mutex, az_key_mutex_ARCHIVE_SHARE_mutex; + +static PSI_mutex_info all_archive_mutexes[]= +{ + { &az_key_mutex_archive_mutex, "archive_mutex", PSI_FLAG_GLOBAL}, + { &az_key_mutex_ARCHIVE_SHARE_mutex, "ARCHIVE_SHARE::mutex", 0} +}; + +static void init_archive_psi_keys(void) +{ + const char* category= "archive"; + int count; + + if (PSI_server == NULL) + return; + + count= array_elements(all_archive_mutexes); + PSI_server->register_mutex(category, all_archive_mutexes, count); +} + +#endif /* HAVE_PSI_INTERFACE */ /* Initialize the archive handler. @@ -163,6 +185,10 @@ int archive_db_init(void *p) DBUG_ENTER("archive_db_init"); handlerton *archive_hton; +#ifdef HAVE_PSI_INTERFACE + init_archive_psi_keys(); +#endif + archive_hton= (handlerton *)p; archive_hton->state= SHOW_OPTION_YES; archive_hton->db_type= DB_TYPE_ARCHIVE_DB; @@ -170,12 +196,13 @@ int archive_db_init(void *p) archive_hton->flags= HTON_NO_FLAGS; archive_hton->discover= archive_discover; - if (pthread_mutex_init(&archive_mutex, MY_MUTEX_INIT_FAST)) + if (mysql_mutex_init(az_key_mutex_archive_mutex, + &archive_mutex, MY_MUTEX_INIT_FAST)) goto error; if (my_hash_init(&archive_open_tables, table_alias_charset, 32, 0, 0, (my_hash_get_key) archive_get_key, 0, 0)) { - pthread_mutex_destroy(&archive_mutex); + mysql_mutex_destroy(&archive_mutex); } else { @@ -199,7 +226,7 @@ error: int archive_db_done(void *p) { my_hash_free(&archive_open_tables); - pthread_mutex_destroy(&archive_mutex); + mysql_mutex_destroy(&archive_mutex); return 0; } @@ -313,7 +340,7 @@ ARCHIVE_SHARE *ha_archive::get_share(const char *table_name, int *rc) uint length; DBUG_ENTER("ha_archive::get_share"); - pthread_mutex_lock(&archive_mutex); + mysql_mutex_lock(&archive_mutex); length=(uint) strlen(table_name); if (!(share=(ARCHIVE_SHARE*) my_hash_search(&archive_open_tables, @@ -328,7 +355,7 @@ ARCHIVE_SHARE *ha_archive::get_share(const char *table_name, int *rc) &tmp_name, length+1, NullS)) { - pthread_mutex_unlock(&archive_mutex); + mysql_mutex_unlock(&archive_mutex); *rc= HA_ERR_OUT_OF_MEM; DBUG_RETURN(NULL); } @@ -346,7 +373,8 @@ ARCHIVE_SHARE *ha_archive::get_share(const char *table_name, int *rc) /* We will use this lock for rows. */ - pthread_mutex_init(&share->mutex,MY_MUTEX_INIT_FAST); + mysql_mutex_init(az_key_mutex_ARCHIVE_SHARE_mutex, + &share->mutex, MY_MUTEX_INIT_FAST); /* We read the meta file, but do not mark it dirty. Since we are not @@ -372,7 +400,7 @@ ARCHIVE_SHARE *ha_archive::get_share(const char *table_name, int *rc) share->use_count)); if (share->crashed) *rc= HA_ERR_CRASHED_ON_USAGE; - pthread_mutex_unlock(&archive_mutex); + mysql_mutex_unlock(&archive_mutex); DBUG_RETURN(share); } @@ -391,12 +419,12 @@ int ha_archive::free_share() share->table_name_length, share->table_name, share->use_count)); - pthread_mutex_lock(&archive_mutex); + mysql_mutex_lock(&archive_mutex); if (!--share->use_count) { my_hash_delete(&archive_open_tables, (uchar*) share); thr_lock_delete(&share->lock); - pthread_mutex_destroy(&share->mutex); + mysql_mutex_destroy(&share->mutex); /* We need to make sure we don't reset the crashed state. If we open a crashed file, wee need to close it as crashed unless @@ -411,7 +439,7 @@ int ha_archive::free_share() } my_free((uchar*) share, MYF(0)); } - pthread_mutex_unlock(&archive_mutex); + mysql_mutex_unlock(&archive_mutex); DBUG_RETURN(rc); } @@ -651,7 +679,7 @@ int ha_archive::create(const char *name, TABLE *table_arg, */ if ((frm_file= my_open(name_buff, O_RDONLY, MYF(0))) > 0) { - if (!my_fstat(frm_file, &file_stat, MYF(MY_WME))) + if (!mysql_file_fstat(frm_file, &file_stat, MYF(MY_WME))) { frm_ptr= (uchar *)my_malloc(sizeof(uchar) * file_stat.st_size, MYF(0)); if (frm_ptr) @@ -800,7 +828,7 @@ int ha_archive::write_row(uchar *buf) ha_statistic_increment(&SSV::ha_write_count); if (table->timestamp_field_type & TIMESTAMP_AUTO_SET_ON_INSERT) table->timestamp_field->set_time(); - pthread_mutex_lock(&share->mutex); + mysql_mutex_lock(&share->mutex); if (!share->archive_write_open) if (init_archive_writer()) @@ -883,7 +911,7 @@ int ha_archive::write_row(uchar *buf) share->rows_recorded++; rc= real_write_row(buf, &(share->archive_write)); error: - pthread_mutex_unlock(&share->mutex); + mysql_mutex_unlock(&share->mutex); if (read_buf) my_free((uchar*) read_buf, MYF(0)); @@ -1387,7 +1415,7 @@ int ha_archive::optimize(THD* thd, HA_CHECK_OPT* check_opt) azclose(&archive); // make the file we just wrote be our data file - rc = my_rename(writer_filename,share->data_file_name,MYF(0)); + rc= my_rename(writer_filename, share->data_file_name, MYF(0)); DBUG_RETURN(rc); @@ -1471,7 +1499,7 @@ int ha_archive::info(uint flag) If dirty, we lock, and then reset/flush the data. I found that just calling azflush() doesn't always work. */ - pthread_mutex_lock(&share->mutex); + mysql_mutex_lock(&share->mutex); if (share->dirty == TRUE) { if (share->dirty == TRUE) @@ -1487,7 +1515,7 @@ int ha_archive::info(uint flag) cause the number to be inaccurate. */ stats.records= share->rows_recorded; - pthread_mutex_unlock(&share->mutex); + mysql_mutex_unlock(&share->mutex); stats.deleted= 0; @@ -1512,9 +1540,9 @@ int ha_archive::info(uint flag) if (flag & HA_STATUS_AUTO) { init_archive_reader(); - pthread_mutex_lock(&share->mutex); + mysql_mutex_lock(&share->mutex); azflush(&archive, Z_SYNC_FLUSH); - pthread_mutex_unlock(&share->mutex); + mysql_mutex_unlock(&share->mutex); stats.auto_increment_value= archive.auto_increment + 1; } @@ -1582,9 +1610,9 @@ int ha_archive::check(THD* thd, HA_CHECK_OPT* check_opt) old_proc_info= thd_proc_info(thd, "Checking table"); /* Flush any waiting data */ - pthread_mutex_lock(&share->mutex); + mysql_mutex_lock(&share->mutex); azflush(&(share->archive_write), Z_SYNC_FLUSH); - pthread_mutex_unlock(&share->mutex); + mysql_mutex_unlock(&share->mutex); /* Now we will rewind the archive file so that we are positioned at the diff --git a/storage/archive/ha_archive.h b/storage/archive/ha_archive.h index ab630ed22fd..94842203f16 100644 --- a/storage/archive/ha_archive.h +++ b/storage/archive/ha_archive.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2003 MySQL AB +/* Copyright (C) 2003 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -36,7 +36,7 @@ typedef struct st_archive_share { char *table_name; char data_file_name[FN_REFLEN]; uint table_name_length,use_count; - pthread_mutex_t mutex; + mysql_mutex_t mutex; THR_LOCK lock; azio_stream archive_write; /* Archive file we are working with */ bool archive_write_open; diff --git a/storage/blackhole/ha_blackhole.cc b/storage/blackhole/ha_blackhole.cc index 6aa090263d5..e10054a79f2 100644 --- a/storage/blackhole/ha_blackhole.cc +++ b/storage/blackhole/ha_blackhole.cc @@ -1,4 +1,4 @@ -/* Copyright 2005-2008 MySQL AB, 2008 Sun Microsystems, Inc. +/* Copyright 2005-2008 MySQL AB, 2008-2009 Sun Microsystems, Inc. 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 @@ -35,7 +35,7 @@ static handler *blackhole_create_handler(handlerton *hton, /* Static declarations for shared structures */ -static pthread_mutex_t blackhole_mutex; +static mysql_mutex_t blackhole_mutex; static HASH blackhole_open_tables; static st_blackhole_share *get_share(const char *table_name); @@ -317,7 +317,7 @@ static st_blackhole_share *get_share(const char *table_name) uint length; length= (uint) strlen(table_name); - pthread_mutex_lock(&blackhole_mutex); + mysql_mutex_lock(&blackhole_mutex); if (!(share= (st_blackhole_share*) my_hash_search(&blackhole_open_tables, @@ -343,16 +343,16 @@ static st_blackhole_share *get_share(const char *table_name) share->use_count++; error: - pthread_mutex_unlock(&blackhole_mutex); + mysql_mutex_unlock(&blackhole_mutex); return share; } static void free_share(st_blackhole_share *share) { - pthread_mutex_lock(&blackhole_mutex); + mysql_mutex_lock(&blackhole_mutex); if (!--share->use_count) my_hash_delete(&blackhole_open_tables, (uchar*) share); - pthread_mutex_unlock(&blackhole_mutex); + mysql_mutex_unlock(&blackhole_mutex); } static void blackhole_free_key(st_blackhole_share *share) @@ -368,16 +368,43 @@ static uchar* blackhole_get_key(st_blackhole_share *share, size_t *length, return (uchar*) share->table_name; } +#ifdef HAVE_PSI_INTERFACE +static PSI_mutex_key bh_key_mutex_blackhole; + +static PSI_mutex_info all_blackhole_mutexes[]= +{ + { &bh_key_mutex_blackhole, "blackhole", PSI_FLAG_GLOBAL} +}; + +void init_blackhole_psi_keys() +{ + const char* category= "blackhole"; + int count; + + if (PSI_server == NULL) + return; + + count= array_elements(all_blackhole_mutexes); + PSI_server->register_mutex(category, all_blackhole_mutexes, count); +} +#endif + static int blackhole_init(void *p) { handlerton *blackhole_hton; + +#ifdef HAVE_PSI_INTERFACE + init_blackhole_psi_keys(); +#endif + blackhole_hton= (handlerton *)p; blackhole_hton->state= SHOW_OPTION_YES; blackhole_hton->db_type= DB_TYPE_BLACKHOLE_DB; blackhole_hton->create= blackhole_create_handler; blackhole_hton->flags= HTON_CAN_RECREATE; - - pthread_mutex_init(&blackhole_mutex, MY_MUTEX_INIT_FAST); + + mysql_mutex_init(bh_key_mutex_blackhole, + &blackhole_mutex, MY_MUTEX_INIT_FAST); (void) my_hash_init(&blackhole_open_tables, system_charset_info,32,0,0, (my_hash_get_key) blackhole_get_key, (my_hash_free_key) blackhole_free_key, 0); @@ -388,7 +415,7 @@ static int blackhole_init(void *p) static int blackhole_fini(void *p) { my_hash_free(&blackhole_open_tables); - pthread_mutex_destroy(&blackhole_mutex); + mysql_mutex_destroy(&blackhole_mutex); return 0; } diff --git a/storage/csv/ha_tina.cc b/storage/csv/ha_tina.cc index 5348b5b9331..65d7cd4a9c1 100644 --- a/storage/csv/ha_tina.cc +++ b/storage/csv/ha_tina.cc @@ -1,4 +1,4 @@ -/* Copyright (C) 2003 MySQL AB +/* Copyright (C) 2003 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -75,7 +75,7 @@ extern "C" void tina_update_status(void* param); extern "C" my_bool tina_check_status(void* param); /* Stuff for shares */ -pthread_mutex_t tina_mutex; +mysql_mutex_t tina_mutex; static HASH tina_open_tables; static handler *tina_create_handler(handlerton *hton, TABLE_SHARE *table, @@ -105,12 +105,52 @@ static uchar* tina_get_key(TINA_SHARE *share, size_t *length, return (uchar*) share->table_name; } +#ifdef HAVE_PSI_INTERFACE + +static PSI_mutex_key csv_key_mutex_tina, csv_key_mutex_TINA_SHARE_mutex; + +static PSI_mutex_info all_tina_mutexes[]= +{ + { &csv_key_mutex_tina, "tina", PSI_FLAG_GLOBAL}, + { &csv_key_mutex_TINA_SHARE_mutex, "TINA_SHARE::mutex", 0} +}; + +static PSI_file_key csv_key_file_metadata, csv_key_file_data, + csv_key_file_update; + +static PSI_file_info all_tina_files[]= +{ + { &csv_key_file_metadata, "metadata", 0}, + { &csv_key_file_data, "data", 0}, + { &csv_key_file_update, "update", 0} +}; + +static void init_tina_psi_keys(void) +{ + const char* category= "csv"; + int count; + + if (PSI_server == NULL) + return; + + count= array_elements(all_tina_mutexes); + PSI_server->register_mutex(category, all_tina_mutexes, count); + + count= array_elements(all_tina_files); + PSI_server->register_file(category, all_tina_files, count); +} +#endif /* HAVE_PSI_INTERFACE */ + static int tina_init_func(void *p) { handlerton *tina_hton; +#ifdef HAVE_PSI_INTERFACE + init_tina_psi_keys(); +#endif + tina_hton= (handlerton *)p; - pthread_mutex_init(&tina_mutex,MY_MUTEX_INIT_FAST); + mysql_mutex_init(csv_key_mutex_tina, &tina_mutex, MY_MUTEX_INIT_FAST); (void) my_hash_init(&tina_open_tables,system_charset_info,32,0,0, (my_hash_get_key) tina_get_key,0,0); tina_hton->state= SHOW_OPTION_YES; @@ -124,7 +164,7 @@ static int tina_init_func(void *p) static int tina_done_func(void *p) { my_hash_free(&tina_open_tables); - pthread_mutex_destroy(&tina_mutex); + mysql_mutex_destroy(&tina_mutex); return 0; } @@ -141,7 +181,7 @@ static TINA_SHARE *get_share(const char *table_name, TABLE *table) char *tmp_name; uint length; - pthread_mutex_lock(&tina_mutex); + mysql_mutex_lock(&tina_mutex); length=(uint) strlen(table_name); /* @@ -157,7 +197,7 @@ static TINA_SHARE *get_share(const char *table_name, TABLE *table) &tmp_name, length+1, NullS)) { - pthread_mutex_unlock(&tina_mutex); + mysql_mutex_unlock(&tina_mutex); return NULL; } @@ -176,14 +216,16 @@ static TINA_SHARE *get_share(const char *table_name, TABLE *table) fn_format(meta_file_name, table_name, "", CSM_EXT, MY_REPLACE_EXT|MY_UNPACK_FILENAME); - if (my_stat(share->data_file_name, &file_stat, MYF(MY_WME)) == NULL) + if (mysql_file_stat(csv_key_file_data, + share->data_file_name, &file_stat, MYF(MY_WME)) == NULL) goto error; share->saved_data_file_length= file_stat.st_size; if (my_hash_insert(&tina_open_tables, (uchar*) share)) goto error; thr_lock_init(&share->lock); - pthread_mutex_init(&share->mutex,MY_MUTEX_INIT_FAST); + mysql_mutex_init(csv_key_mutex_TINA_SHARE_mutex, + &share->mutex, MY_MUTEX_INIT_FAST); /* Open or create the meta file. In the latter case, we'll get @@ -191,19 +233,21 @@ static TINA_SHARE *get_share(const char *table_name, TABLE *table) Usually this will result in auto-repair, and we will get a good meta-file in the end. */ - if (((share->meta_file= my_open(meta_file_name, - O_RDWR|O_CREAT, MYF(MY_WME))) == -1) || + if (((share->meta_file= mysql_file_open(csv_key_file_metadata, + meta_file_name, + O_RDWR|O_CREAT, + MYF(MY_WME))) == -1) || read_meta_file(share->meta_file, &share->rows_recorded)) share->crashed= TRUE; } share->use_count++; - pthread_mutex_unlock(&tina_mutex); + mysql_mutex_unlock(&tina_mutex); return share; error: - pthread_mutex_unlock(&tina_mutex); + mysql_mutex_unlock(&tina_mutex); my_free((uchar*) share, MYF(0)); return NULL; @@ -236,8 +280,8 @@ static int read_meta_file(File meta_file, ha_rows *rows) DBUG_ENTER("ha_tina::read_meta_file"); - my_seek(meta_file, 0, MY_SEEK_SET, MYF(0)); - if (my_read(meta_file, (uchar*)meta_buffer, META_BUFFER_SIZE, 0) + mysql_file_seek(meta_file, 0, MY_SEEK_SET, MYF(0)); + if (mysql_file_read(meta_file, (uchar*)meta_buffer, META_BUFFER_SIZE, 0) != META_BUFFER_SIZE) DBUG_RETURN(HA_ERR_CRASHED_ON_USAGE); @@ -259,7 +303,7 @@ static int read_meta_file(File meta_file, ha_rows *rows) ((bool)(*ptr)== TRUE)) DBUG_RETURN(HA_ERR_CRASHED_ON_USAGE); - my_sync(meta_file, MYF(MY_WME)); + mysql_file_sync(meta_file, MYF(MY_WME)); DBUG_RETURN(0); } @@ -305,12 +349,12 @@ static int write_meta_file(File meta_file, ha_rows rows, bool dirty) ptr+= 3*sizeof(ulonglong); *ptr= (uchar)dirty; - my_seek(meta_file, 0, MY_SEEK_SET, MYF(0)); - if (my_write(meta_file, (uchar *)meta_buffer, META_BUFFER_SIZE, 0) + mysql_file_seek(meta_file, 0, MY_SEEK_SET, MYF(0)); + if (mysql_file_write(meta_file, (uchar *)meta_buffer, META_BUFFER_SIZE, 0) != META_BUFFER_SIZE) DBUG_RETURN(-1); - my_sync(meta_file, MYF(MY_WME)); + mysql_file_sync(meta_file, MYF(MY_WME)); DBUG_RETURN(0); } @@ -338,7 +382,9 @@ int ha_tina::init_tina_writer() (void)write_meta_file(share->meta_file, share->rows_recorded, TRUE); if ((share->tina_write_filedes= - my_open(share->data_file_name, O_RDWR|O_APPEND, MYF(MY_WME))) == -1) + mysql_file_open(csv_key_file_data, + share->data_file_name, O_RDWR|O_APPEND, + MYF(MY_WME))) == -1) { DBUG_PRINT("info", ("Could not open tina file writes")); share->crashed= TRUE; @@ -362,27 +408,27 @@ bool ha_tina::is_crashed() const static int free_share(TINA_SHARE *share) { DBUG_ENTER("ha_tina::free_share"); - pthread_mutex_lock(&tina_mutex); + mysql_mutex_lock(&tina_mutex); int result_code= 0; if (!--share->use_count){ /* Write the meta file. Mark it as crashed if needed. */ (void)write_meta_file(share->meta_file, share->rows_recorded, share->crashed ? TRUE :FALSE); - if (my_close(share->meta_file, MYF(0))) + if (mysql_file_close(share->meta_file, MYF(0))) result_code= 1; if (share->tina_write_opened) { - if (my_close(share->tina_write_filedes, MYF(0))) + if (mysql_file_close(share->tina_write_filedes, MYF(0))) result_code= 1; share->tina_write_opened= FALSE; } my_hash_delete(&tina_open_tables, (uchar*) share); thr_lock_delete(&share->lock); - pthread_mutex_destroy(&share->mutex); + mysql_mutex_destroy(&share->mutex); my_free((uchar*) share, MYF(0)); } - pthread_mutex_unlock(&tina_mutex); + mysql_mutex_unlock(&tina_mutex); DBUG_RETURN(result_code); } @@ -769,9 +815,9 @@ void ha_tina::get_status() We have to use mutex to follow pthreads memory visibility rules for share->saved_data_file_length */ - pthread_mutex_lock(&share->mutex); + mysql_mutex_lock(&share->mutex); local_saved_data_file_length= share->saved_data_file_length; - pthread_mutex_unlock(&share->mutex); + mysql_mutex_unlock(&share->mutex); return; } local_saved_data_file_length= share->saved_data_file_length; @@ -825,8 +871,9 @@ int ha_tina::open(const char *name, int mode, uint open_options) } local_data_file_version= share->data_file_version; - if ((data_file= my_open(share->data_file_name, - O_RDONLY, MYF(MY_WME))) == -1) + if ((data_file= mysql_file_open(csv_key_file_data, + share->data_file_name, + O_RDONLY, MYF(MY_WME))) == -1) { free_share(share); DBUG_RETURN(my_errno ? my_errno : -1); @@ -856,7 +903,7 @@ int ha_tina::close(void) { int rc= 0; DBUG_ENTER("ha_tina::close"); - rc= my_close(data_file, MYF(0)); + rc= mysql_file_close(data_file, MYF(0)); DBUG_RETURN(free_share(share) || rc); } @@ -885,20 +932,20 @@ int ha_tina::write_row(uchar * buf) DBUG_RETURN(-1); /* use pwrite, as concurrent reader could have changed the position */ - if (my_write(share->tina_write_filedes, (uchar*)buffer.ptr(), size, - MYF(MY_WME | MY_NABP))) + if (mysql_file_write(share->tina_write_filedes, (uchar*)buffer.ptr(), size, + MYF(MY_WME | MY_NABP))) DBUG_RETURN(-1); /* update local copy of the max position to see our own changes */ local_saved_data_file_length+= size; /* update shared info */ - pthread_mutex_lock(&share->mutex); + mysql_mutex_lock(&share->mutex); share->rows_recorded++; /* update status for the log tables */ if (share->is_log_table) update_status(); - pthread_mutex_unlock(&share->mutex); + mysql_mutex_unlock(&share->mutex); stats.records++; DBUG_RETURN(0); @@ -912,10 +959,11 @@ int ha_tina::open_update_temp_file_if_needed() if (!share->update_file_opened) { if ((update_temp_file= - my_create(fn_format(updated_fname, share->table_name, - "", CSN_EXT, - MY_REPLACE_EXT | MY_UNPACK_FILENAME), - 0, O_RDWR | O_TRUNC, MYF(MY_WME))) < 0) + mysql_file_create(csv_key_file_update, + fn_format(updated_fname, share->table_name, + "", CSN_EXT, + MY_REPLACE_EXT | MY_UNPACK_FILENAME), + 0, O_RDWR | O_TRUNC, MYF(MY_WME))) < 0) return 1; share->update_file_opened= TRUE; temp_file_length= 0; @@ -957,8 +1005,8 @@ int ha_tina::update_row(const uchar * old_data, uchar * new_data) if (open_update_temp_file_if_needed()) goto err; - if (my_write(update_temp_file, (uchar*)buffer.ptr(), size, - MYF(MY_WME | MY_NABP))) + if (mysql_file_write(update_temp_file, (uchar*)buffer.ptr(), size, + MYF(MY_WME | MY_NABP))) goto err; temp_file_length+= size; rc= 0; @@ -992,9 +1040,9 @@ int ha_tina::delete_row(const uchar * buf) stats.records--; /* Update shared info */ DBUG_ASSERT(share->rows_recorded); - pthread_mutex_lock(&share->mutex); + mysql_mutex_lock(&share->mutex); share->rows_recorded--; - pthread_mutex_unlock(&share->mutex); + mysql_mutex_unlock(&share->mutex); /* DELETE should never happen on the log table */ DBUG_ASSERT(!share->is_log_table); @@ -1021,8 +1069,10 @@ int ha_tina::init_data_file() if (local_data_file_version != share->data_file_version) { local_data_file_version= share->data_file_version; - if (my_close(data_file, MYF(0)) || - (data_file= my_open(share->data_file_name, O_RDONLY, MYF(MY_WME))) == -1) + if (mysql_file_close(data_file, MYF(0)) || + (data_file= mysql_file_open(csv_key_file_data, + share->data_file_name, O_RDONLY, + MYF(MY_WME))) == -1) return my_errno ? my_errno : -1; } file_buff->init_buff(data_file); @@ -1184,9 +1234,9 @@ int ha_tina::extra(enum ha_extra_function operation) DBUG_ENTER("ha_tina::extra"); if (operation == HA_EXTRA_MARK_AS_LOG_TABLE) { - pthread_mutex_lock(&share->mutex); + mysql_mutex_lock(&share->mutex); share->is_log_table= TRUE; - pthread_mutex_unlock(&share->mutex); + mysql_mutex_unlock(&share->mutex); } DBUG_RETURN(0); } @@ -1255,10 +1305,10 @@ int ha_tina::rnd_end() /* if there is something to write, write it */ if (write_length) { - if (my_write(update_temp_file, - (uchar*) (file_buff->ptr() + - (write_begin - file_buff->start())), - (size_t)write_length, MYF_RW)) + if (mysql_file_write(update_temp_file, + (uchar*) (file_buff->ptr() + + (write_begin - file_buff->start())), + (size_t)write_length, MYF_RW)) goto error; temp_file_length+= write_length; } @@ -1279,15 +1329,15 @@ int ha_tina::rnd_end() } - if (my_sync(update_temp_file, MYF(MY_WME)) || - my_close(update_temp_file, MYF(0))) + if (mysql_file_sync(update_temp_file, MYF(MY_WME)) || + mysql_file_close(update_temp_file, MYF(0))) DBUG_RETURN(-1); share->update_file_opened= FALSE; if (share->tina_write_opened) { - if (my_close(share->tina_write_filedes, MYF(0))) + if (mysql_file_close(share->tina_write_filedes, MYF(0))) DBUG_RETURN(-1); /* Mark that the writer fd is closed, so that init_tina_writer() @@ -1300,15 +1350,18 @@ int ha_tina::rnd_end() Close opened fildes's. Then move updated file in place of the old datafile. */ - if (my_close(data_file, MYF(0)) || - my_rename(fn_format(updated_fname, share->table_name, "", CSN_EXT, - MY_REPLACE_EXT | MY_UNPACK_FILENAME), - share->data_file_name, MYF(0))) + if (mysql_file_close(data_file, MYF(0)) || + mysql_file_rename(csv_key_file_data, + fn_format(updated_fname, share->table_name, + "", CSN_EXT, + MY_REPLACE_EXT | MY_UNPACK_FILENAME), + share->data_file_name, MYF(0))) DBUG_RETURN(-1); /* Open the file again */ - if (((data_file= my_open(share->data_file_name, - O_RDONLY, MYF(MY_WME))) == -1)) + if (((data_file= mysql_file_open(csv_key_file_data, + share->data_file_name, + O_RDONLY, MYF(MY_WME))) == -1)) DBUG_RETURN(my_errno ? my_errno : -1); /* As we reopened the data file, increase share->data_file_version @@ -1335,7 +1388,7 @@ int ha_tina::rnd_end() DBUG_RETURN(0); error: - my_close(update_temp_file, MYF(0)); + mysql_file_close(update_temp_file, MYF(0)); share->update_file_opened= FALSE; DBUG_RETURN(-1); } @@ -1421,10 +1474,12 @@ int ha_tina::repair(THD* thd, HA_CHECK_OPT* check_opt) Otherwise we've encountered a bad row => repair is needed. Let us create a temporary file. */ - if ((repair_file= my_create(fn_format(repaired_fname, share->table_name, - "", CSN_EXT, - MY_REPLACE_EXT|MY_UNPACK_FILENAME), - 0, O_RDWR | O_TRUNC,MYF(MY_WME))) < 0) + if ((repair_file= mysql_file_create(csv_key_file_update, + fn_format(repaired_fname, + share->table_name, + "", CSN_EXT, + MY_REPLACE_EXT|MY_UNPACK_FILENAME), + 0, O_RDWR | O_TRUNC, MYF(MY_WME))) < 0) DBUG_RETURN(HA_ERR_CRASHED_ON_REPAIR); file_buff->init_buff(data_file); @@ -1438,8 +1493,8 @@ int ha_tina::repair(THD* thd, HA_CHECK_OPT* check_opt) { write_end= min(file_buff->end(), current_position); if ((write_end - write_begin) && - (my_write(repair_file, (uchar*)file_buff->ptr(), - (size_t) (write_end - write_begin), MYF_RW))) + (mysql_file_write(repair_file, (uchar*)file_buff->ptr(), + (size_t) (write_end - write_begin), MYF_RW))) DBUG_RETURN(-1); write_begin= write_end; @@ -1453,7 +1508,7 @@ int ha_tina::repair(THD* thd, HA_CHECK_OPT* check_opt) Close the files and rename repaired file to the datafile. We have to close the files, as on Windows one cannot rename a file, which descriptor is still open. EACCES will be returned - when trying to delete the "to"-file in my_rename(). + when trying to delete the "to"-file in mysql_file_rename(). */ if (share->tina_write_opened) { @@ -1462,17 +1517,20 @@ int ha_tina::repair(THD* thd, HA_CHECK_OPT* check_opt) during write_row execution. We need to close both instances to satisfy Win. */ - if (my_close(share->tina_write_filedes, MYF(0))) + if (mysql_file_close(share->tina_write_filedes, MYF(0))) DBUG_RETURN(my_errno ? my_errno : -1); share->tina_write_opened= FALSE; } - if (my_close(data_file,MYF(0)) || my_close(repair_file, MYF(0)) || - my_rename(repaired_fname, share->data_file_name, MYF(0))) + if (mysql_file_close(data_file, MYF(0)) || + mysql_file_close(repair_file, MYF(0)) || + mysql_file_rename(csv_key_file_data, + repaired_fname, share->data_file_name, MYF(0))) DBUG_RETURN(-1); /* Open the file again, it should now be repaired */ - if ((data_file= my_open(share->data_file_name, O_RDWR|O_APPEND, - MYF(MY_WME))) == -1) + if ((data_file= mysql_file_open(csv_key_file_data, + share->data_file_name, O_RDWR|O_APPEND, + MYF(MY_WME))) == -1) DBUG_RETURN(my_errno ? my_errno : -1); /* Set new file size. The file size will be updated by ::update_status() */ @@ -1500,13 +1558,13 @@ int ha_tina::delete_all_rows() DBUG_RETURN(-1); /* Truncate the file to zero size */ - rc= my_chsize(share->tina_write_filedes, 0, 0, MYF(MY_WME)); + rc= mysql_file_chsize(share->tina_write_filedes, 0, 0, MYF(MY_WME)); stats.records=0; /* Update shared info */ - pthread_mutex_lock(&share->mutex); + mysql_mutex_lock(&share->mutex); share->rows_recorded= 0; - pthread_mutex_unlock(&share->mutex); + mysql_mutex_unlock(&share->mutex); local_saved_data_file_length= 0; DBUG_RETURN(rc); } @@ -1550,20 +1608,22 @@ int ha_tina::create(const char *name, TABLE *table_arg, } - if ((create_file= my_create(fn_format(name_buff, name, "", CSM_EXT, - MY_REPLACE_EXT|MY_UNPACK_FILENAME), 0, - O_RDWR | O_TRUNC,MYF(MY_WME))) < 0) + if ((create_file= mysql_file_create(csv_key_file_metadata, + fn_format(name_buff, name, "", CSM_EXT, + MY_REPLACE_EXT|MY_UNPACK_FILENAME), + 0, O_RDWR | O_TRUNC, MYF(MY_WME))) < 0) DBUG_RETURN(-1); write_meta_file(create_file, 0, FALSE); - my_close(create_file, MYF(0)); + mysql_file_close(create_file, MYF(0)); - if ((create_file= my_create(fn_format(name_buff, name, "", CSV_EXT, - MY_REPLACE_EXT|MY_UNPACK_FILENAME),0, - O_RDWR | O_TRUNC,MYF(MY_WME))) < 0) + if ((create_file= mysql_file_create(csv_key_file_data, + fn_format(name_buff, name, "", CSV_EXT, + MY_REPLACE_EXT|MY_UNPACK_FILENAME), + 0, O_RDWR | O_TRUNC, MYF(MY_WME))) < 0) DBUG_RETURN(-1); - my_close(create_file, MYF(0)); + mysql_file_close(create_file, MYF(0)); DBUG_RETURN(0); } diff --git a/storage/csv/ha_tina.h b/storage/csv/ha_tina.h index a246d1858e5..7bb80170e87 100644 --- a/storage/csv/ha_tina.h +++ b/storage/csv/ha_tina.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2003 MySQL AB +/* Copyright (C) 2003 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -41,7 +41,7 @@ typedef struct st_tina_share { share initialization. */ my_off_t saved_data_file_length; - pthread_mutex_t mutex; + mysql_mutex_t mutex; THR_LOCK lock; bool update_file_opened; bool tina_write_opened; diff --git a/storage/csv/transparent_file.cc b/storage/csv/transparent_file.cc index 3d7afae85d4..937f1fb292a 100644 --- a/storage/csv/transparent_file.cc +++ b/storage/csv/transparent_file.cc @@ -1,4 +1,4 @@ -/* Copyright (C) 2003 MySQL AB +/* Copyright (C) 2003 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -35,9 +35,9 @@ void Transparent_file::init_buff(File filedes_arg) filedes= filedes_arg; /* read the beginning of the file */ lower_bound= 0; - my_seek(filedes, 0, MY_SEEK_SET, MYF(0)); + mysql_file_seek(filedes, 0, MY_SEEK_SET, MYF(0)); if (filedes && buff) - upper_bound= my_read(filedes, buff, buff_size, MYF(0)); + upper_bound= mysql_file_read(filedes, buff, buff_size, MYF(0)); } uchar *Transparent_file::ptr() @@ -63,7 +63,8 @@ my_off_t Transparent_file::read_next() No need to seek here, as the file managed by Transparent_file class always points to upper_bound byte */ - if ((bytes_read= my_read(filedes, buff, buff_size, MYF(0))) == MY_FILE_ERROR) + if ((bytes_read= mysql_file_read(filedes, buff, buff_size, MYF(0))) + == MY_FILE_ERROR) return (my_off_t) -1; /* end of file */ @@ -85,10 +86,10 @@ char Transparent_file::get_value(my_off_t offset) if ((lower_bound <= offset) && (((my_off_t) offset) < upper_bound)) return buff[offset - lower_bound]; - my_seek(filedes, offset, MY_SEEK_SET, MYF(0)); + mysql_file_seek(filedes, offset, MY_SEEK_SET, MYF(0)); /* read appropriate portion of the file */ - if ((bytes_read= my_read(filedes, buff, buff_size, - MYF(0))) == MY_FILE_ERROR) + if ((bytes_read= mysql_file_read(filedes, buff, buff_size, + MYF(0))) == MY_FILE_ERROR) return 0; lower_bound= offset; diff --git a/storage/example/ha_example.cc b/storage/example/ha_example.cc index 743c7423b80..8d2eb914a97 100644 --- a/storage/example/ha_example.cc +++ b/storage/example/ha_example.cc @@ -112,7 +112,7 @@ handlerton *example_hton; static HASH example_open_tables; /* The mutex used to init the hash; variable for example share methods */ -pthread_mutex_t example_mutex; +mysql_mutex_t example_mutex; /** @brief @@ -126,13 +126,39 @@ static uchar* example_get_key(EXAMPLE_SHARE *share, size_t *length, return (uchar*) share->table_name; } +#ifdef HAVE_PSI_INTERFACE +static PSI_mutex_key ex_key_mutex_example, ex_key_mutex_EXAMPLE_SHARE_mutex; + +static PSI_mutex_info all_example_mutexes[]= +{ + { &ex_key_mutex_example, "example", PSI_FLAG_GLOBAL}, + { &ex_key_mutex_EXAMPLE_SHARE_mutex, "EXAMPLE_SHARE::mutex", 0} +}; + +static void init_example_psi_keys() +{ + const char* category= "example"; + int count; + + if (PSI_server == NULL) + return; + + count= array_elements(all_example_mutexes); + PSI_server->register_mutex(category, all_example_mutexes, count); +} +#endif + static int example_init_func(void *p) { DBUG_ENTER("example_init_func"); +#ifdef HAVE_PSI_INTERFACE + init_example_psi_keys(); +#endif + example_hton= (handlerton *)p; - pthread_mutex_init(&example_mutex,MY_MUTEX_INIT_FAST); + mysql_mutex_init(ex_key_mutex_example, &example_mutex, MY_MUTEX_INIT_FAST); (void) my_hash_init(&example_open_tables,system_charset_info,32,0,0, (my_hash_get_key) example_get_key,0,0); @@ -152,7 +178,7 @@ static int example_done_func(void *p) if (example_open_tables.records) error= 1; my_hash_free(&example_open_tables); - pthread_mutex_destroy(&example_mutex); + mysql_mutex_destroy(&example_mutex); DBUG_RETURN(0); } @@ -172,7 +198,7 @@ static EXAMPLE_SHARE *get_share(const char *table_name, TABLE *table) uint length; char *tmp_name; - pthread_mutex_lock(&example_mutex); + mysql_mutex_lock(&example_mutex); length=(uint) strlen(table_name); if (!(share=(EXAMPLE_SHARE*) my_hash_search(&example_open_tables, @@ -185,7 +211,7 @@ static EXAMPLE_SHARE *get_share(const char *table_name, TABLE *table) &tmp_name, length+1, NullS))) { - pthread_mutex_unlock(&example_mutex); + mysql_mutex_unlock(&example_mutex); return NULL; } @@ -196,15 +222,16 @@ static EXAMPLE_SHARE *get_share(const char *table_name, TABLE *table) if (my_hash_insert(&example_open_tables, (uchar*) share)) goto error; thr_lock_init(&share->lock); - pthread_mutex_init(&share->mutex,MY_MUTEX_INIT_FAST); + mysql_mutex_init(ex_key_mutex_EXAMPLE_SHARE_mutex, + &share->mutex, MY_MUTEX_INIT_FAST); } share->use_count++; - pthread_mutex_unlock(&example_mutex); + mysql_mutex_unlock(&example_mutex); return share; error: - pthread_mutex_destroy(&share->mutex); + mysql_mutex_destroy(&share->mutex); my_free(share, MYF(0)); return NULL; @@ -219,15 +246,15 @@ error: static int free_share(EXAMPLE_SHARE *share) { - pthread_mutex_lock(&example_mutex); + mysql_mutex_lock(&example_mutex); if (!--share->use_count) { my_hash_delete(&example_open_tables, (uchar*) share); thr_lock_delete(&share->lock); - pthread_mutex_destroy(&share->mutex); + mysql_mutex_destroy(&share->mutex); my_free(share, MYF(0)); } - pthread_mutex_unlock(&example_mutex); + mysql_mutex_unlock(&example_mutex); return 0; } diff --git a/storage/example/ha_example.h b/storage/example/ha_example.h index ec3987ced5d..4f88d6ced8e 100644 --- a/storage/example/ha_example.h +++ b/storage/example/ha_example.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2003 MySQL AB +/* Copyright (C) 2003 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -42,7 +42,7 @@ typedef struct st_example_share { char *table_name; uint table_name_length,use_count; - pthread_mutex_t mutex; + mysql_mutex_t mutex; THR_LOCK lock; } EXAMPLE_SHARE; diff --git a/storage/federated/ha_federated.cc b/storage/federated/ha_federated.cc index c582adc43e6..a73a39440d7 100644 --- a/storage/federated/ha_federated.cc +++ b/storage/federated/ha_federated.cc @@ -1,4 +1,4 @@ -/* Copyright (C) 2004 MySQL AB +/* Copyright (C) 2004 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -388,7 +388,7 @@ /* Variables for federated share methods */ static HASH federated_open_tables; // To track open tables -pthread_mutex_t federated_mutex; // To init the hash +mysql_mutex_t federated_mutex; // To init the hash static char ident_quote_char= '`'; // Character for quoting // identifiers static char value_quote_char= '\''; // Character for quoting @@ -427,6 +427,28 @@ static uchar *federated_get_key(FEDERATED_SHARE *share, size_t *length, return (uchar*) share->share_key; } +#ifdef HAVE_PSI_INTERFACE +static PSI_mutex_key fe_key_mutex_federated, fe_key_mutex_FEDERATED_SHARE_mutex; + +static PSI_mutex_info all_federated_mutexes[]= +{ + { &fe_key_mutex_federated, "federated", PSI_FLAG_GLOBAL}, + { &fe_key_mutex_FEDERATED_SHARE_mutex, "FEDERATED_SHARE::mutex", 0} +}; + +static void init_federated_psi_keys(void) +{ + const char* category= "federated"; + int count; + + if (PSI_server == NULL) + return; + + count= array_elements(all_federated_mutexes); + PSI_server->register_mutex(category, all_federated_mutexes, count); +} +#endif /* HAVE_PSI_INTERFACE */ + /* Initialize the federated handler. @@ -442,6 +464,11 @@ static uchar *federated_get_key(FEDERATED_SHARE *share, size_t *length, int federated_db_init(void *p) { DBUG_ENTER("federated_db_init"); + +#ifdef HAVE_PSI_INTERFACE + init_federated_psi_keys(); +#endif /* HAVE_PSI_INTERFACE */ + handlerton *federated_hton= (handlerton *)p; federated_hton->state= SHOW_OPTION_YES; federated_hton->db_type= DB_TYPE_FEDERATED_DB; @@ -457,7 +484,8 @@ int federated_db_init(void *p) federated_hton->commit= 0; federated_hton->rollback= 0; - if (pthread_mutex_init(&federated_mutex, MY_MUTEX_INIT_FAST)) + if (mysql_mutex_init(fe_key_mutex_federated, + &federated_mutex, MY_MUTEX_INIT_FAST)) goto error; if (!my_hash_init(&federated_open_tables, &my_charset_bin, 32, 0, 0, (my_hash_get_key) federated_get_key, 0, 0)) @@ -465,7 +493,7 @@ int federated_db_init(void *p) DBUG_RETURN(FALSE); } - pthread_mutex_destroy(&federated_mutex); + mysql_mutex_destroy(&federated_mutex); error: DBUG_RETURN(TRUE); } @@ -484,7 +512,7 @@ error: int federated_done(void *p) { my_hash_free(&federated_open_tables); - pthread_mutex_destroy(&federated_mutex); + mysql_mutex_destroy(&federated_mutex); return 0; } @@ -1487,7 +1515,7 @@ static FEDERATED_SHARE *get_share(const char *table_name, TABLE *table) init_alloc_root(&mem_root, 256, 0); - pthread_mutex_lock(&federated_mutex); + mysql_mutex_lock(&federated_mutex); tmp_share.share_key= table_name; tmp_share.share_key_length= (uint) strlen(table_name); @@ -1529,18 +1557,19 @@ static FEDERATED_SHARE *get_share(const char *table_name, TABLE *table) if (my_hash_insert(&federated_open_tables, (uchar*) share)) goto error; thr_lock_init(&share->lock); - pthread_mutex_init(&share->mutex, MY_MUTEX_INIT_FAST); + mysql_mutex_init(fe_key_mutex_FEDERATED_SHARE_mutex, + &share->mutex, MY_MUTEX_INIT_FAST); } else free_root(&mem_root, MYF(0)); /* prevents memory leak */ share->use_count++; - pthread_mutex_unlock(&federated_mutex); + mysql_mutex_unlock(&federated_mutex); DBUG_RETURN(share); error: - pthread_mutex_unlock(&federated_mutex); + mysql_mutex_unlock(&federated_mutex); free_root(&mem_root, MYF(0)); DBUG_RETURN(NULL); } @@ -1557,15 +1586,15 @@ static int free_share(FEDERATED_SHARE *share) MEM_ROOT mem_root= share->mem_root; DBUG_ENTER("free_share"); - pthread_mutex_lock(&federated_mutex); + mysql_mutex_lock(&federated_mutex); if (!--share->use_count) { my_hash_delete(&federated_open_tables, (uchar*) share); thr_lock_delete(&share->lock); - pthread_mutex_destroy(&share->mutex); + mysql_mutex_destroy(&share->mutex); free_root(&mem_root, MYF(0)); } - pthread_mutex_unlock(&federated_mutex); + mysql_mutex_unlock(&federated_mutex); DBUG_RETURN(0); } diff --git a/storage/federated/ha_federated.h b/storage/federated/ha_federated.h index ea0a3d2f591..8efb8ed744a 100644 --- a/storage/federated/ha_federated.h +++ b/storage/federated/ha_federated.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2003 MySQL AB +/* Copyright (C) 2003 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -71,7 +71,7 @@ typedef struct st_federated_share { ushort port; size_t table_name_length, server_name_length, connect_string_length, use_count; - pthread_mutex_t mutex; + mysql_mutex_t mutex; THR_LOCK lock; } FEDERATED_SHARE; diff --git a/storage/heap/ha_heap.cc b/storage/heap/ha_heap.cc index 99c1ca5d2e9..8d07d21c6ae 100644 --- a/storage/heap/ha_heap.cc +++ b/storage/heap/ha_heap.cc @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2006 MySQL AB +/* Copyright (C) 2000-2006 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -39,6 +39,10 @@ int heap_init(void *p) { handlerton *heap_hton; +#ifdef HAVE_PSI_INTERFACE + init_heap_psi_keys(); +#endif + heap_hton= (handlerton *)p; heap_hton->state= SHOW_OPTION_YES; heap_hton->db_type= DB_TYPE_HEAP; @@ -106,9 +110,9 @@ int ha_heap::open(const char *name, int mode, uint test_if_locked) if (!file) { /* Couldn't open table; Remove the newly created table */ - pthread_mutex_lock(&THR_LOCK_heap); + mysql_mutex_lock(&THR_LOCK_heap); hp_free(internal_share); - pthread_mutex_unlock(&THR_LOCK_heap); + mysql_mutex_unlock(&THR_LOCK_heap); } implicit_emptied= 1; } diff --git a/storage/heap/heapdef.h b/storage/heap/heapdef.h index 3fc94062303..bc3c6bf7239 100644 --- a/storage/heap/heapdef.h +++ b/storage/heap/heapdef.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2002, 2004 MySQL AB +/* Copyright (C) 2000-2002, 2004 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -103,9 +103,14 @@ extern void hp_clear_keys(HP_SHARE *info); extern uint hp_rb_pack_key(HP_KEYDEF *keydef, uchar *key, const uchar *old, key_part_map keypart_map); #ifdef THREAD -extern pthread_mutex_t THR_LOCK_heap; -#else -#define pthread_mutex_lock(A) -#define pthread_mutex_unlock(A) +extern mysql_mutex_t THR_LOCK_heap; #endif + +#ifdef HAVE_PSI_INTERFACE +#ifdef THREAD +extern PSI_mutex_key hp_key_mutex_HP_SHARE_intern_lock; +#endif /* THREAD */ +void init_heap_psi_keys(); +#endif /* HAVE_PSI_INTERFACE */ + C_MODE_END diff --git a/storage/heap/hp_close.c b/storage/heap/hp_close.c index d571815980c..49d8ec376bb 100644 --- a/storage/heap/hp_close.c +++ b/storage/heap/hp_close.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2002 MySQL AB +/* Copyright (C) 2000-2002 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -24,9 +24,9 @@ int heap_close(HP_INFO *info) { int tmp; DBUG_ENTER("heap_close"); - pthread_mutex_lock(&THR_LOCK_heap); + mysql_mutex_lock(&THR_LOCK_heap); tmp= hp_close(info); - pthread_mutex_unlock(&THR_LOCK_heap); + mysql_mutex_unlock(&THR_LOCK_heap); DBUG_RETURN(tmp); } diff --git a/storage/heap/hp_create.c b/storage/heap/hp_create.c index 1440cbc0e98..3f651d1573c 100644 --- a/storage/heap/hp_create.c +++ b/storage/heap/hp_create.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2006 MySQL AB +/* Copyright (C) 2000-2006 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -32,7 +32,7 @@ int heap_create(const char *name, uint keys, HP_KEYDEF *keydef, if (!create_info->internal_table) { - pthread_mutex_lock(&THR_LOCK_heap); + mysql_mutex_lock(&THR_LOCK_heap); if ((share= hp_find_named_heap(name)) && share->open_count == 0) { hp_free(share); @@ -194,7 +194,8 @@ int heap_create(const char *name, uint keys, HP_KEYDEF *keydef, } #ifdef THREAD thr_lock_init(&share->lock); - pthread_mutex_init(&share->intern_lock,MY_MUTEX_INIT_FAST); + mysql_mutex_init(hp_key_mutex_HP_SHARE_intern_lock, + &share->intern_lock, MY_MUTEX_INIT_FAST); #endif if (!create_info->internal_table) { @@ -205,14 +206,14 @@ int heap_create(const char *name, uint keys, HP_KEYDEF *keydef, share->delete_on_close= 1; } if (!create_info->internal_table) - pthread_mutex_unlock(&THR_LOCK_heap); + mysql_mutex_unlock(&THR_LOCK_heap); *res= share; DBUG_RETURN(0); err: if (!create_info->internal_table) - pthread_mutex_unlock(&THR_LOCK_heap); + mysql_mutex_unlock(&THR_LOCK_heap); DBUG_RETURN(1); } /* heap_create */ @@ -266,7 +267,7 @@ int heap_delete_table(const char *name) reg1 HP_SHARE *share; DBUG_ENTER("heap_delete_table"); - pthread_mutex_lock(&THR_LOCK_heap); + mysql_mutex_lock(&THR_LOCK_heap); if ((share= hp_find_named_heap(name))) { heap_try_free(share); @@ -276,7 +277,7 @@ int heap_delete_table(const char *name) { result= my_errno=ENOENT; } - pthread_mutex_unlock(&THR_LOCK_heap); + mysql_mutex_unlock(&THR_LOCK_heap); DBUG_RETURN(result); } @@ -284,9 +285,9 @@ int heap_delete_table(const char *name) void heap_drop_table(HP_INFO *info) { DBUG_ENTER("heap_drop_table"); - pthread_mutex_lock(&THR_LOCK_heap); + mysql_mutex_lock(&THR_LOCK_heap); heap_try_free(info->s); - pthread_mutex_unlock(&THR_LOCK_heap); + mysql_mutex_unlock(&THR_LOCK_heap); DBUG_VOID_RETURN; } @@ -298,7 +299,7 @@ void hp_free(HP_SHARE *share) hp_clear(share); /* Remove blocks from memory */ #ifdef THREAD thr_lock_delete(&share->lock); - pthread_mutex_destroy(&share->intern_lock); + mysql_mutex_destroy(&share->intern_lock); #endif my_free((uchar*) share->name, MYF(0)); my_free((uchar*) share, MYF(0)); diff --git a/storage/heap/hp_open.c b/storage/heap/hp_open.c index 4d5ec6e27ac..feafa5d5cf1 100644 --- a/storage/heap/hp_open.c +++ b/storage/heap/hp_open.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2004, 2006 MySQL AB +/* Copyright (C) 2000-2004, 2006 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -69,13 +69,13 @@ HP_INFO *heap_open_from_share_and_register(HP_SHARE *share, int mode) HP_INFO *info; DBUG_ENTER("heap_open_from_share_and_register"); - pthread_mutex_lock(&THR_LOCK_heap); + mysql_mutex_lock(&THR_LOCK_heap); if ((info= heap_open_from_share(share, mode))) { info->open_list.data= (void*) info; heap_open_list= list_add(heap_open_list,&info->open_list); } - pthread_mutex_unlock(&THR_LOCK_heap); + mysql_mutex_unlock(&THR_LOCK_heap); DBUG_RETURN(info); } @@ -94,11 +94,11 @@ HP_INFO *heap_open(const char *name, int mode) HP_SHARE *share; DBUG_ENTER("heap_open"); - pthread_mutex_lock(&THR_LOCK_heap); + mysql_mutex_lock(&THR_LOCK_heap); if (!(share= hp_find_named_heap(name))) { my_errno= ENOENT; - pthread_mutex_unlock(&THR_LOCK_heap); + mysql_mutex_unlock(&THR_LOCK_heap); DBUG_RETURN(0); } if ((info= heap_open_from_share(share, mode))) @@ -106,7 +106,7 @@ HP_INFO *heap_open(const char *name, int mode) info->open_list.data= (void*) info; heap_open_list= list_add(heap_open_list,&info->open_list); } - pthread_mutex_unlock(&THR_LOCK_heap); + mysql_mutex_unlock(&THR_LOCK_heap); DBUG_RETURN(info); } diff --git a/storage/heap/hp_panic.c b/storage/heap/hp_panic.c index 9a2bd2c574e..87d982dff2a 100644 --- a/storage/heap/hp_panic.c +++ b/storage/heap/hp_panic.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2002 MySQL AB +/* Copyright (C) 2000-2002 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -23,7 +23,7 @@ int hp_panic(enum ha_panic_function flag) LIST *element,*next_open; DBUG_ENTER("hp_panic"); - pthread_mutex_lock(&THR_LOCK_heap); + mysql_mutex_lock(&THR_LOCK_heap); for (element=heap_open_list ; element ; element=next_open) { HP_INFO *info=(HP_INFO*) element->data; @@ -51,6 +51,6 @@ int hp_panic(enum ha_panic_function flag) break; } } - pthread_mutex_unlock(&THR_LOCK_heap); + mysql_mutex_unlock(&THR_LOCK_heap); DBUG_RETURN(0); } /* hp_panic */ diff --git a/storage/heap/hp_rename.c b/storage/heap/hp_rename.c index c2350450e2b..c4e8390cc43 100644 --- a/storage/heap/hp_rename.c +++ b/storage/heap/hp_rename.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2002 MySQL AB +/* Copyright (C) 2000-2002 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -25,17 +25,17 @@ int heap_rename(const char *old_name, const char *new_name) char *name_buff; DBUG_ENTER("heap_rename"); - pthread_mutex_lock(&THR_LOCK_heap); + mysql_mutex_lock(&THR_LOCK_heap); if ((info = hp_find_named_heap(old_name))) { if (!(name_buff=(char*) my_strdup(new_name,MYF(MY_WME)))) { - pthread_mutex_unlock(&THR_LOCK_heap); + mysql_mutex_unlock(&THR_LOCK_heap); DBUG_RETURN(my_errno); } my_free(info->name,MYF(0)); info->name=name_buff; } - pthread_mutex_unlock(&THR_LOCK_heap); + mysql_mutex_unlock(&THR_LOCK_heap); DBUG_RETURN(0); } diff --git a/storage/heap/hp_static.c b/storage/heap/hp_static.c index a501ba7e359..e1ca7d1f445 100644 --- a/storage/heap/hp_static.c +++ b/storage/heap/hp_static.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2001 MySQL AB +/* Copyright (C) 2000-2001 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -23,3 +23,34 @@ #endif LIST *heap_open_list=0,*heap_share_list=0; + +#ifdef HAVE_PSI_INTERFACE +#ifdef THREAD +PSI_mutex_key hp_key_mutex_HP_SHARE_intern_lock; + +static PSI_mutex_info all_heap_mutexes[]= +{ + { & hp_key_mutex_HP_SHARE_intern_lock, "HP_SHARE::intern_lock", 0} + /* + Note: + THR_LOCK_heap is part of mysys, not storage/heap. + */ +}; +#endif /* THREAD */ + +void init_heap_psi_keys() +{ +#ifdef THREAD + const char* category= "memory"; + int count; + + if (PSI_server == NULL) + return; + + count= array_elements(all_heap_mutexes); + PSI_server->register_mutex(category, all_heap_mutexes, count); +#endif /* THREAD */ +} +#endif /* HAVE_PSI_INTERFACE */ + + diff --git a/storage/myisam/ha_myisam.cc b/storage/myisam/ha_myisam.cc index 440a82b0da2..994821a5065 100644 --- a/storage/myisam/ha_myisam.cc +++ b/storage/myisam/ha_myisam.cc @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2006 MySQL AB +/* Copyright (C) 2000-2006 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -118,7 +118,7 @@ static void mi_check_print_msg(MI_CHECK *param, const char* msg_type, */ #ifdef THREAD if (param->need_print_msg_lock) - pthread_mutex_lock(¶m->print_msg_mutex); + mysql_mutex_lock(¶m->print_msg_mutex); #endif protocol->prepare_for_resend(); protocol->store(name, length, system_charset_info); @@ -130,7 +130,7 @@ static void mi_check_print_msg(MI_CHECK *param, const char* msg_type, msgbuf); #ifdef THREAD if (param->need_print_msg_lock) - pthread_mutex_unlock(¶m->print_msg_mutex); + mysql_mutex_unlock(¶m->print_msg_mutex); #endif return; } @@ -762,13 +762,13 @@ int ha_myisam::check(THD* thd, HA_CHECK_OPT* check_opt) mi_is_crashed(file)) { file->update|=HA_STATE_CHANGED | HA_STATE_ROW_CHANGED; - pthread_mutex_lock(&share->intern_lock); + mysql_mutex_lock(&share->intern_lock); share->state.changed&= ~(STATE_CHANGED | STATE_CRASHED | STATE_CRASHED_ON_REPAIR); if (!(table->db_stat & HA_READ_ONLY)) error=update_state_info(¶m,file,UPDATE_TIME | UPDATE_OPEN_COUNT | UPDATE_STAT); - pthread_mutex_unlock(&share->intern_lock); + mysql_mutex_unlock(&share->intern_lock); info(HA_STATUS_NO_LOCK | HA_STATUS_TIME | HA_STATUS_VARIABLE | HA_STATUS_CONST); } @@ -812,9 +812,9 @@ int ha_myisam::analyze(THD *thd, HA_CHECK_OPT* check_opt) error = chk_key(¶m, file); if (!error) { - pthread_mutex_lock(&share->intern_lock); + mysql_mutex_lock(&share->intern_lock); error=update_state_info(¶m,file,UPDATE_STAT); - pthread_mutex_unlock(&share->intern_lock); + mysql_mutex_unlock(&share->intern_lock); } else if (!mi_is_crashed(file) && !thd->killed) mi_mark_crashed(file); @@ -1926,6 +1926,10 @@ static int myisam_init(void *p) { handlerton *myisam_hton; +#ifdef HAVE_PSI_INTERFACE + init_myisam_psi_keys(); +#endif + myisam_hton= (handlerton *)p; myisam_hton->state= SHOW_OPTION_YES; myisam_hton->db_type= DB_TYPE_MYISAM; diff --git a/storage/myisam/mi_cache.c b/storage/myisam/mi_cache.c index d6dcc431a8d..139a50a7c0d 100644 --- a/storage/myisam/mi_cache.c +++ b/storage/myisam/mi_cache.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2003 MySQL AB +/* Copyright (C) 2000-2003 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -29,7 +29,7 @@ is set) - unread part is bzero'ed Note: out-of-cache reads are enabled for shared IO_CACHE's too, - as these reads will be cached by OS cache (and my_pread is always atomic) + as these reads will be cached by OS cache (and mysql_file_pread is always atomic) */ @@ -49,7 +49,7 @@ int _mi_read_cache(IO_CACHE *info, uchar *buff, my_off_t pos, uint length, if ((my_off_t) read_length > (my_off_t) (info->pos_in_file-pos)) read_length=(uint) (info->pos_in_file-pos); info->seek_not_done=1; - if (my_pread(info->file,buff,read_length,pos,MYF(MY_NABP))) + if (mysql_file_pread(info->file, buff, read_length, pos, MYF(MY_NABP))) DBUG_RETURN(1); if (!(length-=read_length)) DBUG_RETURN(0); @@ -88,7 +88,8 @@ int _mi_read_cache(IO_CACHE *info, uchar *buff, my_off_t pos, uint length, else { info->seek_not_done=1; - if ((read_length=my_pread(info->file,buff,length,pos,MYF(0))) == length) + if ((read_length= mysql_file_pread(info->file, buff, length, pos, + MYF(0))) == length) DBUG_RETURN(0); } if (!(flag & READING_HEADER) || (int) read_length == -1 || diff --git a/storage/myisam/mi_check.c b/storage/myisam/mi_check.c index 8ff803b58a0..8e55a7bc50e 100644 --- a/storage/myisam/mi_check.c +++ b/storage/myisam/mi_check.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2006 MySQL AB +/* Copyright (C) 2000-2006 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -53,8 +53,8 @@ #include "rt_index.h" #ifndef USE_RAID -#define my_raid_create(A,B,C,D,E,F,G) my_create(A,B,C,G) -#define my_raid_delete(A,B,C) my_delete(A,B) +#define my_raid_create(K, A, B, C, D, E, F, G) mysql_file_create(K, A, B, C, G) +#define my_raid_delete(K, A, B, C) mysql_file_delete(K, A, B) #endif /* Functions defined in this file */ @@ -175,8 +175,8 @@ int chk_del(MI_CHECK *param, register MI_INFO *info, uint test_flag) printf(" %9s",llstr(next_link,buff)); if (next_link >= info->state->data_file_length) goto wrong; - if (my_pread(info->dfile, (uchar*) buff,delete_link_length, - next_link,MYF(MY_NABP))) + if (mysql_file_pread(info->dfile, (uchar*) buff, delete_link_length, + next_link, MYF(MY_NABP))) { if (test_flag & T_VERBOSE) puts(""); mi_check_print_error(param,"Can't read delete-link at filepos: %s", @@ -338,7 +338,7 @@ int chk_size(MI_CHECK *param, register MI_INFO *info) flush_key_blocks(info->s->key_cache, info->s->kfile, FLUSH_FORCE_WRITE); - size= my_seek(info->s->kfile, 0L, MY_SEEK_END, MYF(MY_THREADSAFE)); + size= mysql_file_seek(info->s->kfile, 0L, MY_SEEK_END, MYF(MY_THREADSAFE)); if ((skr=(my_off_t) info->state->key_file_length) != size) { /* Don't give error if file generated by myisampack */ @@ -362,7 +362,7 @@ int chk_size(MI_CHECK *param, register MI_INFO *info) llstr(info->state->key_file_length,buff), llstr(info->s->base.max_key_file_length-1,buff)); - size=my_seek(info->dfile,0L,MY_SEEK_END,MYF(0)); + size= mysql_file_seek(info->dfile, 0L, MY_SEEK_END, MYF(0)); skr=(my_off_t) info->state->data_file_length; if (info->s->options & HA_OPTION_COMPRESS_RECORD) skr+= MEMMAP_EXTRA_MARGIN; @@ -598,8 +598,8 @@ static int chk_index_down(MI_CHECK *param, MI_INFO *info, MI_KEYDEF *keyinfo, { /* purecov: begin tested */ /* Give it a chance to fit in the real file size. */ - my_off_t max_length= my_seek(info->s->kfile, 0L, MY_SEEK_END, - MYF(MY_THREADSAFE)); + my_off_t max_length= mysql_file_seek(info->s->kfile, 0L, MY_SEEK_END, + MYF(MY_THREADSAFE)); mi_check_print_error(param, "Invalid key block position: %s " "key block size: %u file_length: %s", llstr(page, llbuff), keyinfo->block_length, @@ -1577,14 +1577,15 @@ int mi_repair(MI_CHECK *param, register MI_INFO *info, if (!rep_quick) { /* Get real path for data file */ - if ((new_file=my_raid_create(fn_format(param->temp_filename, - share->data_file_name, "", - DATA_TMP_EXT, 2+4), - 0,param->tmpfile_createflag, - share->base.raid_type, - share->base.raid_chunks, - share->base.raid_chunksize, - MYF(0))) < 0) + if ((new_file= my_raid_create(mi_key_file_datatmp, + fn_format(param->temp_filename, + share->data_file_name, "", + DATA_TMP_EXT, 2+4), + 0, param->tmpfile_createflag, + share->base.raid_type, + share->base.raid_chunks, + share->base.raid_chunksize, + MYF(0))) < 0) { mi_check_print_error(param,"Can't create new tempfile: '%s'", param->temp_filename); @@ -1608,7 +1609,7 @@ int mi_repair(MI_CHECK *param, register MI_INFO *info, sort_param.pos=sort_param.max_pos=share->pack.header_length; sort_param.filepos=new_header_length; param->read_cache.end_of_file=sort_info.filelength= - my_seek(info->dfile,0L,MY_SEEK_END,MYF(0)); + mysql_file_seek(info->dfile, 0L, MY_SEEK_END, MYF(0)); sort_info.dupp=0; sort_param.fix_datafile= (my_bool) (! rep_quick); sort_param.master=1; @@ -1670,7 +1671,7 @@ int mi_repair(MI_CHECK *param, register MI_INFO *info, { (void) fputs(" \r",stdout); (void) fflush(stdout); } - if (my_chsize(share->kfile,info->state->key_file_length,0,MYF(0))) + if (mysql_file_chsize(share->kfile, info->state->key_file_length, 0, MYF(0))) { mi_check_print_warning(param, "Can't change size of indexfile, error: %d", @@ -1700,7 +1701,7 @@ int mi_repair(MI_CHECK *param, register MI_INFO *info, if (!rep_quick) { - my_close(info->dfile,MYF(0)); + mysql_file_close(info->dfile, MYF(0)); info->dfile=new_file; info->state->data_file_length=sort_param.filepos; share->state.version=(ulong) time((time_t*) 0); /* Force reopen */ @@ -1733,7 +1734,7 @@ err: /* Replace the actual file with the temporary file */ if (new_file >= 0) { - my_close(new_file,MYF(0)); + mysql_file_close(new_file, MYF(0)); info->dfile=new_file= -1; if (change_to_newfile(share->data_file_name,MI_NAME_DEXT, DATA_TMP_EXT, share->base.raid_chunks, @@ -1750,9 +1751,10 @@ err: llstr(sort_param.start_recpos,llbuff)); if (new_file >= 0) { - (void) my_close(new_file,MYF(0)); - (void) my_raid_delete(param->temp_filename,info->s->base.raid_chunks, - MYF(MY_WME)); + (void) mysql_file_close(new_file, MYF(0)); + (void) my_raid_delete(mi_key_file_datatmp, + param->temp_filename, info->s->base.raid_chunks, + MYF(MY_WME)); info->rec_cache.file=-1; /* don't flush data to new_file, it's closed */ } mi_mark_crashed_on_repair(info); @@ -1949,9 +1951,11 @@ int mi_sort_index(MI_CHECK *param, register MI_INFO *info, char * name) /* Get real path for index file */ fn_format(param->temp_filename,name,"", MI_NAME_IEXT,2+4+32); - if ((new_file=my_create(fn_format(param->temp_filename,param->temp_filename, - "", INDEX_TMP_EXT,2+4), - 0,param->tmpfile_createflag,MYF(0))) <= 0) + if ((new_file= mysql_file_create(mi_key_file_datatmp, + fn_format(param->temp_filename, + param->temp_filename, + "", INDEX_TMP_EXT, 2+4), + 0, param->tmpfile_createflag, MYF(0))) <= 0) { mi_check_print_error(param,"Can't create new tempfile: '%s'", param->temp_filename); @@ -1991,9 +1995,9 @@ int mi_sort_index(MI_CHECK *param, register MI_INFO *info, char * name) /* Put same locks as old file */ share->r_locks= share->w_locks= share->tot_locks= 0; (void) _mi_writeinfo(info,WRITEINFO_UPDATE_KEYFILE); - (void) my_close(share->kfile,MYF(MY_WME)); + (void) mysql_file_close(share->kfile, MYF(MY_WME)); share->kfile = -1; - (void) my_close(new_file,MYF(MY_WME)); + (void) mysql_file_close(new_file, MYF(MY_WME)); if (change_to_newfile(share->index_file_name,MI_NAME_IEXT,INDEX_TMP_EXT,0, MYF(0)) || mi_open_keyfile(share)) @@ -2017,9 +2021,10 @@ int mi_sort_index(MI_CHECK *param, register MI_INFO *info, char * name) DBUG_RETURN(0); err: - (void) my_close(new_file,MYF(MY_WME)); + (void) mysql_file_close(new_file, MYF(MY_WME)); err2: - (void) my_delete(param->temp_filename,MYF(MY_WME)); + (void) mysql_file_delete(mi_key_file_datatmp, + param->temp_filename, MYF(MY_WME)); DBUG_RETURN(-1); } /* mi_sort_index */ @@ -2099,8 +2104,8 @@ static int sort_one_index(MI_CHECK *param, MI_INFO *info, MI_KEYDEF *keyinfo, /* Fill block with zero and write it to the new index file */ length=mi_getint(buff); bzero((uchar*) buff+length,keyinfo->block_length-length); - if (my_pwrite(new_file,(uchar*) buff,(uint) keyinfo->block_length, - new_page_pos,MYF(MY_NABP | MY_WAIT_IF_FULL))) + if (mysql_file_pwrite(new_file, (uchar*) buff, (uint) keyinfo->block_length, + new_page_pos, MYF(MY_NABP | MY_WAIT_IF_FULL))) { mi_check_print_error(param,"Can't write indexblock, error: %d",my_errno); goto err; @@ -2176,16 +2181,16 @@ int filecopy(MI_CHECK *param, File to,File from,my_off_t start, buff=tmp_buff; buff_length=IO_SIZE; } - my_seek(from,start,MY_SEEK_SET,MYF(0)); + mysql_file_seek(from, start, MY_SEEK_SET, MYF(0)); while (length > buff_length) { - if (my_read(from,(uchar*) buff,buff_length,MYF(MY_NABP)) || - my_write(to,(uchar*) buff,buff_length,param->myf_rw)) + if (mysql_file_read(from, (uchar*) buff, buff_length, MYF(MY_NABP)) || + mysql_file_write(to, (uchar*) buff, buff_length, param->myf_rw)) goto err; length-= buff_length; } - if (my_read(from,(uchar*) buff,(uint) length,MYF(MY_NABP)) || - my_write(to,(uchar*) buff,(uint) length,param->myf_rw)) + if (mysql_file_read(from, (uchar*) buff, (uint) length, MYF(MY_NABP)) || + mysql_file_write(to, (uchar*) buff, (uint) length, param->myf_rw)) goto err; if (buff != tmp_buff) my_free(buff,MYF(0)); @@ -2275,14 +2280,15 @@ int mi_repair_by_sort(MI_CHECK *param, register MI_INFO *info, if (!rep_quick) { /* Get real path for data file */ - if ((new_file=my_raid_create(fn_format(param->temp_filename, - share->data_file_name, "", - DATA_TMP_EXT, 2+4), - 0,param->tmpfile_createflag, - share->base.raid_type, - share->base.raid_chunks, - share->base.raid_chunksize, - MYF(0))) < 0) + if ((new_file= my_raid_create(mi_key_file_datatmp, + fn_format(param->temp_filename, + share->data_file_name, "", + DATA_TMP_EXT, 2+4), + 0, param->tmpfile_createflag, + share->base.raid_type, + share->base.raid_chunks, + share->base.raid_chunksize, + MYF(0))) < 0) { mi_check_print_error(param,"Can't create new tempfile: '%s'", param->temp_filename); @@ -2320,7 +2326,7 @@ int mi_repair_by_sort(MI_CHECK *param, register MI_INFO *info, sort_info.dupp=0; sort_info.buff=0; param->read_cache.end_of_file=sort_info.filelength= - my_seek(param->read_cache.file,0L,MY_SEEK_END,MYF(0)); + mysql_file_seek(param->read_cache.file, 0L, MY_SEEK_END, MYF(0)); sort_param.wordlist=NULL; init_alloc_root(&sort_param.wordroot, FTPARSER_MEMROOT_ALLOC_SIZE, 0); @@ -2470,7 +2476,7 @@ int mi_repair_by_sort(MI_CHECK *param, register MI_INFO *info, sort_param.filepos; /* Only whole records */ share->state.version=(ulong) time((time_t*) 0); - my_close(info->dfile,MYF(0)); + mysql_file_close(info->dfile, MYF(0)); info->dfile=new_file; share->data_file_type=sort_info.new_data_file_type; share->pack.header_length=(ulong) new_header_length; @@ -2510,7 +2516,7 @@ int mi_repair_by_sort(MI_CHECK *param, register MI_INFO *info, skr=share->base.reloc*share->base.min_pack_length; #endif if (skr != sort_info.filelength && !info->s->base.raid_type) - if (my_chsize(info->dfile,skr,0,MYF(0))) + if (mysql_file_chsize(info->dfile, skr, 0, MYF(0))) mi_check_print_warning(param, "Can't change size of datafile, error: %d", my_errno); @@ -2518,7 +2524,7 @@ int mi_repair_by_sort(MI_CHECK *param, register MI_INFO *info, if (param->testflag & T_CALC_CHECKSUM) info->state->checksum=param->glob_crc; - if (my_chsize(share->kfile,info->state->key_file_length,0,MYF(0))) + if (mysql_file_chsize(share->kfile, info->state->key_file_length, 0, MYF(0))) mi_check_print_warning(param, "Can't change size of indexfile, error: %d", my_errno); @@ -2545,7 +2551,7 @@ err: /* Replace the actual file with the temporary file */ if (new_file >= 0) { - my_close(new_file,MYF(0)); + mysql_file_close(new_file, MYF(0)); info->dfile=new_file= -1; if (change_to_newfile(share->data_file_name,MI_NAME_DEXT, DATA_TMP_EXT, share->base.raid_chunks, @@ -2561,9 +2567,10 @@ err: mi_check_print_error(param,"%d when fixing table",my_errno); if (new_file >= 0) { - (void) my_close(new_file,MYF(0)); - (void) my_raid_delete(param->temp_filename,share->base.raid_chunks, - MYF(MY_WME)); + (void) mysql_file_close(new_file, MYF(0)); + (void) my_raid_delete(mi_key_file_datatmp, + param->temp_filename, share->base.raid_chunks, + MYF(MY_WME)); if (info->dfile == new_file) /* Retry with key cache */ if (unlikely(mi_open_datafile(info, share, name, -1))) param->retry_repair= 0; /* Safety */ @@ -2704,9 +2711,11 @@ int mi_repair_parallel(MI_CHECK *param, register MI_INFO *info, DBUG_PRINT("info", ("is quick repair: %d", rep_quick)); bzero((char*)&sort_info,sizeof(sort_info)); /* Initialize pthread structures before goto err. */ - pthread_mutex_init(&sort_info.mutex, MY_MUTEX_INIT_FAST); - pthread_cond_init(&sort_info.cond, 0); - pthread_mutex_init(¶m->print_msg_mutex, MY_MUTEX_INIT_FAST); + mysql_mutex_init(mi_key_mutex_MI_SORT_INFO_mutex, + &sort_info.mutex, MY_MUTEX_INIT_FAST); + mysql_cond_init(mi_key_cond_MI_SORT_INFO_cond, &sort_info.cond, 0); + mysql_mutex_init(mi_key_mutex_MI_CHECK_print_msg, + ¶m->print_msg_mutex, MY_MUTEX_INIT_FAST); param->need_print_msg_lock= 1; if (!(sort_info.key_block= @@ -2732,15 +2741,16 @@ int mi_repair_parallel(MI_CHECK *param, register MI_INFO *info, if (!rep_quick) { /* Get real path for data file */ - if ((new_file=my_raid_create(fn_format(param->temp_filename, - share->data_file_name, "", - DATA_TMP_EXT, - 2+4), - 0,param->tmpfile_createflag, - share->base.raid_type, - share->base.raid_chunks, - share->base.raid_chunksize, - MYF(0))) < 0) + if ((new_file= my_raid_create(mi_key_file_datatmp, + fn_format(param->temp_filename, + share->data_file_name, "", + DATA_TMP_EXT, + 2+4), + 0, param->tmpfile_createflag, + share->base.raid_type, + share->base.raid_chunks, + share->base.raid_chunksize, + MYF(0))) < 0) { mi_check_print_error(param,"Can't create new tempfile: '%s'", param->temp_filename); @@ -2777,7 +2787,7 @@ int mi_repair_parallel(MI_CHECK *param, register MI_INFO *info, sort_info.dupp=0; sort_info.buff=0; param->read_cache.end_of_file=sort_info.filelength= - my_seek(param->read_cache.file,0L,MY_SEEK_END,MYF(0)); + mysql_file_seek(param->read_cache.file, 0L, MY_SEEK_END, MYF(0)); if (share->data_file_type == DYNAMIC_RECORD) rec_length=max(share->base.min_pack_length+1,share->base.min_block_length); @@ -2903,7 +2913,7 @@ int mi_repair_parallel(MI_CHECK *param, register MI_INFO *info, goto err; sort_info.got_error=0; - pthread_mutex_lock(&sort_info.mutex); + mysql_mutex_lock(&sort_info.mutex); /* Initialize the I/O cache share for use with the read caches and, in @@ -2951,9 +2961,10 @@ int mi_repair_parallel(MI_CHECK *param, register MI_INFO *info, #else param->sort_buffer_length*sort_param[i].key_length/total_key_length; #endif - if (pthread_create(&sort_param[i].thr, &thr_attr, - thr_find_all_keys, - (void *) (sort_param+i))) + if (mysql_thread_create(mi_key_thread_find_all_keys, + &sort_param[i].thr, &thr_attr, + thr_find_all_keys, + (void *) (sort_param+i))) { mi_check_print_error(param,"Cannot start a repair thread"); /* Cleanup: Detach from the share. Avoid others to be blocked. */ @@ -2969,8 +2980,8 @@ int mi_repair_parallel(MI_CHECK *param, register MI_INFO *info, /* waiting for all threads to finish */ while (sort_info.threads_running) - pthread_cond_wait(&sort_info.cond, &sort_info.mutex); - pthread_mutex_unlock(&sort_info.mutex); + mysql_cond_wait(&sort_info.cond, &sort_info.mutex); + mysql_mutex_unlock(&sort_info.mutex); if ((got_error= thr_write_keys(sort_param))) { @@ -3006,7 +3017,7 @@ int mi_repair_parallel(MI_CHECK *param, register MI_INFO *info, Exchange the data file descriptor of the table, so that we use the new file from now on. */ - my_close(info->dfile,MYF(0)); + mysql_file_close(info->dfile, MYF(0)); info->dfile=new_file; share->data_file_type=sort_info.new_data_file_type; @@ -3035,7 +3046,7 @@ int mi_repair_parallel(MI_CHECK *param, register MI_INFO *info, skr=share->base.reloc*share->base.min_pack_length; #endif if (skr != sort_info.filelength && !info->s->base.raid_type) - if (my_chsize(info->dfile,skr,0,MYF(0))) + if (mysql_file_chsize(info->dfile, skr, 0, MYF(0))) mi_check_print_warning(param, "Can't change size of datafile, error: %d", my_errno); @@ -3043,7 +3054,7 @@ int mi_repair_parallel(MI_CHECK *param, register MI_INFO *info, if (param->testflag & T_CALC_CHECKSUM) info->state->checksum=param->glob_crc; - if (my_chsize(share->kfile,info->state->key_file_length,0,MYF(0))) + if (mysql_file_chsize(share->kfile, info->state->key_file_length, 0, MYF(0))) mi_check_print_warning(param, "Can't change size of indexfile, error: %d", my_errno); @@ -3082,7 +3093,7 @@ err: /* Replace the actual file with the temporary file */ if (new_file >= 0) { - my_close(new_file,MYF(0)); + mysql_file_close(new_file, MYF(0)); info->dfile=new_file= -1; if (change_to_newfile(share->data_file_name,MI_NAME_DEXT, DATA_TMP_EXT, share->base.raid_chunks, @@ -3098,9 +3109,10 @@ err: mi_check_print_error(param,"%d when fixing table",my_errno); if (new_file >= 0) { - (void) my_close(new_file,MYF(0)); - (void) my_raid_delete(param->temp_filename,share->base.raid_chunks, - MYF(MY_WME)); + (void) mysql_file_close(new_file, MYF(0)); + (void) my_raid_delete(mi_key_file_datatmp, + param->temp_filename, share->base.raid_chunks, + MYF(MY_WME)); if (info->dfile == new_file) /* Retry with key cache */ if (unlikely(mi_open_datafile(info, share, name, -1))) param->retry_repair= 0; /* Safety */ @@ -3111,9 +3123,9 @@ err: share->state.changed&= ~STATE_NOT_OPTIMIZED_KEYS; share->state.changed|=STATE_NOT_SORTED_PAGES; - pthread_cond_destroy (&sort_info.cond); - pthread_mutex_destroy(&sort_info.mutex); - pthread_mutex_destroy(¶m->print_msg_mutex); + mysql_cond_destroy(&sort_info.cond); + mysql_mutex_destroy(&sort_info.mutex); + mysql_mutex_destroy(¶m->print_msg_mutex); param->need_print_msg_lock= 0; my_free((uchar*) sort_info.ft_buf, MYF(MY_ALLOW_ZERO_PTR)); @@ -4067,8 +4079,9 @@ static int sort_insert_key(MI_SORT_PARAM *sort_param, if (_mi_write_keypage(info, keyinfo, filepos, DFLT_INIT_HITS, anc_buff)) DBUG_RETURN(1); } - else if (my_pwrite(info->s->kfile,(uchar*) anc_buff, - (uint) keyinfo->block_length,filepos, param->myf_rw)) + else if (mysql_file_pwrite(info->s->kfile, (uchar*) anc_buff, + (uint) keyinfo->block_length, filepos, + param->myf_rw)) DBUG_RETURN(1); DBUG_DUMP("buff",(uchar*) anc_buff,mi_getint(anc_buff)); @@ -4172,8 +4185,8 @@ int flush_pending_blocks(MI_SORT_PARAM *sort_param) DFLT_INIT_HITS, key_block->buff)) DBUG_RETURN(1); } - else if (my_pwrite(info->s->kfile,(uchar*) key_block->buff, - (uint) keyinfo->block_length,filepos, myf_rw)) + else if (mysql_file_pwrite(info->s->kfile, (uchar*) key_block->buff, + (uint) keyinfo->block_length, filepos, myf_rw)) DBUG_RETURN(1); DBUG_DUMP("buff",(uchar*) key_block->buff,length); nod_flag=1; @@ -4213,9 +4226,11 @@ int test_if_almost_full(MI_INFO *info) { if (info->s->options & HA_OPTION_COMPRESS_RECORD) return 0; - return my_seek(info->s->kfile, 0L, MY_SEEK_END, MYF(MY_THREADSAFE)) / 10 * 9 > + return mysql_file_seek(info->s->kfile, 0L, MY_SEEK_END, + MYF(MY_THREADSAFE)) / 10 * 9 > (my_off_t) info->s->base.max_key_file_length || - my_seek(info->dfile, 0L, MY_SEEK_END, MYF(0)) / 10 * 9 > + mysql_file_seek(info->dfile, 0L, MY_SEEK_END, + MYF(0)) / 10 * 9 > (my_off_t) info->s->base.max_data_file_length; } @@ -4313,7 +4328,8 @@ int recreate_table(MI_CHECK *param, MI_INFO **org_info, char *filename) if (share.options & HA_OPTION_COMPRESS_RECORD) share.base.records=max_records=info.state->records; else if (share.base.min_pack_length) - max_records=(ha_rows) (my_seek(info.dfile,0L,MY_SEEK_END,MYF(0)) / + max_records=(ha_rows) (mysql_file_seek(info.dfile, 0L, MY_SEEK_END, + MYF(0)) / (ulong) share.base.min_pack_length); else max_records=0; @@ -4321,7 +4337,7 @@ int recreate_table(MI_CHECK *param, MI_INFO **org_info, char *filename) (param->testflag & T_UNPACK); share.options&= ~HA_OPTION_TEMP_COMPRESS_RECORD; - file_length=(ulonglong) my_seek(info.dfile,0L,MY_SEEK_END,MYF(0)); + file_length=(ulonglong) mysql_file_seek(info.dfile, 0L, MY_SEEK_END, MYF(0)); tmp_length= file_length+file_length/10; set_if_bigger(file_length,param->max_data_file_length); set_if_bigger(file_length,tmp_length); diff --git a/storage/myisam/mi_close.c b/storage/myisam/mi_close.c index f94c8f3558d..8ec0bf14e0a 100644 --- a/storage/myisam/mi_close.c +++ b/storage/myisam/mi_close.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2004 MySQL AB +/* Copyright (C) 2000-2004 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -31,7 +31,7 @@ int mi_close(register MI_INFO *info) (long) info, (uint) share->reopen, (uint) share->tot_locks)); - pthread_mutex_lock(&THR_LOCK_myisam); + mysql_mutex_lock(&THR_LOCK_myisam); if (info->lock_type == F_EXTRA_LCK) info->lock_type=F_UNLCK; /* HA_EXTRA_NO_USER_CHANGE */ @@ -40,7 +40,7 @@ int mi_close(register MI_INFO *info) if (mi_lock_database(info,F_UNLCK)) error=my_errno; } - pthread_mutex_lock(&share->intern_lock); + mysql_mutex_lock(&share->intern_lock); if (share->options & HA_OPTION_READ_ONLY_DATA) { @@ -55,7 +55,7 @@ int mi_close(register MI_INFO *info) } flag= !--share->reopen; myisam_open_list=list_delete(myisam_open_list,&info->open_list); - pthread_mutex_unlock(&share->intern_lock); + mysql_mutex_unlock(&share->intern_lock); my_free(mi_get_rec_buff_ptr(info, info->rec_buff), MYF(MY_ALLOW_ZERO_PTR)); if (flag) @@ -79,7 +79,7 @@ int mi_close(register MI_INFO *info) mi_state_info_write(share->kfile, &share->state, 1); /* Decrement open count must be last I/O on this file. */ _mi_decrement_open_count(info); - if (my_close(share->kfile,MYF(0))) + if (mysql_file_close(share->kfile, MYF(0))) error = my_errno; } #ifdef HAVE_MMAP @@ -93,25 +93,25 @@ int mi_close(register MI_INFO *info) } #ifdef THREAD thr_lock_delete(&share->lock); - pthread_mutex_destroy(&share->intern_lock); + mysql_mutex_destroy(&share->intern_lock); { int i,keys; keys = share->state.header.keys; - (void) rwlock_destroy(&share->mmap_lock); + mysql_rwlock_destroy(&share->mmap_lock); for(i=0; i<keys; i++) { - (void) rwlock_destroy(&share->key_root_lock[i]); + mysql_rwlock_destroy(&share->key_root_lock[i]); } } #endif my_free((uchar*) info->s,MYF(0)); } - pthread_mutex_unlock(&THR_LOCK_myisam); + mysql_mutex_unlock(&THR_LOCK_myisam); if (info->ftparser_param) { my_free((uchar*)info->ftparser_param, MYF(0)); info->ftparser_param= 0; } - if (info->dfile >= 0 && my_close(info->dfile,MYF(0))) + if (info->dfile >= 0 && mysql_file_close(info->dfile, MYF(0))) error = my_errno; myisam_log_command(MI_LOG_CLOSE,info,NULL,0,error); diff --git a/storage/myisam/mi_create.c b/storage/myisam/mi_create.c index 7733fd5db17..66d5d4fa3cd 100644 --- a/storage/myisam/mi_create.c +++ b/storage/myisam/mi_create.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2006 MySQL AB +/* Copyright (C) 2000-2006 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -572,7 +572,7 @@ int mi_create(const char *name,uint keys,MI_KEYDEF *keydefs, if (! (flags & HA_DONT_TOUCH_DATA)) share.state.create_time= (long) time((time_t*) 0); - pthread_mutex_lock(&THR_LOCK_myisam); + mysql_mutex_lock(&THR_LOCK_myisam); /* NOTE: For test_if_reopen() we need a real path name. Hence we need @@ -638,8 +638,10 @@ int mi_create(const char *name,uint keys,MI_KEYDEF *keydefs, goto err; } - if ((file= my_create_with_symlink(linkname_ptr, filename, 0, create_mode, - MYF(MY_WME | create_flag))) < 0) + if ((file= mysql_file_create_with_symlink(mi_key_file_kfile, + linkname_ptr, filename, 0, + create_mode, + MYF(MY_WME | create_flag))) < 0) goto err; errpos=1; @@ -694,8 +696,10 @@ int mi_create(const char *name,uint keys,MI_KEYDEF *keydefs, create_flag=(flags & HA_CREATE_KEEP_FILES) ? 0 : MY_DELETE_OLD; } if ((dfile= - my_create_with_symlink(linkname_ptr, filename, 0, create_mode, - MYF(MY_WME | create_flag))) < 0) + mysql_file_create_with_symlink(mi_key_file_dfile, + linkname_ptr, filename, 0, + create_mode, + MYF(MY_WME | create_flag))) < 0) goto err; } errpos=3; @@ -706,9 +710,9 @@ int mi_create(const char *name,uint keys,MI_KEYDEF *keydefs, mi_base_info_write(file, &share.base)) goto err; #ifndef DBUG_OFF - if ((uint) my_tell(file,MYF(0)) != base_pos+ MI_BASE_INFO_SIZE) + if ((uint) mysql_file_tell(file, MYF(0)) != base_pos + MI_BASE_INFO_SIZE) { - uint pos=(uint) my_tell(file,MYF(0)); + uint pos=(uint) mysql_file_tell(file, MYF(0)); DBUG_PRINT("warning",("base_length: %d != used_length: %d", base_pos+ MI_BASE_INFO_SIZE, pos)); } @@ -803,9 +807,9 @@ int mi_create(const char *name,uint keys,MI_KEYDEF *keydefs, goto err; #ifndef DBUG_OFF - if ((uint) my_tell(file,MYF(0)) != info_length) + if ((uint) mysql_file_tell(file, MYF(0)) != info_length) { - uint pos= (uint) my_tell(file,MYF(0)); + uint pos= (uint) mysql_file_tell(file, MYF(0)); DBUG_PRINT("warning",("info_length: %d != used_length: %d", info_length, pos)); } @@ -813,46 +817,49 @@ int mi_create(const char *name,uint keys,MI_KEYDEF *keydefs, /* Enlarge files */ DBUG_PRINT("info", ("enlarge to keystart: %lu", (ulong) share.base.keystart)); - if (my_chsize(file,(ulong) share.base.keystart,0,MYF(0))) + if (mysql_file_chsize(file, (ulong) share.base.keystart, 0, MYF(0))) goto err; if (! (flags & HA_DONT_TOUCH_DATA)) { #ifdef USE_RELOC - if (my_chsize(dfile,share.base.min_pack_length*ci->reloc_rows,0,MYF(0))) + if (mysql_file_chsize(dfile, share.base.min_pack_length*ci->reloc_rows, + 0, MYF(0))) goto err; #endif errpos=2; - if (my_close(dfile,MYF(0))) + if (mysql_file_close(dfile, MYF(0))) goto err; } errpos=0; - pthread_mutex_unlock(&THR_LOCK_myisam); - if (my_close(file,MYF(0))) + mysql_mutex_unlock(&THR_LOCK_myisam); + if (mysql_file_close(file, MYF(0))) goto err; my_free((char*) rec_per_key_part,MYF(0)); DBUG_RETURN(0); err: - pthread_mutex_unlock(&THR_LOCK_myisam); + mysql_mutex_unlock(&THR_LOCK_myisam); save_errno=my_errno; switch (errpos) { case 3: - (void) my_close(dfile,MYF(0)); + (void) mysql_file_close(dfile, MYF(0)); /* fall through */ case 2: /* QQ: Tõnu should add a call to my_raid_delete() here */ if (! (flags & HA_DONT_TOUCH_DATA)) - my_delete_with_symlink(fn_format(filename,name,"",MI_NAME_DEXT, - MY_UNPACK_FILENAME | MY_APPEND_EXT), - MYF(0)); + mysql_file_delete_with_symlink(mi_key_file_dfile, + fn_format(filename, name, "", MI_NAME_DEXT, + MY_UNPACK_FILENAME | MY_APPEND_EXT), + MYF(0)); /* fall through */ case 1: - (void) my_close(file,MYF(0)); + (void) mysql_file_close(file, MYF(0)); if (! (flags & HA_DONT_TOUCH_DATA)) - my_delete_with_symlink(fn_format(filename,name,"",MI_NAME_IEXT, - MY_UNPACK_FILENAME | MY_APPEND_EXT), - MYF(0)); + mysql_file_delete_with_symlink(mi_key_file_kfile, + fn_format(filename, name, "", MI_NAME_IEXT, + MY_UNPACK_FILENAME | MY_APPEND_EXT), + MYF(0)); } my_free((char*) rec_per_key_part, MYF(0)); DBUG_RETURN(my_errno=save_errno); /* return the fatal errno */ diff --git a/storage/myisam/mi_delete_all.c b/storage/myisam/mi_delete_all.c index cbf5abf7ef5..b8706069ced 100644 --- a/storage/myisam/mi_delete_all.c +++ b/storage/myisam/mi_delete_all.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2003, 2005 MySQL AB +/* Copyright (C) 2000-2003, 2005 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -57,8 +57,8 @@ int mi_delete_all_rows(MI_INFO *info) if (share->file_map) _mi_unmap_file(info); #endif - if (my_chsize(info->dfile, 0, 0, MYF(MY_WME)) || - my_chsize(share->kfile, share->base.keystart, 0, MYF(MY_WME)) ) + if (mysql_file_chsize(info->dfile, 0, 0, MYF(MY_WME)) || + mysql_file_chsize(share->kfile, share->base.keystart, 0, MYF(MY_WME))) goto err; (void) _mi_writeinfo(info,WRITEINFO_UPDATE_KEYFILE); #ifdef HAVE_MMAP diff --git a/storage/myisam/mi_delete_table.c b/storage/myisam/mi_delete_table.c index a3c0dede581..28aee848665 100644 --- a/storage/myisam/mi_delete_table.c +++ b/storage/myisam/mi_delete_table.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2001, 2004, 2006 MySQL AB +/* Copyright (C) 2000-2001, 2004, 2006 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -58,12 +58,13 @@ int mi_delete_table(const char *name) #endif /* USE_RAID */ fn_format(from,name,"",MI_NAME_IEXT,MY_UNPACK_FILENAME|MY_APPEND_EXT); - if (my_delete_with_symlink(from, MYF(MY_WME))) + if (mysql_file_delete_with_symlink(mi_key_file_kfile, from, MYF(MY_WME))) DBUG_RETURN(my_errno); fn_format(from,name,"",MI_NAME_DEXT,MY_UNPACK_FILENAME|MY_APPEND_EXT); #ifdef USE_RAID if (raid_type) DBUG_RETURN(my_raid_delete(from, raid_chunks, MYF(MY_WME)) ? my_errno : 0); #endif - DBUG_RETURN(my_delete_with_symlink(from, MYF(MY_WME)) ? my_errno : 0); + DBUG_RETURN(mysql_file_delete_with_symlink(mi_key_file_dfile, + from, MYF(MY_WME)) ? my_errno : 0); } diff --git a/storage/myisam/mi_dynrec.c b/storage/myisam/mi_dynrec.c index 1de0fef876d..4c681eeff5f 100644 --- a/storage/myisam/mi_dynrec.c +++ b/storage/myisam/mi_dynrec.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2006 MySQL AB +/* Copyright (C) 2000-2006 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -143,7 +143,7 @@ size_t mi_mmap_pread(MI_INFO *info, uchar *Buffer, { DBUG_PRINT("info", ("mi_read with mmap %d\n", info->dfile)); if (info->s->concurrent_insert) - rw_rdlock(&info->s->mmap_lock); + mysql_rwlock_rdlock(&info->s->mmap_lock); /* The following test may fail in the following cases: @@ -156,24 +156,24 @@ size_t mi_mmap_pread(MI_INFO *info, uchar *Buffer, { memcpy(Buffer, info->s->file_map + offset, Count); if (info->s->concurrent_insert) - rw_unlock(&info->s->mmap_lock); + mysql_rwlock_unlock(&info->s->mmap_lock); return 0; } else { if (info->s->concurrent_insert) - rw_unlock(&info->s->mmap_lock); - return my_pread(info->dfile, Buffer, Count, offset, MyFlags); + mysql_rwlock_unlock(&info->s->mmap_lock); + return mysql_file_pread(info->dfile, Buffer, Count, offset, MyFlags); } } - /* wrapper for my_pread in case if mmap isn't used */ + /* wrapper for mysql_file_pread in case if mmap isn't used */ size_t mi_nommap_pread(MI_INFO *info, uchar *Buffer, size_t Count, my_off_t offset, myf MyFlags) { - return my_pread(info->dfile, Buffer, Count, offset, MyFlags); + return mysql_file_pread(info->dfile, Buffer, Count, offset, MyFlags); } @@ -198,7 +198,7 @@ size_t mi_mmap_pwrite(MI_INFO *info, const uchar *Buffer, { DBUG_PRINT("info", ("mi_write with mmap %d\n", info->dfile)); if (info->s->concurrent_insert) - rw_rdlock(&info->s->mmap_lock); + mysql_rwlock_rdlock(&info->s->mmap_lock); /* The following test may fail in the following cases: @@ -211,26 +211,26 @@ size_t mi_mmap_pwrite(MI_INFO *info, const uchar *Buffer, { memcpy(info->s->file_map + offset, Buffer, Count); if (info->s->concurrent_insert) - rw_unlock(&info->s->mmap_lock); + mysql_rwlock_unlock(&info->s->mmap_lock); return 0; } else { info->s->nonmmaped_inserts++; if (info->s->concurrent_insert) - rw_unlock(&info->s->mmap_lock); - return my_pwrite(info->dfile, Buffer, Count, offset, MyFlags); + mysql_rwlock_unlock(&info->s->mmap_lock); + return mysql_file_pwrite(info->dfile, Buffer, Count, offset, MyFlags); } } - /* wrapper for my_pwrite in case if mmap isn't used */ + /* wrapper for mysql_file_pwrite in case if mmap isn't used */ size_t mi_nommap_pwrite(MI_INFO *info, const uchar *Buffer, size_t Count, my_off_t offset, myf MyFlags) { - return my_pwrite(info->dfile, Buffer, Count, offset, MyFlags); + return mysql_file_pwrite(info->dfile, Buffer, Count, offset, MyFlags); } @@ -1642,7 +1642,7 @@ static int _mi_cmp_buffer(File file, const uchar *buff, my_off_t filepos, while (length > IO_SIZE*2) { - if (my_pread(file,temp_buff,next_length,filepos, MYF(MY_NABP)) || + if (mysql_file_pread(file, temp_buff, next_length, filepos, MYF(MY_NABP)) || memcmp(buff, temp_buff, next_length)) goto err; filepos+=next_length; @@ -1650,7 +1650,7 @@ static int _mi_cmp_buffer(File file, const uchar *buff, my_off_t filepos, length-= next_length; next_length=IO_SIZE*2; } - if (my_pread(file,temp_buff,length,filepos,MYF(MY_NABP))) + if (mysql_file_pread(file, temp_buff, length, filepos, MYF(MY_NABP))) goto err; DBUG_RETURN(memcmp(buff,temp_buff,length)); err: @@ -1831,8 +1831,9 @@ int _mi_read_rnd_dynamic_record(MI_INFO *info, uchar *buf, block_info.filepos + block_info.data_len && flush_io_cache(&info->rec_cache)) goto err; - /* my_seek(info->dfile,filepos,MY_SEEK_SET,MYF(0)); */ - if (my_read(info->dfile,(uchar*) to,block_info.data_len,MYF(MY_NABP))) + /* mysql_file_seek(info->dfile, filepos, MY_SEEK_SET, MYF(0)); */ + if (mysql_file_read(info->dfile, (uchar*) to, block_info.data_len, + MYF(MY_NABP))) { if (my_errno == -1) my_errno= HA_ERR_WRONG_IN_RECORD; /* Unexpected end of file */ @@ -1880,12 +1881,12 @@ uint _mi_get_block_info(MI_BLOCK_INFO *info, File file, my_off_t filepos) if (file >= 0) { /* - We do not use my_pread() here because we want to have the file + We do not use mysql_file_pread() here because we want to have the file pointer set to the end of the header after this function. - my_pread() may leave the file pointer untouched. + mysql_file_pread() may leave the file pointer untouched. */ - my_seek(file,filepos,MY_SEEK_SET,MYF(0)); - if (my_read(file, header, sizeof(info->header),MYF(0)) != + mysql_file_seek(file, filepos, MY_SEEK_SET, MYF(0)); + if (mysql_file_read(file, header, sizeof(info->header), MYF(0)) != sizeof(info->header)) goto err; } diff --git a/storage/myisam/mi_extra.c b/storage/myisam/mi_extra.c index f0ddc15b325..d8f4fc99c8e 100644 --- a/storage/myisam/mi_extra.c +++ b/storage/myisam/mi_extra.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2005 MySQL AB +/* Copyright (C) 2000-2005 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -74,17 +74,17 @@ int mi_extra(MI_INFO *info, enum ha_extra_function function, void *extra_arg) #if defined(HAVE_MMAP) && defined(HAVE_MADVISE) if ((share->options & HA_OPTION_COMPRESS_RECORD)) { - pthread_mutex_lock(&share->intern_lock); + mysql_mutex_lock(&share->intern_lock); if (_mi_memmap_file(info)) { /* We don't nead MADV_SEQUENTIAL if small file */ madvise((char*) share->file_map, share->state.state.data_file_length, share->state.state.data_file_length <= RECORD_CACHE_SIZE*16 ? MADV_RANDOM : MADV_SEQUENTIAL); - pthread_mutex_unlock(&share->intern_lock); + mysql_mutex_unlock(&share->intern_lock); break; } - pthread_mutex_unlock(&share->intern_lock); + mysql_mutex_unlock(&share->intern_lock); } #endif if (info->opt_flag & WRITE_CACHE_USED) @@ -252,16 +252,16 @@ int mi_extra(MI_INFO *info, enum ha_extra_function function, void *extra_arg) } break; case HA_EXTRA_FORCE_REOPEN: - pthread_mutex_lock(&THR_LOCK_myisam); + mysql_mutex_lock(&THR_LOCK_myisam); share->last_version= 0L; /* Impossible version */ - pthread_mutex_unlock(&THR_LOCK_myisam); + mysql_mutex_unlock(&THR_LOCK_myisam); break; case HA_EXTRA_PREPARE_FOR_DROP: - pthread_mutex_lock(&THR_LOCK_myisam); + mysql_mutex_lock(&THR_LOCK_myisam); share->last_version= 0L; /* Impossible version */ #ifdef __WIN__REMOVE_OBSOLETE_WORKAROUND /* Close the isam and data files as Win32 can't drop an open table */ - pthread_mutex_lock(&share->intern_lock); + mysql_mutex_lock(&share->intern_lock); if (flush_key_blocks(share->key_cache, share->kfile, (function == HA_EXTRA_FORCE_REOPEN ? FLUSH_RELEASE : FLUSH_IGNORE_CHANGED))) @@ -285,7 +285,7 @@ int mi_extra(MI_INFO *info, enum ha_extra_function function, void *extra_arg) } if (share->kfile >= 0) _mi_decrement_open_count(info); - if (share->kfile >= 0 && my_close(share->kfile,MYF(0))) + if (share->kfile >= 0 && mysql_file_close(share->kfile, MYF(0))) error=my_errno; { LIST *list_element ; @@ -296,16 +296,16 @@ int mi_extra(MI_INFO *info, enum ha_extra_function function, void *extra_arg) MI_INFO *tmpinfo=(MI_INFO*) list_element->data; if (tmpinfo->s == info->s) { - if (tmpinfo->dfile >= 0 && my_close(tmpinfo->dfile,MYF(0))) + if (tmpinfo->dfile >= 0 && mysql_file_close(tmpinfo->dfile, MYF(0))) error = my_errno; tmpinfo->dfile= -1; } } } share->kfile= -1; /* Files aren't open anymore */ - pthread_mutex_unlock(&share->intern_lock); + mysql_mutex_unlock(&share->intern_lock); #endif - pthread_mutex_unlock(&THR_LOCK_myisam); + mysql_mutex_unlock(&THR_LOCK_myisam); break; case HA_EXTRA_FLUSH: if (!share->temporary) @@ -316,9 +316,9 @@ int mi_extra(MI_INFO *info, enum ha_extra_function function, void *extra_arg) if (share->not_flushed) { share->not_flushed=0; - if (my_sync(share->kfile, MYF(0))) + if (mysql_file_sync(share->kfile, MYF(0))) error= my_errno; - if (my_sync(info->dfile, MYF(0))) + if (mysql_file_sync(info->dfile, MYF(0))) error= my_errno; if (error) { @@ -349,7 +349,7 @@ int mi_extra(MI_INFO *info, enum ha_extra_function function, void *extra_arg) break; case HA_EXTRA_MMAP: #ifdef HAVE_MMAP - pthread_mutex_lock(&share->intern_lock); + mysql_mutex_lock(&share->intern_lock); /* Memory map the data file if it is not already mapped. It is safe to memory map a file while other threads are using file I/O on it. @@ -370,13 +370,13 @@ int mi_extra(MI_INFO *info, enum ha_extra_function function, void *extra_arg) share->file_write= mi_mmap_pwrite; } } - pthread_mutex_unlock(&share->intern_lock); + mysql_mutex_unlock(&share->intern_lock); #endif break; case HA_EXTRA_MARK_AS_LOG_TABLE: - pthread_mutex_lock(&share->intern_lock); + mysql_mutex_lock(&share->intern_lock); share->is_log_table= TRUE; - pthread_mutex_unlock(&share->intern_lock); + mysql_mutex_unlock(&share->intern_lock); break; case HA_EXTRA_KEY_CACHE: case HA_EXTRA_NO_KEY_CACHE: diff --git a/storage/myisam/mi_info.c b/storage/myisam/mi_info.c index a454a4ade9b..36d7073a4dc 100644 --- a/storage/myisam/mi_info.c +++ b/storage/myisam/mi_info.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2001, 2003-2004 MySQL AB +/* Copyright (C) 2000-2001, 2003-2004 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -42,10 +42,10 @@ int mi_status(MI_INFO *info, register MI_ISAMINFO *x, uint flag) DBUG_RETURN(0); /* Compatible with ISAM */ if (!(flag & HA_STATUS_NO_LOCK)) { - pthread_mutex_lock(&share->intern_lock); + mysql_mutex_lock(&share->intern_lock); (void) _mi_readinfo(info,F_RDLCK,0); fast_mi_writeinfo(info); - pthread_mutex_unlock(&share->intern_lock); + mysql_mutex_unlock(&share->intern_lock); } if (flag & HA_STATUS_VARIABLE) { @@ -85,7 +85,7 @@ int mi_status(MI_INFO *info, register MI_ISAMINFO *x, uint flag) x->data_file_name = share->data_file_name; x->index_file_name = share->index_file_name; } - if ((flag & HA_STATUS_TIME) && !my_fstat(info->dfile,&state,MYF(0))) + if ((flag & HA_STATUS_TIME) && !mysql_file_fstat(info->dfile, &state, MYF(0))) x->update_time=state.st_mtime; else x->update_time=0; diff --git a/storage/myisam/mi_keycache.c b/storage/myisam/mi_keycache.c index 5cf3fede1ae..cbd9c7d76ab 100644 --- a/storage/myisam/mi_keycache.c +++ b/storage/myisam/mi_keycache.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2003 MySQL AB +/* Copyright (C) 2003 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -96,7 +96,7 @@ int mi_assign_to_key_cache(MI_INFO *info, ensure that setting the key cache and changing the multi_key_cache is done atomicly */ - pthread_mutex_lock(&share->intern_lock); + mysql_mutex_lock(&share->intern_lock); /* Tell all threads to use the new key cache This should be seen at the lastes for the next call to an myisam function. @@ -108,7 +108,7 @@ int mi_assign_to_key_cache(MI_INFO *info, share->unique_name_length, share->key_cache)) error= my_errno; - pthread_mutex_unlock(&share->intern_lock); + mysql_mutex_unlock(&share->intern_lock); DBUG_RETURN(error); } @@ -143,7 +143,7 @@ void mi_change_key_cache(KEY_CACHE *old_key_cache, /* Lock list to ensure that no one can close the table while we manipulate it */ - pthread_mutex_lock(&THR_LOCK_myisam); + mysql_mutex_lock(&THR_LOCK_myisam); for (pos=myisam_open_list ; pos ; pos=pos->next) { MI_INFO *info= (MI_INFO*) pos->data; @@ -158,6 +158,6 @@ void mi_change_key_cache(KEY_CACHE *old_key_cache, open a new table that will be associted with the old key cache */ multi_key_cache_change(old_key_cache, new_key_cache); - pthread_mutex_unlock(&THR_LOCK_myisam); + mysql_mutex_unlock(&THR_LOCK_myisam); DBUG_VOID_RETURN; } diff --git a/storage/myisam/mi_locking.c b/storage/myisam/mi_locking.c index 687962af42a..dd33fb71910 100644 --- a/storage/myisam/mi_locking.c +++ b/storage/myisam/mi_locking.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2006 MySQL AB +/* Copyright (C) 2000-2006 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -49,7 +49,7 @@ int mi_lock_database(MI_INFO *info, int lock_type) } flag=error=0; - pthread_mutex_lock(&share->intern_lock); + mysql_mutex_lock(&share->intern_lock); if (share->kfile >= 0) /* May only be false on windows */ { switch (lock_type) { @@ -88,11 +88,11 @@ int mi_lock_database(MI_INFO *info, int lock_type) (info->s->nonmmaped_inserts > MAX_NONMAPPED_INSERTS)) { if (info->s->concurrent_insert) - rw_wrlock(&info->s->mmap_lock); + mysql_rwlock_wrlock(&info->s->mmap_lock); mi_remap_file(info, info->s->state.state.data_file_length); info->s->nonmmaped_inserts= 0; if (info->s->concurrent_insert) - rw_unlock(&info->s->mmap_lock); + mysql_rwlock_unlock(&info->s->mmap_lock); } #endif share->state.process= share->last_process=share->this_process; @@ -103,9 +103,9 @@ int mi_lock_database(MI_INFO *info, int lock_type) share->changed=0; if (myisam_flush) { - if (my_sync(share->kfile, MYF(0))) + if (mysql_file_sync(share->kfile, MYF(0))) error= my_errno; - if (my_sync(info->dfile, MYF(0))) + if (mysql_file_sync(info->dfile, MYF(0))) error= my_errno; } else @@ -251,7 +251,7 @@ int mi_lock_database(MI_INFO *info, int lock_type) } } #endif - pthread_mutex_unlock(&share->intern_lock); + mysql_mutex_unlock(&share->intern_lock); #if defined(FULL_LOG) || defined(_lint) lock_type|=(int) (flag << 8); /* Set bit to set if real lock */ myisam_log_command(MI_LOG_LOCK,info,(uchar*) &lock_type,sizeof(lock_type), @@ -458,8 +458,8 @@ int _mi_writeinfo(register MI_INFO *info, uint operation) #ifdef _WIN32 if (myisam_flush) { - my_sync(share->kfile,0); - my_sync(info->dfile,0); + mysql_file_sync(share->kfile, 0); + mysql_file_sync(info->dfile, 0); } #endif } @@ -539,9 +539,9 @@ int _mi_mark_file_changed(MI_INFO *info) { mi_int2store(buff,share->state.open_count); buff[2]=1; /* Mark that it's changed */ - DBUG_RETURN(my_pwrite(share->kfile,buff,sizeof(buff), - sizeof(share->state.header), - MYF(MY_NABP))); + DBUG_RETURN(mysql_file_pwrite(share->kfile, buff, sizeof(buff), + sizeof(share->state.header), + MYF(MY_NABP))); } } DBUG_RETURN(0); @@ -568,9 +568,9 @@ int _mi_decrement_open_count(MI_INFO *info) { share->state.open_count--; mi_int2store(buff,share->state.open_count); - write_error=my_pwrite(share->kfile,buff,sizeof(buff), - sizeof(share->state.header), - MYF(MY_NABP)); + write_error= mysql_file_pwrite(share->kfile, buff, sizeof(buff), + sizeof(share->state.header), + MYF(MY_NABP)); } if (!lock_error) lock_error=mi_lock_database(info,old_lock); diff --git a/storage/myisam/mi_log.c b/storage/myisam/mi_log.c index 14e496e79b7..54498393f15 100644 --- a/storage/myisam/mi_log.c +++ b/storage/myisam/mi_log.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2001, 2004 MySQL AB +/* Copyright (C) 2000-2001, 2004 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -54,16 +54,19 @@ int mi_log(int activate_log) myisam_pid=(ulong) getpid(); if (myisam_log_file < 0) { - if ((myisam_log_file = my_create(fn_format(buff,myisam_log_filename, - "",".log",4), - 0,(O_RDWR | O_BINARY | O_APPEND),MYF(0))) - < 0) + if ((myisam_log_file= mysql_file_create(mi_key_file_log, + fn_format(buff, + myisam_log_filename, + "", ".log", 4), + 0, + (O_RDWR | O_BINARY | O_APPEND), + MYF(0))) < 0) DBUG_RETURN(my_errno); } } else if (myisam_log_file >= 0) { - error=my_close(myisam_log_file,MYF(0)) ? my_errno : 0 ; + error= mysql_file_close(myisam_log_file, MYF(0)) ? my_errno : 0 ; myisam_log_file= -1; } DBUG_RETURN(error); @@ -86,13 +89,13 @@ void _myisam_log(enum myisam_log_commands command, MI_INFO *info, mi_int4store(buff+3,pid); mi_int2store(buff+9,length); - pthread_mutex_lock(&THR_LOCK_myisam); + mysql_mutex_lock(&THR_LOCK_myisam); error=my_lock(myisam_log_file,F_WRLCK,0L,F_TO_EOF,MYF(MY_SEEK_NOT_DONE)); - (void) my_write(myisam_log_file,buff,sizeof(buff),MYF(0)); - (void) my_write(myisam_log_file,buffert,length,MYF(0)); + (void) mysql_file_write(myisam_log_file, buff, sizeof(buff), MYF(0)); + (void) mysql_file_write(myisam_log_file, buffert, length, MYF(0)); if (!error) error=my_lock(myisam_log_file,F_UNLCK,0L,F_TO_EOF,MYF(MY_SEEK_NOT_DONE)); - pthread_mutex_unlock(&THR_LOCK_myisam); + mysql_mutex_unlock(&THR_LOCK_myisam); my_errno=old_errno; } @@ -109,14 +112,14 @@ void _myisam_log_command(enum myisam_log_commands command, MI_INFO *info, mi_int2store(buff+1,info->dfile); mi_int4store(buff+3,pid); mi_int2store(buff+7,result); - pthread_mutex_lock(&THR_LOCK_myisam); + mysql_mutex_lock(&THR_LOCK_myisam); error=my_lock(myisam_log_file,F_WRLCK,0L,F_TO_EOF,MYF(MY_SEEK_NOT_DONE)); - (void) my_write(myisam_log_file,buff,sizeof(buff),MYF(0)); + (void) mysql_file_write(myisam_log_file, buff, sizeof(buff), MYF(0)); if (buffert) - (void) my_write(myisam_log_file,buffert,length,MYF(0)); + (void) mysql_file_write(myisam_log_file, buffert, length, MYF(0)); if (!error) error=my_lock(myisam_log_file,F_UNLCK,0L,F_TO_EOF,MYF(MY_SEEK_NOT_DONE)); - pthread_mutex_unlock(&THR_LOCK_myisam); + mysql_mutex_unlock(&THR_LOCK_myisam); my_errno=old_errno; } @@ -140,10 +143,10 @@ void _myisam_log_record(enum myisam_log_commands command, MI_INFO *info, mi_int2store(buff+7,result); mi_sizestore(buff+9,filepos); mi_int4store(buff+17,length); - pthread_mutex_lock(&THR_LOCK_myisam); + mysql_mutex_lock(&THR_LOCK_myisam); error=my_lock(myisam_log_file,F_WRLCK,0L,F_TO_EOF,MYF(MY_SEEK_NOT_DONE)); - (void) my_write(myisam_log_file, buff,sizeof(buff),MYF(0)); - (void) my_write(myisam_log_file, record,info->s->base.reclength,MYF(0)); + (void) mysql_file_write(myisam_log_file, buff, sizeof(buff), MYF(0)); + (void) mysql_file_write(myisam_log_file, record, info->s->base.reclength, MYF(0)); if (info->s->base.blobs) { MI_BLOB *blob,*end; @@ -154,11 +157,11 @@ void _myisam_log_record(enum myisam_log_commands command, MI_INFO *info, { memcpy_fixed((uchar*) &pos, record+blob->offset+blob->pack_length, sizeof(char*)); - (void) my_write(myisam_log_file,pos,blob->length,MYF(0)); + (void) mysql_file_write(myisam_log_file, pos, blob->length, MYF(0)); } } if (!error) error=my_lock(myisam_log_file,F_UNLCK,0L,F_TO_EOF,MYF(MY_SEEK_NOT_DONE)); - pthread_mutex_unlock(&THR_LOCK_myisam); + mysql_mutex_unlock(&THR_LOCK_myisam); my_errno=old_errno; } diff --git a/storage/myisam/mi_open.c b/storage/myisam/mi_open.c index b97470c0aa6..f7137ac554d 100644 --- a/storage/myisam/mi_open.c +++ b/storage/myisam/mi_open.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2006 MySQL AB +/* Copyright (C) 2000-2006 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -103,7 +103,7 @@ MI_INFO *mi_open(const char *name, int mode, uint open_flags) DBUG_RETURN (NULL); } - pthread_mutex_lock(&THR_LOCK_myisam); + mysql_mutex_lock(&THR_LOCK_myisam); if (!(old_info=test_if_reopen(name_buff))) { share= &share_buff; @@ -120,17 +120,21 @@ MI_INFO *mi_open(const char *name, int mode, uint open_flags) my_errno= HA_ERR_CRASHED; goto err; }); - if ((kfile=my_open(name_buff,(open_mode=O_RDWR) | O_SHARE,MYF(0))) < 0) + if ((kfile= mysql_file_open(mi_key_file_kfile, + name_buff, + (open_mode= O_RDWR) | O_SHARE, MYF(0))) < 0) { if ((errno != EROFS && errno != EACCES) || mode != O_RDONLY || - (kfile=my_open(name_buff,(open_mode=O_RDONLY) | O_SHARE,MYF(0))) < 0) + (kfile= mysql_file_open(mi_key_file_kfile, + name_buff, + (open_mode= O_RDONLY) | O_SHARE, MYF(0))) < 0) goto err; } share->mode=open_mode; errpos=1; - if (my_read(kfile, share->state.header.file_version, head_length, - MYF(MY_NABP))) + if (mysql_file_read(kfile, share->state.header.file_version, head_length, + MYF(MY_NABP))) { my_errno= HA_ERR_NOT_A_TABLE; goto err; @@ -181,7 +185,7 @@ MI_INFO *mi_open(const char *name, int mode, uint open_flags) end_pos=disk_cache+info_length; errpos=2; - my_seek(kfile,0L,MY_SEEK_SET,MYF(0)); + mysql_file_seek(kfile, 0L, MY_SEEK_SET, MYF(0)); if (!(open_flags & HA_OPEN_TMP_TABLE)) { if ((lock_error=my_lock(kfile,F_RDLCK,0L,F_TO_EOF, @@ -191,7 +195,7 @@ MI_INFO *mi_open(const char *name, int mode, uint open_flags) goto err; } errpos=3; - if (my_read(kfile,disk_cache,info_length,MYF(MY_NABP))) + if (mysql_file_read(kfile, disk_cache, info_length, MYF(MY_NABP))) { my_errno=HA_ERR_CRASHED; goto err; @@ -309,9 +313,9 @@ MI_INFO *mi_open(const char *name, int mode, uint open_flags) &share->state.key_del, (share->state.header.max_block_size_index*sizeof(my_off_t)), #ifdef THREAD - &share->key_root_lock,sizeof(rw_lock_t)*keys, + &share->key_root_lock, sizeof(mysql_rwlock_t)*keys, #endif - &share->mmap_lock,sizeof(rw_lock_t), + &share->mmap_lock, sizeof(mysql_rwlock_t), NullS)) goto err; errpos=4; @@ -522,10 +526,12 @@ MI_INFO *mi_open(const char *name, int mode, uint open_flags) share->is_log_table= FALSE; #ifdef THREAD thr_lock_init(&share->lock); - pthread_mutex_init(&share->intern_lock,MY_MUTEX_INIT_FAST); + mysql_mutex_init(mi_key_mutex_MYISAM_SHARE_intern_lock, + &share->intern_lock, MY_MUTEX_INIT_FAST); for (i=0; i<keys; i++) - (void) my_rwlock_init(&share->key_root_lock[i], NULL); - (void) my_rwlock_init(&share->mmap_lock, NULL); + mysql_rwlock_init(mi_key_rwlock_MYISAM_SHARE_key_root_lock, + &share->key_root_lock[i]); + mysql_rwlock_init(mi_key_rwlock_MYISAM_SHARE_mmap_lock, &share->mmap_lock); if (!thr_lock_inited) { /* Probably a single threaded program; Don't use concurrent inserts */ @@ -611,7 +617,7 @@ MI_INFO *mi_open(const char *name, int mode, uint open_flags) info.ft1_to_ft2=0; info.errkey= -1; info.page_changed=1; - pthread_mutex_lock(&share->intern_lock); + mysql_mutex_lock(&share->intern_lock); info.read_record=share->read_record; share->reopen++; share->write_flag=MYF(MY_NABP | MY_WAIT_IF_FULL); @@ -635,7 +641,7 @@ MI_INFO *mi_open(const char *name, int mode, uint open_flags) myisam_delay_key_write) share->delay_key_write=1; info.state= &share->state.state; /* Change global values by default */ - pthread_mutex_unlock(&share->intern_lock); + mysql_mutex_unlock(&share->intern_lock); /* Allocate buffer for one record */ @@ -651,7 +657,7 @@ MI_INFO *mi_open(const char *name, int mode, uint open_flags) m_info->open_list.data=(void*) m_info; myisam_open_list=list_add(myisam_open_list,&m_info->open_list); - pthread_mutex_unlock(&THR_LOCK_myisam); + mysql_mutex_unlock(&THR_LOCK_myisam); if (myisam_log_file >= 0) { intern_filename(name_buff,share->index_file_name); @@ -670,7 +676,7 @@ err: my_free((uchar*) m_info,MYF(0)); /* fall through */ case 5: - (void) my_close(info.dfile,MYF(0)); + (void) mysql_file_close(info.dfile, MYF(0)); if (old_info) break; /* Don't remove open table */ /* fall through */ @@ -685,13 +691,13 @@ err: my_afree(disk_cache); /* fall through */ case 1: - (void) my_close(kfile,MYF(0)); + (void) mysql_file_close(kfile, MYF(0)); /* fall through */ case 0: default: break; } - pthread_mutex_unlock(&THR_LOCK_myisam); + mysql_mutex_unlock(&THR_LOCK_myisam); my_errno=save_errno; DBUG_RETURN (NULL); } /* mi_open */ @@ -924,10 +930,10 @@ uint mi_state_info_write(File file, MI_STATE_INFO *state, uint pWrite) } if (pWrite & 1) - DBUG_RETURN(my_pwrite(file, buff, (size_t) (ptr-buff), 0L, - MYF(MY_NABP | MY_THREADSAFE)) != 0); - DBUG_RETURN(my_write(file, buff, (size_t) (ptr-buff), - MYF(MY_NABP)) != 0); + DBUG_RETURN(mysql_file_pwrite(file, buff, (size_t) (ptr-buff), 0L, + MYF(MY_NABP | MY_THREADSAFE)) != 0); + DBUG_RETURN(mysql_file_write(file, buff, (size_t) (ptr-buff), + MYF(MY_NABP)) != 0); } @@ -992,10 +998,10 @@ uint mi_state_info_read_dsk(File file, MI_STATE_INFO *state, my_bool pRead) { if (pRead) { - if (my_pread(file, buff, state->state_length,0L, MYF(MY_NABP))) + if (mysql_file_pread(file, buff, state->state_length, 0L, MYF(MY_NABP))) return 1; } - else if (my_read(file, buff, state->state_length,MYF(MY_NABP))) + else if (mysql_file_read(file, buff, state->state_length, MYF(MY_NABP))) return 1; mi_state_info_read(buff, state); } @@ -1038,7 +1044,7 @@ uint mi_base_info_write(File file, MI_BASE_INFO *base) mi_int2store(ptr,base->raid_chunks); ptr +=2; mi_int4store(ptr,base->raid_chunksize); ptr +=4; bzero(ptr,6); ptr +=6; /* extra */ - return my_write(file, buff, (size_t) (ptr-buff), MYF(MY_NABP)) != 0; + return mysql_file_write(file, buff, (size_t) (ptr-buff), MYF(MY_NABP)) != 0; } @@ -1098,7 +1104,7 @@ uint mi_keydef_write(File file, MI_KEYDEF *keydef) mi_int2store(ptr,keydef->keylength); ptr +=2; mi_int2store(ptr,keydef->minlength); ptr +=2; mi_int2store(ptr,keydef->maxlength); ptr +=2; - return my_write(file, buff, (size_t) (ptr-buff), MYF(MY_NABP)) != 0; + return mysql_file_write(file, buff, (size_t) (ptr-buff), MYF(MY_NABP)) != 0; } uchar *mi_keydef_read(uchar *ptr, MI_KEYDEF *keydef) @@ -1142,7 +1148,7 @@ int mi_keyseg_write(File file, const HA_KEYSEG *keyseg) mi_int4store(ptr, pos); ptr+=4; - return my_write(file, buff, (size_t) (ptr-buff), MYF(MY_NABP)) != 0; + return mysql_file_write(file, buff, (size_t) (ptr-buff), MYF(MY_NABP)) != 0; } @@ -1184,7 +1190,7 @@ uint mi_uniquedef_write(File file, MI_UNIQUEDEF *def) *ptr++= (uchar) def->key; *ptr++ = (uchar) def->null_are_equal; - return my_write(file, buff, (size_t) (ptr-buff), MYF(MY_NABP)) != 0; + return mysql_file_write(file, buff, (size_t) (ptr-buff), MYF(MY_NABP)) != 0; } uchar *mi_uniquedef_read(uchar *ptr, MI_UNIQUEDEF *def) @@ -1208,7 +1214,7 @@ uint mi_recinfo_write(File file, MI_COLUMNDEF *recinfo) mi_int2store(ptr,recinfo->length); ptr +=2; *ptr++ = recinfo->null_bit; mi_int2store(ptr,recinfo->null_pos); ptr+= 2; - return my_write(file, buff, (size_t) (ptr-buff), MYF(MY_NABP)) != 0; + return mysql_file_write(file, buff, (size_t) (ptr-buff), MYF(MY_NABP)) != 0; } uchar *mi_recinfo_read(uchar *ptr, MI_COLUMNDEF *recinfo) @@ -1261,15 +1267,18 @@ int mi_open_datafile(MI_INFO *info, MYISAM_SHARE *share, const char *org_name, } else #endif - info->dfile=my_open(data_name, share->mode | O_SHARE, MYF(MY_WME)); + info->dfile= mysql_file_open(mi_key_file_dfile, + data_name, share->mode | O_SHARE, MYF(MY_WME)); return info->dfile >= 0 ? 0 : 1; } int mi_open_keyfile(MYISAM_SHARE *share) { - if ((share->kfile=my_open(share->unique_file_name, share->mode | O_SHARE, - MYF(MY_WME))) < 0) + if ((share->kfile= mysql_file_open(mi_key_file_kfile, + share->unique_file_name, + share->mode | O_SHARE, + MYF(MY_WME))) < 0) return 1; return 0; } diff --git a/storage/myisam/mi_packrec.c b/storage/myisam/mi_packrec.c index 887a8254979..ee56d86f5ba 100644 --- a/storage/myisam/mi_packrec.c +++ b/storage/myisam/mi_packrec.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2006 MySQL AB +/* Copyright (C) 2000-2006 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -150,7 +150,7 @@ my_bool _mi_read_pack_info(MI_INFO *info, pbool fix_keys) file=info->dfile; my_errno=0; - if (my_read(file,(uchar*) header,sizeof(header),MYF(MY_NABP))) + if (mysql_file_read(file, (uchar*) header, sizeof(header), MYF(MY_NABP))) { if (!my_errno) my_errno=HA_ERR_END_OF_FILE; @@ -224,9 +224,9 @@ my_bool _mi_read_pack_info(MI_INFO *info, pbool fix_keys) tmp_buff=share->decode_tables+length; disk_cache= (uchar*) (tmp_buff+OFFSET_TABLE_SIZE); - if (my_read(file,disk_cache, - (uint) (share->pack.header_length-sizeof(header)), - MYF(MY_NABP))) + if (mysql_file_read(file, disk_cache, + (uint) (share->pack.header_length-sizeof(header)), + MYF(MY_NABP))) goto err2; huff_tree_bits=max_bit(trees ? trees-1 : 0); @@ -717,8 +717,8 @@ int _mi_read_pack_record(MI_INFO *info, my_off_t filepos, uchar *buf) if (_mi_pack_get_block_info(info, &info->bit_buff, &block_info, &info->rec_buff, file, filepos)) goto err; - if (my_read(file,(uchar*) info->rec_buff + block_info.offset , - block_info.rec_len - block_info.offset, MYF(MY_NABP))) + if (mysql_file_read(file, (uchar*) info->rec_buff + block_info.offset, + block_info.rec_len - block_info.offset, MYF(MY_NABP))) goto panic; info->update|= HA_STATE_AKTIV; DBUG_RETURN(_mi_pack_rec_unpack(info, &info->bit_buff, buf, @@ -1339,9 +1339,9 @@ int _mi_read_rnd_pack_record(MI_INFO *info, uchar *buf, } else { - if (my_read(info->dfile,(uchar*) info->rec_buff + block_info.offset, - block_info.rec_len-block_info.offset, - MYF(MY_NABP))) + if (mysql_file_read(info->dfile, + (uchar*) info->rec_buff + block_info.offset, + block_info.rec_len-block_info.offset, MYF(MY_NABP))) goto err; } info->packed_length=block_info.rec_len; @@ -1370,11 +1370,11 @@ uint _mi_pack_get_block_info(MI_INFO *myisam, MI_BIT_BUFF *bit_buff, { ref_length=myisam->s->pack.ref_length; /* - We can't use my_pread() here because mi_read_rnd_pack_record assumes + We can't use mysql_file_pread() here because mi_read_rnd_pack_record assumes position is ok */ - my_seek(file,filepos,MY_SEEK_SET,MYF(0)); - if (my_read(file, header,ref_length,MYF(MY_NABP))) + mysql_file_seek(file, filepos, MY_SEEK_SET, MYF(0)); + if (mysql_file_read(file, header, ref_length, MYF(MY_NABP))) return BLOCK_FATAL_ERROR; DBUG_DUMP("header",(uchar*) header,ref_length); } @@ -1496,7 +1496,7 @@ my_bool _mi_memmap_file(MI_INFO *info) if (!info->s->file_map) { - if (my_seek(info->dfile,0L,MY_SEEK_END,MYF(0)) < + if (mysql_file_seek(info->dfile, 0L, MY_SEEK_END, MYF(0)) < share->state.state.data_file_length+MEMMAP_EXTRA_MARGIN) { DBUG_PRINT("warning",("File isn't extended for memmap")); diff --git a/storage/myisam/mi_panic.c b/storage/myisam/mi_panic.c index 02dfb239cc0..69865cfc0bb 100644 --- a/storage/myisam/mi_panic.c +++ b/storage/myisam/mi_panic.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2001, 2003 MySQL AB +/* Copyright (C) 2000-2001, 2003 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -30,17 +30,17 @@ int mi_panic(enum ha_panic_function flag) MI_INFO *info; DBUG_ENTER("mi_panic"); - pthread_mutex_lock(&THR_LOCK_myisam); + mysql_mutex_lock(&THR_LOCK_myisam); for (list_element=myisam_open_list ; list_element ; list_element=next_open) { next_open=list_element->next; /* Save if close */ info=(MI_INFO*) list_element->data; switch (flag) { case HA_PANIC_CLOSE: - pthread_mutex_unlock(&THR_LOCK_myisam); /* Not exactly right... */ + mysql_mutex_unlock(&THR_LOCK_myisam); /* Not exactly right... */ if (mi_close(info)) error=my_errno; - pthread_mutex_lock(&THR_LOCK_myisam); + mysql_mutex_lock(&THR_LOCK_myisam); break; case HA_PANIC_WRITE: /* Do this to free databases */ #ifdef CANT_OPEN_FILES_TWICE @@ -66,9 +66,9 @@ int mi_panic(enum ha_panic_function flag) error=my_errno; } #ifdef CANT_OPEN_FILES_TWICE - if (info->s->kfile >= 0 && my_close(info->s->kfile,MYF(0))) + if (info->s->kfile >= 0 && mysql_file_close(info->s->kfile, MYF(0))) error = my_errno; - if (info->dfile >= 0 && my_close(info->dfile,MYF(0))) + if (info->dfile >= 0 && mysql_file_close(info->dfile, MYF(0))) error = my_errno; info->s->kfile=info->dfile= -1; /* Files aren't open anymore */ break; @@ -78,15 +78,19 @@ int mi_panic(enum ha_panic_function flag) { /* Open closed files */ char name_buff[FN_REFLEN]; if (info->s->kfile < 0) - if ((info->s->kfile= my_open(fn_format(name_buff,info->filename,"", - N_NAME_IEXT,4),info->mode, - MYF(MY_WME))) < 0) + if ((info->s->kfile= mysql_file_open(mi_key_file_kfile, + fn_format(name_buff, + info->filename, "", + N_NAME_IEXT, 4), + info->mode, MYF(MY_WME))) < 0) error = my_errno; if (info->dfile < 0) { - if ((info->dfile= my_open(fn_format(name_buff,info->filename,"", - N_NAME_DEXT,4),info->mode, - MYF(MY_WME))) < 0) + if ((info->dfile= mysql_file_open(mi_key_file_dfile, + fn_format(name_buff, + info->filename, "", + N_NAME_DEXT, 4), + info->mode, MYF(MY_WME))) < 0) error = my_errno; info->rec_cache.file=info->dfile; } @@ -106,7 +110,7 @@ int mi_panic(enum ha_panic_function flag) (void) mi_log(0); /* Close log if neaded */ ft_free_stopwords(); } - pthread_mutex_unlock(&THR_LOCK_myisam); + mysql_mutex_unlock(&THR_LOCK_myisam); if (!error) DBUG_RETURN(0); DBUG_RETURN(my_errno=error); diff --git a/storage/myisam/mi_preload.c b/storage/myisam/mi_preload.c index 60ab55106cb..ae45014eab5 100644 --- a/storage/myisam/mi_preload.c +++ b/storage/myisam/mi_preload.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2003, 2005 MySQL AB +/* Copyright (C) 2003, 2005 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -81,7 +81,8 @@ int mi_preload(MI_INFO *info, ulonglong key_map, my_bool ignore_leaves) /* Read the next block of index file into the preload buffer */ if ((my_off_t) length > (key_file_length-pos)) length= (ulong) (key_file_length-pos); - if (my_pread(share->kfile, (uchar*) buff, length, pos, MYF(MY_FAE|MY_FNABP))) + if (mysql_file_pread(share->kfile, (uchar*) buff, length, pos, + MYF(MY_FAE|MY_FNABP))) goto err; if (ignore_leaves) diff --git a/storage/myisam/mi_range.c b/storage/myisam/mi_range.c index dc6dc9d62b7..927c511eec1 100644 --- a/storage/myisam/mi_range.c +++ b/storage/myisam/mi_range.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2004, 2006 MySQL AB +/* Copyright (C) 2000-2004, 2006 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -57,7 +57,7 @@ ha_rows mi_records_in_range(MI_INFO *info, int inx, DBUG_RETURN(HA_POS_ERROR); info->update&= (HA_STATE_CHANGED+HA_STATE_ROW_CHANGED); if (info->s->concurrent_insert) - rw_rdlock(&info->s->key_root_lock[inx]); + mysql_rwlock_rdlock(&info->s->key_root_lock[inx]); switch(info->s->keyinfo[inx].key_alg){ #ifdef HAVE_RTREE_KEYS @@ -106,7 +106,7 @@ ha_rows mi_records_in_range(MI_INFO *info, int inx, } if (info->s->concurrent_insert) - rw_unlock(&info->s->key_root_lock[inx]); + mysql_rwlock_unlock(&info->s->key_root_lock[inx]); fast_mi_writeinfo(info); DBUG_PRINT("info",("records: %ld",(ulong) (res))); diff --git a/storage/myisam/mi_rename.c b/storage/myisam/mi_rename.c index 51669b0caa6..56ccb333d03 100644 --- a/storage/myisam/mi_rename.c +++ b/storage/myisam/mi_rename.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2001, 2004 MySQL AB +/* Copyright (C) 2000-2001, 2004 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -47,7 +47,7 @@ int mi_rename(const char *old_name, const char *new_name) fn_format(from,old_name,"",MI_NAME_IEXT,MY_UNPACK_FILENAME|MY_APPEND_EXT); fn_format(to,new_name,"",MI_NAME_IEXT,MY_UNPACK_FILENAME|MY_APPEND_EXT); - if (my_rename_with_symlink(from, to, MYF(MY_WME))) + if (mysql_file_rename_with_symlink(mi_key_file_kfile, from, to, MYF(MY_WME))) DBUG_RETURN(my_errno); fn_format(from,old_name,"",MI_NAME_DEXT,MY_UNPACK_FILENAME|MY_APPEND_EXT); fn_format(to,new_name,"",MI_NAME_DEXT,MY_UNPACK_FILENAME|MY_APPEND_EXT); @@ -56,5 +56,7 @@ int mi_rename(const char *old_name, const char *new_name) DBUG_RETURN(my_raid_rename(from, to, raid_chunks, MYF(MY_WME)) ? my_errno : 0); #endif - DBUG_RETURN(my_rename_with_symlink(from, to,MYF(MY_WME)) ? my_errno : 0); + DBUG_RETURN(mysql_file_rename_with_symlink(mi_key_file_dfile, + from, to, + MYF(MY_WME)) ? my_errno : 0); } diff --git a/storage/myisam/mi_rkey.c b/storage/myisam/mi_rkey.c index f1d35810d36..d3744c9a053 100644 --- a/storage/myisam/mi_rkey.c +++ b/storage/myisam/mi_rkey.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2006 MySQL AB +/* Copyright (C) 2000-2006 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -71,7 +71,7 @@ int mi_rkey(MI_INFO *info, uchar *buf, int inx, const uchar *key, goto err; if (share->concurrent_insert) - rw_rdlock(&share->key_root_lock[inx]); + mysql_rwlock_rdlock(&share->key_root_lock[inx]); nextflag=myisam_read_vec[search_flag]; use_key_length=pack_key_length; @@ -156,7 +156,7 @@ int mi_rkey(MI_INFO *info, uchar *buf, int inx, const uchar *key, } } if (share->concurrent_insert) - rw_unlock(&share->key_root_lock[inx]); + mysql_rwlock_unlock(&share->key_root_lock[inx]); /* Calculate length of the found key; Used by mi_rnext_same */ if ((keyinfo->flag & HA_VAR_LENGTH_KEY) && last_used_keyseg && diff --git a/storage/myisam/mi_rnext.c b/storage/myisam/mi_rnext.c index 7ce66d41e0f..6def5749043 100644 --- a/storage/myisam/mi_rnext.c +++ b/storage/myisam/mi_rnext.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2004 MySQL AB +/* Copyright (C) 2000-2004 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -39,7 +39,7 @@ int mi_rnext(MI_INFO *info, uchar *buf, int inx) if (fast_mi_readinfo(info)) DBUG_RETURN(my_errno); if (info->s->concurrent_insert) - rw_rdlock(&info->s->key_root_lock[inx]); + mysql_rwlock_rdlock(&info->s->key_root_lock[inx]); changed=_mi_test_if_changed(info); if (!flag) { @@ -96,7 +96,7 @@ int mi_rnext(MI_INFO *info, uchar *buf, int inx) break; } } - rw_unlock(&info->s->key_root_lock[inx]); + mysql_rwlock_unlock(&info->s->key_root_lock[inx]); } /* Don't clear if database-changed */ info->update&= (HA_STATE_CHANGED | HA_STATE_ROW_CHANGED); diff --git a/storage/myisam/mi_rnext_same.c b/storage/myisam/mi_rnext_same.c index 1892fe3e1e0..6779709fc80 100644 --- a/storage/myisam/mi_rnext_same.c +++ b/storage/myisam/mi_rnext_same.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2006 MySQL AB +/* Copyright (C) 2000-2006 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -38,7 +38,7 @@ int mi_rnext_same(MI_INFO *info, uchar *buf) DBUG_RETURN(my_errno); if (info->s->concurrent_insert) - rw_rdlock(&info->s->key_root_lock[inx]); + mysql_rwlock_rdlock(&info->s->key_root_lock[inx]); switch (keyinfo->key_alg) { @@ -81,7 +81,7 @@ int mi_rnext_same(MI_INFO *info, uchar *buf) } } if (info->s->concurrent_insert) - rw_unlock(&info->s->key_root_lock[inx]); + mysql_rwlock_unlock(&info->s->key_root_lock[inx]); /* Don't clear if database-changed */ info->update&= (HA_STATE_CHANGED | HA_STATE_ROW_CHANGED); info->update|= HA_STATE_NEXT_FOUND | HA_STATE_RNEXT_SAME; diff --git a/storage/myisam/mi_rprev.c b/storage/myisam/mi_rprev.c index d1407012590..f7dddefb647 100644 --- a/storage/myisam/mi_rprev.c +++ b/storage/myisam/mi_rprev.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2001, 2004 MySQL AB +/* Copyright (C) 2000-2001, 2004 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -39,7 +39,7 @@ int mi_rprev(MI_INFO *info, uchar *buf, int inx) DBUG_RETURN(my_errno); changed=_mi_test_if_changed(info); if (share->concurrent_insert) - rw_rdlock(&share->key_root_lock[inx]); + mysql_rwlock_rdlock(&share->key_root_lock[inx]); if (!flag) error=_mi_search_last(info, share->keyinfo+inx, share->state.key_root[inx]); @@ -65,7 +65,7 @@ int mi_rprev(MI_INFO *info, uchar *buf, int inx) break; } } - rw_unlock(&share->key_root_lock[inx]); + mysql_rwlock_unlock(&share->key_root_lock[inx]); } info->update&= (HA_STATE_CHANGED | HA_STATE_ROW_CHANGED); info->update|= HA_STATE_PREV_FOUND; diff --git a/storage/myisam/mi_rsame.c b/storage/myisam/mi_rsame.c index 08c482acc9b..ea41dc73c92 100644 --- a/storage/myisam/mi_rsame.c +++ b/storage/myisam/mi_rsame.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2001, 2005 MySQL AB +/* Copyright (C) 2000-2001, 2005 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -49,12 +49,12 @@ int mi_rsame(MI_INFO *info, uchar *record, int inx) info->lastkey_length=_mi_make_key(info,(uint) inx,info->lastkey,record, info->lastpos); if (info->s->concurrent_insert) - rw_rdlock(&info->s->key_root_lock[inx]); + mysql_rwlock_rdlock(&info->s->key_root_lock[inx]); (void) _mi_search(info,info->s->keyinfo+inx,info->lastkey, USE_WHOLE_KEY, SEARCH_SAME, info->s->state.key_root[inx]); if (info->s->concurrent_insert) - rw_unlock(&info->s->key_root_lock[inx]); + mysql_rwlock_unlock(&info->s->key_root_lock[inx]); } if (!(*info->read_record)(info,info->lastpos,record)) diff --git a/storage/myisam/mi_static.c b/storage/myisam/mi_static.c index a3ba785a94f..aaa7405bbb5 100644 --- a/storage/myisam/mi_static.c +++ b/storage/myisam/mi_static.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2002, 2004-2005 MySQL AB +/* Copyright (C) 2000-2002, 2004-2005 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -68,3 +68,74 @@ uint NEAR myisam_readnext_vec[]= SEARCH_BIGGER, SEARCH_BIGGER, SEARCH_SMALLER, SEARCH_BIGGER, SEARCH_SMALLER, SEARCH_BIGGER, SEARCH_SMALLER, SEARCH_SMALLER }; + +#ifdef HAVE_PSI_INTERFACE +PSI_mutex_key mi_key_mutex_MYISAM_SHARE_intern_lock, + mi_key_mutex_MI_SORT_INFO_mutex, mi_key_mutex_MI_CHECK_print_msg; + +static PSI_mutex_info all_myisam_mutexes[]= +{ + { &mi_key_mutex_MI_SORT_INFO_mutex, "MI_SORT_INFO::mutex", 0}, + { &mi_key_mutex_MYISAM_SHARE_intern_lock, "MYISAM_SHARE::intern_lock", 0}, + { &mi_key_mutex_MI_CHECK_print_msg, "MI_CHECK::print_msg", 0} +}; + +PSI_rwlock_key mi_key_rwlock_MYISAM_SHARE_key_root_lock, + mi_key_rwlock_MYISAM_SHARE_mmap_lock; + +static PSI_rwlock_info all_myisam_rwlocks[]= +{ + { &mi_key_rwlock_MYISAM_SHARE_key_root_lock, "MYISAM_SHARE::key_root_lock", 0}, + { &mi_key_rwlock_MYISAM_SHARE_mmap_lock, "MYISAM_SHARE::mmap_lock", 0} +}; + +PSI_cond_key mi_key_cond_MI_SORT_INFO_cond; + +static PSI_cond_info all_myisam_conds[]= +{ + { &mi_key_cond_MI_SORT_INFO_cond, "MI_SORT_INFO::cond", 0} +}; + +PSI_file_key mi_key_file_datatmp, mi_key_file_dfile, mi_key_file_kfile, + mi_key_file_log; + +static PSI_file_info all_myisam_files[]= +{ + { & mi_key_file_datatmp, "data_tmp", 0}, + { & mi_key_file_dfile, "dfile", 0}, + { & mi_key_file_kfile, "kfile", 0}, + { & mi_key_file_log, "log", 0} +}; + +PSI_thread_key mi_key_thread_find_all_keys; + +static PSI_thread_info all_myisam_threads[]= +{ + { &mi_key_thread_find_all_keys, "find_all_keys", 0}, +}; + +void init_myisam_psi_keys() +{ + const char* category= "myisam"; + int count; + + if (PSI_server == NULL) + return; + + count= array_elements(all_myisam_mutexes); + PSI_server->register_mutex(category, all_myisam_mutexes, count); + + count= array_elements(all_myisam_rwlocks); + PSI_server->register_rwlock(category, all_myisam_rwlocks, count); + + count= array_elements(all_myisam_conds); + PSI_server->register_cond(category, all_myisam_conds, count); + + count= array_elements(all_myisam_files); + PSI_server->register_file(category, all_myisam_files, count); + + count= array_elements(all_myisam_threads); + PSI_server->register_thread(category, all_myisam_threads, count); +} +#endif /* HAVE_PSI_INTERFACE */ + diff --git a/storage/myisam/mi_write.c b/storage/myisam/mi_write.c index b9bc84aa6ad..4293d9b5269 100644 --- a/storage/myisam/mi_write.c +++ b/storage/myisam/mi_write.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2006 MySQL AB +/* Copyright (C) 2000-2006 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -107,7 +107,7 @@ int mi_write(MI_INFO *info, uchar *record) is_tree_inited(&info->bulk_insert[i]))); if (local_lock_tree) { - rw_wrlock(&share->key_root_lock[i]); + mysql_rwlock_wrlock(&share->key_root_lock[i]); share->keyinfo[i].version++; } if (share->keyinfo[i].flag & HA_FULLTEXT ) @@ -115,7 +115,7 @@ int mi_write(MI_INFO *info, uchar *record) if (_mi_ft_add(info,i, buff, record, filepos)) { if (local_lock_tree) - rw_unlock(&share->key_root_lock[i]); + mysql_rwlock_unlock(&share->key_root_lock[i]); DBUG_PRINT("error",("Got error: %d on write",my_errno)); goto err; } @@ -126,7 +126,7 @@ int mi_write(MI_INFO *info, uchar *record) _mi_make_key(info,i,buff,record,filepos))) { if (local_lock_tree) - rw_unlock(&share->key_root_lock[i]); + mysql_rwlock_unlock(&share->key_root_lock[i]); DBUG_PRINT("error",("Got error: %d on write",my_errno)); goto err; } @@ -136,7 +136,7 @@ int mi_write(MI_INFO *info, uchar *record) info->update&= ~HA_STATE_RNEXT_SAME; if (local_lock_tree) - rw_unlock(&share->key_root_lock[i]); + mysql_rwlock_unlock(&share->key_root_lock[i]); } } if (share->calc_checksum) @@ -197,13 +197,13 @@ err: !(info->bulk_insert && is_tree_inited(&info->bulk_insert[i]))); if (local_lock_tree) - rw_wrlock(&share->key_root_lock[i]); + mysql_rwlock_wrlock(&share->key_root_lock[i]); if (share->keyinfo[i].flag & HA_FULLTEXT) { if (_mi_ft_del(info,i, buff,record,filepos)) { if (local_lock_tree) - rw_unlock(&share->key_root_lock[i]); + mysql_rwlock_unlock(&share->key_root_lock[i]); break; } } @@ -213,12 +213,12 @@ err: if (_mi_ck_delete(info,i,buff,key_length)) { if (local_lock_tree) - rw_unlock(&share->key_root_lock[i]); + mysql_rwlock_unlock(&share->key_root_lock[i]); break; } } if (local_lock_tree) - rw_unlock(&share->key_root_lock[i]); + mysql_rwlock_unlock(&share->key_root_lock[i]); } } } @@ -943,7 +943,7 @@ static int keys_free(uchar *key, TREE_FREE mode, bulk_insert_param *param) case free_init: if (param->info->s->concurrent_insert) { - rw_wrlock(¶m->info->s->key_root_lock[param->keynr]); + mysql_rwlock_wrlock(¶m->info->s->key_root_lock[param->keynr]); param->info->s->keyinfo[param->keynr].version++; } return 0; @@ -955,7 +955,7 @@ static int keys_free(uchar *key, TREE_FREE mode, bulk_insert_param *param) keylen - param->info->s->rec_reflength); case free_end: if (param->info->s->concurrent_insert) - rw_unlock(¶m->info->s->key_root_lock[param->keynr]); + mysql_rwlock_unlock(¶m->info->s->key_root_lock[param->keynr]); return 0; } return -1; diff --git a/storage/myisam/myisamdef.h b/storage/myisam/myisamdef.h index b64c7f6bd7f..7f617fd044e 100644 --- a/storage/myisam/myisamdef.h +++ b/storage/myisam/myisamdef.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2006 MySQL AB +/* Copyright (C) 2000-2006 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -24,6 +24,7 @@ #else #include <my_no_pthread.h> #endif +#include <mysql/psi/mysql_file.h> #if defined(my_write) && !defined(MAP_TO_USE_RAID) #undef my_write /* undef map from my_nosys; We need test-if-disk full */ @@ -213,13 +214,13 @@ typedef struct st_mi_isam_share { /* Shared between opens */ concurrent_insert; #ifdef THREAD THR_LOCK lock; - pthread_mutex_t intern_lock; /* Locking for use with _locking */ - rw_lock_t *key_root_lock; + mysql_mutex_t intern_lock; /* Locking for use with _locking */ + mysql_rwlock_t *key_root_lock; #endif my_off_t mmaped_length; uint nonmmaped_inserts; /* counter of writing in non-mmaped area */ - rw_lock_t mmap_lock; + mysql_rwlock_t mmap_lock; } MYISAM_SHARE; @@ -460,12 +461,12 @@ typedef struct st_mi_sort_param #define mi_unique_store(A,B) mi_int4store((A),(B)) #ifdef THREAD -extern pthread_mutex_t THR_LOCK_myisam; +extern mysql_mutex_t THR_LOCK_myisam; #endif #if !defined(THREAD) || defined(DONT_USE_RW_LOCKS) -#define rw_wrlock(A) {} -#define rw_rdlock(A) {} -#define rw_unlock(A) {} +#define mysql_rwlock_wrlock(A) {} +#define mysql_rwlock_rdlock(A) {} +#define mysql_rwlock_unlock(A) {} #endif /* Some extern variables */ @@ -785,3 +786,22 @@ int _create_index_by_sort(MI_SORT_PARAM *info,my_bool no_messages, ulong); } #endif +#ifdef HAVE_PSI_INTERFACE +C_MODE_START +extern PSI_mutex_key mi_key_mutex_MYISAM_SHARE_intern_lock, + mi_key_mutex_MI_SORT_INFO_mutex, mi_key_mutex_MI_CHECK_print_msg; + +extern PSI_rwlock_key mi_key_rwlock_MYISAM_SHARE_key_root_lock, + mi_key_rwlock_MYISAM_SHARE_mmap_lock; + +extern PSI_cond_key mi_key_cond_MI_SORT_INFO_cond; + +extern PSI_file_key mi_key_file_datatmp, mi_key_file_dfile, mi_key_file_kfile, + mi_key_file_log; + +extern PSI_thread_key mi_key_thread_find_all_keys; + +void init_myisam_psi_keys(); +C_MODE_END +#endif /* HAVE_PSI_INTERFACE */ + diff --git a/storage/myisam/sort.c b/storage/myisam/sort.c index 670b5f4a30f..441d6bfa05b 100644 --- a/storage/myisam/sort.c +++ b/storage/myisam/sort.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2006 MySQL AB +/* Copyright (C) 2000-2006 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -478,10 +478,10 @@ ok: if (sort_param->read_cache.share) remove_io_thread(&sort_param->read_cache); - pthread_mutex_lock(&sort_param->sort_info->mutex); + mysql_mutex_lock(&sort_param->sort_info->mutex); if (!--sort_param->sort_info->threads_running) - pthread_cond_signal(&sort_param->sort_info->cond); - pthread_mutex_unlock(&sort_param->sort_info->mutex); + mysql_cond_signal(&sort_param->sort_info->cond); + mysql_mutex_unlock(&sort_param->sort_info->mutex); DBUG_PRINT("exit", ("======== ending thread ========")); } my_thread_end(); @@ -824,8 +824,9 @@ static uint NEAR_F read_to_buffer(IO_CACHE *fromfile, BUFFPEK *buffpek, if ((count=(uint) min((ha_rows) buffpek->max_keys,buffpek->count))) { - if (my_pread(fromfile->file,(uchar*) buffpek->base, - (length= sort_length*count),buffpek->file_pos,MYF_RW)) + if (mysql_file_pread(fromfile->file, (uchar*) buffpek->base, + (length= sort_length*count), + buffpek->file_pos, MYF_RW)) return((uint) -1); /* purecov: inspected */ buffpek->key=buffpek->base; buffpek->file_pos+= length; /* New filepos */ @@ -849,12 +850,12 @@ static uint NEAR_F read_to_buffer_varlen(IO_CACHE *fromfile, BUFFPEK *buffpek, for (idx=1;idx<=count;idx++) { - if (my_pread(fromfile->file,(uchar*)&length_of_key,sizeof(length_of_key), - buffpek->file_pos,MYF_RW)) + if (mysql_file_pread(fromfile->file, (uchar*)&length_of_key, + sizeof(length_of_key), buffpek->file_pos, MYF_RW)) return((uint) -1); buffpek->file_pos+=sizeof(length_of_key); - if (my_pread(fromfile->file,(uchar*) buffp,length_of_key, - buffpek->file_pos,MYF_RW)) + if (mysql_file_pread(fromfile->file, (uchar*) buffp, + length_of_key, buffpek->file_pos, MYF_RW)) return((uint) -1); buffpek->file_pos+=length_of_key; buffp = buffp + sort_length; diff --git a/storage/myisammrg/ha_myisammrg.cc b/storage/myisammrg/ha_myisammrg.cc index 760639e2c6b..a34a52d8f9c 100644 --- a/storage/myisammrg/ha_myisammrg.cc +++ b/storage/myisammrg/ha_myisammrg.cc @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2006 MySQL AB +/* Copyright (C) 2000-2006 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -1513,6 +1513,10 @@ static int myisammrg_init(void *p) myisammrg_hton= (handlerton *)p; +#ifdef HAVE_PSI_INTERFACE + init_myisammrg_psi_keys(); +#endif + myisammrg_hton->db_type= DB_TYPE_MRG_MYISAM; myisammrg_hton->create= myisammrg_create_handler; myisammrg_hton->panic= myisammrg_panic; diff --git a/storage/myisammrg/myrg_close.c b/storage/myisammrg/myrg_close.c index 6f641019a73..45e0a82913a 100644 --- a/storage/myisammrg/myrg_close.c +++ b/storage/myisammrg/myrg_close.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2001 MySQL AB +/* Copyright (C) 2000-2001 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -55,10 +55,10 @@ int myrg_close(MYRG_INFO *info) else my_free((uchar*) info->rec_per_key_part, MYF(MY_ALLOW_ZERO_PTR)); delete_queue(&info->by_key); - pthread_mutex_lock(&THR_LOCK_open); + mysql_mutex_lock(&THR_LOCK_open); myrg_open_list=list_delete(myrg_open_list,&info->open_list); - pthread_mutex_unlock(&THR_LOCK_open); - pthread_mutex_destroy(&info->mutex); + mysql_mutex_unlock(&THR_LOCK_open); + mysql_mutex_destroy(&info->mutex); my_free((uchar*) info,MYF(0)); if (error) { diff --git a/storage/myisammrg/myrg_create.c b/storage/myisammrg/myrg_create.c index b030340e743..5fbf8a44b8d 100644 --- a/storage/myisammrg/myrg_create.c +++ b/storage/myisammrg/myrg_create.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2001, 2005 MySQL AB +/* Copyright (C) 2000-2001, 2005 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -32,9 +32,10 @@ int myrg_create(const char *name, const char **table_names, DBUG_ENTER("myrg_create"); errpos=0; - if ((file = my_create(fn_format(buff,name,"",MYRG_NAME_EXT, - MY_UNPACK_FILENAME|MY_APPEND_EXT),0, - O_RDWR | O_EXCL | O_NOFOLLOW,MYF(MY_WME))) < 0) + if ((file= mysql_file_create(rg_key_file_MRG, + fn_format(buff, name, "", MYRG_NAME_EXT, + MY_UNPACK_FILENAME|MY_APPEND_EXT), 0, + O_RDWR | O_EXCL | O_NOFOLLOW, MYF(MY_WME))) < 0) goto err; errpos=1; if (table_names) @@ -46,8 +47,8 @@ int myrg_create(const char *name, const char **table_names, fn_same(buff,name,4); *(end=strend(buff))='\n'; end[1]=0; - if (my_write(file,(uchar*) buff,(uint) (end-buff+1), - MYF(MY_WME | MY_NABP))) + if (mysql_file_write(file, (uchar*) buff, (uint) (end-buff+1), + MYF(MY_WME | MY_NABP))) goto err; } } @@ -55,10 +56,11 @@ int myrg_create(const char *name, const char **table_names, { end=strxmov(buff,"#INSERT_METHOD=", get_type(&merge_insert_method,insert_method-1),"\n",NullS); - if (my_write(file, (uchar*) buff,(uint) (end-buff),MYF(MY_WME | MY_NABP))) + if (mysql_file_write(file, (uchar*) buff, (uint) (end-buff), + MYF(MY_WME | MY_NABP))) goto err; } - if (my_close(file,MYF(0))) + if (mysql_file_close(file, MYF(0))) goto err; DBUG_RETURN(0); @@ -66,7 +68,7 @@ err: save_errno=my_errno ? my_errno : -1; switch (errpos) { case 1: - (void) my_close(file,MYF(0)); + (void) mysql_file_close(file, MYF(0)); } DBUG_RETURN(my_errno=save_errno); } /* myrg_create */ diff --git a/storage/myisammrg/myrg_def.h b/storage/myisammrg/myrg_def.h index 9c69da1424d..b916243be21 100644 --- a/storage/myisammrg/myrg_def.h +++ b/storage/myisammrg/myrg_def.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2001, 2003 MySQL AB +/* Copyright (C) 2000-2001, 2003 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -24,7 +24,7 @@ extern LIST *myrg_open_list; #ifdef THREAD -extern pthread_mutex_t THR_LOCK_open; +extern mysql_mutex_t THR_LOCK_open; #endif int _myrg_init_queue(MYRG_INFO *info,int inx,enum ha_rkey_function search_flag); @@ -33,3 +33,14 @@ int _myrg_mi_read_record(MI_INFO *info, uchar *buf); extern "C" #endif void myrg_print_wrong_table(const char *table_name); + +#ifdef HAVE_PSI_INTERFACE +extern PSI_mutex_key rg_key_mutex_MYRG_INFO_mutex; + +extern PSI_file_key rg_key_file_MRG; + +C_MODE_START +void init_myisammrg_psi_keys(); +C_MODE_END +#endif /* HAVE_PSI_INTERFACE */ + diff --git a/storage/myisammrg/myrg_open.c b/storage/myisammrg/myrg_open.c index d6d1a68ca20..d782224a680 100644 --- a/storage/myisammrg/myrg_open.c +++ b/storage/myisammrg/myrg_open.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2006 MySQL AB +/* Copyright (C) 2000-2006 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -50,9 +50,10 @@ MYRG_INFO *myrg_open(const char *name, int mode, int handle_locking) DBUG_ENTER("myrg_open"); bzero((char*) &file,sizeof(file)); - if ((fd=my_open(fn_format(name_buff,name,"",MYRG_NAME_EXT, - MY_UNPACK_FILENAME|MY_APPEND_EXT), - O_RDONLY | O_SHARE,MYF(0))) < 0) + if ((fd= mysql_file_open(rg_key_file_MRG, + fn_format(name_buff, name, "", MYRG_NAME_EXT, + MY_UNPACK_FILENAME|MY_APPEND_EXT), + O_RDONLY | O_SHARE, MYF(0))) < 0) goto err; errpos=1; if (init_io_cache(&file, fd, 4*IO_SIZE, READ_CACHE, 0, 0, @@ -167,13 +168,14 @@ MYRG_INFO *myrg_open(const char *name, int mode, int handle_locking) m_info->last_used_table=m_info->open_tables; m_info->children_attached= TRUE; - (void) my_close(fd,MYF(0)); + (void) mysql_file_close(fd, MYF(0)); end_io_cache(&file); - pthread_mutex_init(&m_info->mutex, MY_MUTEX_INIT_FAST); + mysql_mutex_init(rg_key_mutex_MYRG_INFO_mutex, + &m_info->mutex, MY_MUTEX_INIT_FAST); m_info->open_list.data=(void*) m_info; - pthread_mutex_lock(&THR_LOCK_open); + mysql_mutex_lock(&THR_LOCK_open); myrg_open_list=list_add(myrg_open_list,&m_info->open_list); - pthread_mutex_unlock(&THR_LOCK_open); + mysql_mutex_unlock(&THR_LOCK_open); DBUG_RETURN(m_info); bad_children: @@ -190,7 +192,7 @@ err: end_io_cache(&file); /* Fall through */ case 1: - (void) my_close(fd,MYF(0)); + (void) mysql_file_close(fd, MYF(0)); } my_errno=save_errno; DBUG_RETURN (NULL); @@ -241,9 +243,11 @@ MYRG_INFO *myrg_parent_open(const char *parent_name, bzero((char*) &file_cache, sizeof(file_cache)); /* Open MERGE meta file. */ - if ((fd= my_open(fn_format(parent_name_buff, parent_name, "", MYRG_NAME_EXT, - MY_UNPACK_FILENAME|MY_APPEND_EXT), - O_RDONLY | O_SHARE, MYF(0))) < 0) + if ((fd= mysql_file_open(rg_key_file_MRG, + fn_format(parent_name_buff, parent_name, + "", MYRG_NAME_EXT, + MY_UNPACK_FILENAME|MY_APPEND_EXT), + O_RDONLY | O_SHARE, MYF(0))) < 0) goto err; /* purecov: inspected */ errpos= 1; @@ -327,13 +331,14 @@ MYRG_INFO *myrg_parent_open(const char *parent_name, } end_io_cache(&file_cache); - (void) my_close(fd, MYF(0)); - pthread_mutex_init(&m_info->mutex, MY_MUTEX_INIT_FAST); + (void) mysql_file_close(fd, MYF(0)); + mysql_mutex_init(rg_key_mutex_MYRG_INFO_mutex, + &m_info->mutex, MY_MUTEX_INIT_FAST); m_info->open_list.data= (void*) m_info; - pthread_mutex_lock(&THR_LOCK_open); + mysql_mutex_lock(&THR_LOCK_open); myrg_open_list= list_add(myrg_open_list, &m_info->open_list); - pthread_mutex_unlock(&THR_LOCK_open); + mysql_mutex_unlock(&THR_LOCK_open); DBUG_RETURN(m_info); @@ -348,7 +353,7 @@ MYRG_INFO *myrg_parent_open(const char *parent_name, end_io_cache(&file_cache); /* Fall through */ case 1: - (void) my_close(fd, MYF(0)); + (void) mysql_file_close(fd, MYF(0)); } my_errno= save_errno; DBUG_RETURN (NULL); @@ -405,7 +410,7 @@ int myrg_attach_children(MYRG_INFO *m_info, int handle_locking, 'open_tables' has all the pointers to the children. Use of a mutex here and in ha_myisammrg::store_lock() forces consistent data. */ - pthread_mutex_lock(&m_info->mutex); + mysql_mutex_lock(&m_info->mutex); rc= 1; errpos= 0; file_offset= 0; @@ -485,7 +490,7 @@ int myrg_attach_children(MYRG_INFO *m_info, int handle_locking, m_info->keys= min_keys; m_info->last_used_table= m_info->open_tables; m_info->children_attached= TRUE; - pthread_mutex_unlock(&m_info->mutex); + mysql_mutex_unlock(&m_info->mutex); DBUG_RETURN(0); bad_children: @@ -497,7 +502,7 @@ err: my_free((char*) m_info->rec_per_key_part, MYF(0)); m_info->rec_per_key_part= NULL; } - pthread_mutex_unlock(&m_info->mutex); + mysql_mutex_unlock(&m_info->mutex); my_errno= save_errno; DBUG_RETURN(1); } @@ -520,7 +525,7 @@ int myrg_detach_children(MYRG_INFO *m_info) { DBUG_ENTER("myrg_detach_children"); /* For symmetry with myrg_attach_children() we use the mutex here. */ - pthread_mutex_lock(&m_info->mutex); + mysql_mutex_lock(&m_info->mutex); if (m_info->tables) { /* Do not attach/detach an empty child list. */ @@ -531,7 +536,7 @@ int myrg_detach_children(MYRG_INFO *m_info) m_info->del= 0; m_info->data_file_length= 0; m_info->options= 0; - pthread_mutex_unlock(&m_info->mutex); + mysql_mutex_unlock(&m_info->mutex); DBUG_RETURN(0); } diff --git a/storage/myisammrg/myrg_static.c b/storage/myisammrg/myrg_static.c index c20d2be4396..b518a3d84c8 100644 --- a/storage/myisammrg/myrg_static.c +++ b/storage/myisammrg/myrg_static.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2001, 2004 MySQL AB +/* Copyright (C) 2000-2001, 2004 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -27,3 +27,35 @@ static const char *merge_insert_methods[] = { "FIRST", "LAST", NullS }; TYPELIB merge_insert_method= { array_elements(merge_insert_methods)-1,"", merge_insert_methods, 0}; + +#ifdef HAVE_PSI_INTERFACE +PSI_mutex_key rg_key_mutex_MYRG_INFO_mutex; + +static PSI_mutex_info all_myisammrg_mutexes[]= +{ + { &rg_key_mutex_MYRG_INFO_mutex, "MYRG_INFO::mutex", 0} +}; + +PSI_file_key rg_key_file_MRG; + +static PSI_file_info all_myisammrg_files[]= +{ + { &rg_key_file_MRG, "MRG", 0} +}; + +void init_myisammrg_psi_keys() +{ + const char* category= "myisammrg"; + int count; + + if (PSI_server == NULL) + return; + + count= array_elements(all_myisammrg_mutexes); + PSI_server->register_mutex(category, all_myisammrg_mutexes, count); + + count= array_elements(all_myisammrg_files); + PSI_server->register_file(category, all_myisammrg_files, count); +} +#endif /* HAVE_PSI_INTERFACE */ + diff --git a/strings/Makefile.am b/strings/Makefile.am index ddd41e627dc..4c34a923d81 100644 --- a/strings/Makefile.am +++ b/strings/Makefile.am @@ -1,4 +1,4 @@ -# Copyright (C) 2000-2006 MySQL AB +# Copyright (C) 2000-2006 MySQL AB, 2009 Sun Microsystems, Inc. # # 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 @@ -15,7 +15,16 @@ # This file is public domain and comes with NO WARRANTY of any kind -INCLUDES = -I$(top_builddir)/include -I$(top_srcdir)/include +# +# Note that the string library is built with #define THREAD, +# which by default cause all the thread related code (my_pthread.h) +# and therefore the associated instrumentation (mysql/psi/mysql_thread.h) +# to be used. +# Since the string code itself is not instrumented, we use +# #define DISABLE_MYSQL_THREAD_H here to avoid unneeded dependencies. +# + +INCLUDES = -I$(top_builddir)/include -I$(top_srcdir)/include -DDISABLE_MYSQL_THREAD_H pkglib_LIBRARIES = libmystrings.a # Exact one of ASSEMBLER_X |