summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/.cvsignore4
-rw-r--r--include/CMakeLists.txt64
-rw-r--r--include/Makefile.am70
-rw-r--r--include/atomic/gcc_builtins.h42
-rw-r--r--include/atomic/generic-msvc.h134
-rw-r--r--include/atomic/nolock.h69
-rw-r--r--include/atomic/rwlock.h100
-rw-r--r--include/atomic/solaris.h72
-rw-r--r--include/atomic/x86-gcc.h145
-rw-r--r--include/config-netware.h162
-rw-r--r--include/config-win.h412
-rw-r--r--include/errmsg.h8
-rw-r--r--include/ft_global.h4
-rw-r--r--include/hash.h68
-rw-r--r--include/heap.h21
-rw-r--r--include/keycache.h17
-rw-r--r--include/lf.h265
-rw-r--r--include/m_ctype.h141
-rw-r--r--include/m_string.h209
-rw-r--r--include/my_aes.h5
-rw-r--r--include/my_alarm.h10
-rw-r--r--include/my_alloc.h9
-rw-r--r--include/my_atomic.h287
-rw-r--r--include/my_attribute.h6
-rw-r--r--include/my_base.h31
-rw-r--r--include/my_bit.h26
-rw-r--r--include/my_bitmap.h26
-rw-r--r--include/my_dbug.h179
-rw-r--r--include/my_dir.h22
-rw-r--r--include/my_getopt.h58
-rw-r--r--include/my_global.h576
-rw-r--r--include/my_handler.h4
-rw-r--r--include/my_libwrap.h4
-rw-r--r--include/my_list.h2
-rw-r--r--include/my_md5.h5
-rw-r--r--include/my_net.h26
-rw-r--r--include/my_no_pthread.h22
-rw-r--r--include/my_nosys.h4
-rw-r--r--include/my_pthread.h388
-rw-r--r--include/my_rdtsc.h129
-rw-r--r--include/my_stacktrace.h2
-rw-r--r--include/my_sys.h240
-rw-r--r--include/my_time.h8
-rw-r--r--include/my_tree.h1
-rw-r--r--include/my_trie.h141
-rw-r--r--include/my_uctype.h4
-rw-r--r--include/my_vle.h38
-rw-r--r--include/myisam.h19
-rw-r--r--include/myisammrg.h4
-rw-r--r--include/myisampack.h4
-rw-r--r--include/mysql.h203
-rw-r--r--include/mysql.h.pp122
-rw-r--r--include/mysql/client_plugin.h163
-rw-r--r--include/mysql/client_plugin.h.pp40
-rw-r--r--include/mysql/innodb_priv.h37
-rw-r--r--include/mysql/plugin.h324
-rw-r--r--include/mysql/plugin_audit.h98
-rw-r--r--include/mysql/plugin_audit.h.pp217
-rw-r--r--include/mysql/plugin_auth.h125
-rw-r--r--include/mysql/plugin_auth.h.pp224
-rw-r--r--include/mysql/plugin_auth_common.h105
-rw-r--r--include/mysql/plugin_ftparser.h211
-rw-r--r--include/mysql/plugin_ftparser.h.pp (renamed from include/mysql/plugin.h.pp)147
-rw-r--r--include/mysql/psi/mysql_file.h1432
-rw-r--r--include/mysql/psi/mysql_thread.h1071
-rw-r--r--include/mysql/psi/psi.h1312
-rw-r--r--include/mysql/psi/psi_abi_v1.h26
-rw-r--r--include/mysql/psi/psi_abi_v1.h.pp323
-rw-r--r--include/mysql/psi/psi_abi_v2.h26
-rw-r--r--include/mysql/psi/psi_abi_v2.h.pp117
-rw-r--r--include/mysql/service_my_snprintf.h101
-rw-r--r--include/mysql/service_thd_alloc.h130
-rw-r--r--include/mysql/service_thd_wait.h83
-rw-r--r--include/mysql/service_thread_scheduler.h65
-rw-r--r--include/mysql/services.h (renamed from include/help_end.h)28
-rw-r--r--include/mysql_com.h74
-rw-r--r--include/mysql_embed.h8
-rw-r--r--include/mysys_err.h3
-rw-r--r--include/password.h32
-rw-r--r--include/probes_mysql.d.base176
-rw-r--r--include/probes_mysql.h13
-rw-r--r--include/probes_mysql_nodtrace.h129
-rw-r--r--include/queues.h3
-rw-r--r--include/rijndael.h5
-rw-r--r--include/service_versions.h (renamed from include/help_start.h)21
-rw-r--r--include/sha1.h5
-rw-r--r--include/sha2.h72
-rw-r--r--include/sql_common.h67
-rw-r--r--include/sslopt-case.h6
-rw-r--r--include/sslopt-longopts.h13
-rw-r--r--include/sslopt-vars.h6
-rw-r--r--include/thr_alarm.h2
-rw-r--r--include/thr_lock.h49
-rw-r--r--include/typelib.h5
-rw-r--r--include/violite.h48
-rw-r--r--include/welcome_copyright_notice.h31
96 files changed, 9307 insertions, 2478 deletions
diff --git a/include/.cvsignore b/include/.cvsignore
deleted file mode 100644
index fc53b1b5f65..00000000000
--- a/include/.cvsignore
+++ /dev/null
@@ -1,4 +0,0 @@
-Makefile
-Makefile.in
-my_config.h
-mysql_version.h
diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt
new file mode 100644
index 00000000000..5334fc0f5ae
--- /dev/null
+++ b/include/CMakeLists.txt
@@ -0,0 +1,64 @@
+# Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+SET(HEADERS_GEN_CONFIGURE
+${CMAKE_CURRENT_BINARY_DIR}/mysql_version.h
+${CMAKE_CURRENT_BINARY_DIR}/my_config.h
+${CMAKE_CURRENT_BINARY_DIR}/mysqld_ername.h
+${CMAKE_CURRENT_BINARY_DIR}/mysqld_error.h
+${CMAKE_CURRENT_BINARY_DIR}/sql_state.h
+)
+SET(HEADERS_ABI
+ mysql.h
+ mysql_com.h
+ mysql_time.h
+ my_list.h
+ my_alloc.h
+ typelib.h
+ mysql/plugin.h
+ mysql/plugin_audit.h
+ mysql/plugin_ftparser.h
+)
+
+SET(HEADERS
+ ${HEADERS_ABI}
+ my_dbug.h
+ m_string.h
+ my_sys.h
+ my_xml.h
+ mysql_embed.h
+ my_pthread.h
+ my_no_pthread.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
+ m_ctype.h
+ my_attribute.h
+ my_compiler.h
+ ${HEADERS_GEN_CONFIGURE}
+)
+
+INSTALL(FILES ${HEADERS} DESTINATION ${INSTALL_INCLUDEDIR} COMPONENT Development)
+INSTALL(DIRECTORY mysql/ DESTINATION ${INSTALL_INCLUDEDIR} COMPONENT Development FILES_MATCHING PATTERN "*.h" )
+
+
diff --git a/include/Makefile.am b/include/Makefile.am
deleted file mode 100644
index 08532db1731..00000000000
--- a/include/Makefile.am
+++ /dev/null
@@ -1,70 +0,0 @@
-# Copyright (C) 2000-2006 MySQL AB
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Library General Public
-# License as published by the Free Software Foundation; version 2
-# of the License.
-#
-# This library 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
-# Library General Public License for more details.
-#
-# You should have received a copy of the GNU Library General Public
-# License along with this library; if not, write to the Free
-# Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
-# MA 02111-1307, USA
-
-BUILT_SOURCES = $(HEADERS_GEN_MAKE) link_sources
-HEADERS_GEN_CONFIGURE = mysql_version.h
-HEADERS_GEN_MAKE = my_config.h
-HEADERS_ABI = mysql.h mysql_com.h mysql_time.h \
- my_list.h my_alloc.h typelib.h mysql/plugin.h
-pkginclude_HEADERS = $(HEADERS_ABI) my_dbug.h m_string.h my_sys.h \
- my_xml.h mysql_embed.h \
- my_pthread.h my_no_pthread.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 \
- m_ctype.h my_attribute.h my_compiler.h \
- $(HEADERS_GEN_CONFIGURE) \
- $(HEADERS_GEN_MAKE)
-
-noinst_HEADERS = config-win.h config-netware.h my_bit.h \
- heap.h my_bitmap.h my_uctype.h \
- myisam.h myisampack.h myisammrg.h ft_global.h\
- mysys_err.h my_base.h help_start.h help_end.h \
- my_nosys.h my_alarm.h queues.h rijndael.h sha1.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 my_vle.h my_user.h \
- my_libwrap.h my_stacktrace.h
-
-EXTRA_DIST = mysql.h.pp mysql/plugin.h.pp
-
-# Remove built files and the symlinked directories
-CLEANFILES = $(BUILT_SOURCES) readline openssl
-
-
-# Some include files that may be moved and patched by configure
-DISTCLEANFILES = sched.h $(CLEANFILES) $(HEADERS_GEN_CONFIGURE)
-
-link_sources:
- -$(RM) -f readline openssl
- @readline_h_ln_cmd@
- @yassl_h_ln_cmd@
- echo timestamp > link_sources
-
-# We want both "my_config.h" and "config.h" that are identical, as
-# MySQL sources assumes the name "my_config.h", and 3rd party sources
-# assumes the name "config.h".
-my_config.h: config.h
- $(CP) config.h my_config.h
-
-# These files should not be included in distributions since they are
-# generated by configure from the .h.in files
-dist-hook:
- $(RM) -f $(distdir)/mysql_version.h $(distdir)/my_config.h
-
-# Don't update the files from bitkeeper
-%::SCCS/s.%
diff --git a/include/atomic/gcc_builtins.h b/include/atomic/gcc_builtins.h
new file mode 100644
index 00000000000..d03d28f572e
--- /dev/null
+++ b/include/atomic/gcc_builtins.h
@@ -0,0 +1,42 @@
+#ifndef ATOMIC_GCC_BUILTINS_INCLUDED
+#define ATOMIC_GCC_BUILTINS_INCLUDED
+
+/* Copyright (C) 2008 MySQL AB
+
+ 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 */
+
+#define make_atomic_add_body(S) \
+ v= __sync_fetch_and_add(a, v);
+#define make_atomic_fas_body(S) \
+ v= __sync_lock_test_and_set(a, v);
+#define make_atomic_cas_body(S) \
+ int ## S sav; \
+ int ## S cmp_val= *cmp; \
+ sav= __sync_val_compare_and_swap(a, cmp_val, set);\
+ if (!(ret= (sav == cmp_val))) *cmp= sav
+
+#ifdef MY_ATOMIC_MODE_DUMMY
+#define make_atomic_load_body(S) ret= *a
+#define make_atomic_store_body(S) *a= v
+#define MY_ATOMIC_MODE "gcc-builtins-up"
+
+#else
+#define MY_ATOMIC_MODE "gcc-builtins-smp"
+#define make_atomic_load_body(S) \
+ ret= __sync_fetch_and_or(a, 0);
+#define make_atomic_store_body(S) \
+ (void) __sync_lock_test_and_set(a, v);
+#endif
+
+#endif /* ATOMIC_GCC_BUILTINS_INCLUDED */
diff --git a/include/atomic/generic-msvc.h b/include/atomic/generic-msvc.h
new file mode 100644
index 00000000000..a84cde6b2c3
--- /dev/null
+++ b/include/atomic/generic-msvc.h
@@ -0,0 +1,134 @@
+/* Copyright (C) 2006-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
+ 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 _atomic_h_cleanup_
+#define _atomic_h_cleanup_ "atomic/generic-msvc.h"
+
+/*
+ We don't implement anything specific for MY_ATOMIC_MODE_DUMMY, always use
+ intrinsics.
+ 8 and 16-bit atomics are not implemented, but it can be done if necessary.
+*/
+#undef MY_ATOMIC_HAS_8_16
+
+#include <windows.h>
+/*
+ x86 compilers (both VS2003 or VS2005) never use instrinsics, but generate
+ function calls to kernel32 instead, even in the optimized build.
+ We force intrinsics as described in MSDN documentation for
+ _InterlockedCompareExchange.
+*/
+#ifdef _M_IX86
+
+#if (_MSC_VER >= 1500)
+#include <intrin.h>
+#else
+C_MODE_START
+/*Visual Studio 2003 and earlier do not have prototypes for atomic intrinsics*/
+LONG _InterlockedCompareExchange (LONG volatile *Target, LONG Value, LONG Comp);
+LONGLONG _InterlockedCompareExchange64 (LONGLONG volatile *Target,
+ LONGLONG Value, LONGLONG Comp);
+C_MODE_END
+
+#pragma intrinsic(_InterlockedCompareExchange)
+#pragma intrinsic(_InterlockedCompareExchange64)
+#endif
+
+#define InterlockedCompareExchange _InterlockedCompareExchange
+#define InterlockedCompareExchange64 _InterlockedCompareExchange64
+/*
+ No need to do something special for InterlockedCompareExchangePointer
+ as it is a #define to InterlockedCompareExchange. The same applies to
+ InterlockedExchangePointer.
+*/
+#endif /*_M_IX86*/
+
+#define MY_ATOMIC_MODE "msvc-intrinsics"
+/* Implement using CAS on WIN32 */
+#define IL_COMP_EXCHG32(X,Y,Z) \
+ InterlockedCompareExchange((volatile LONG *)(X),(Y),(Z))
+#define IL_COMP_EXCHG64(X,Y,Z) \
+ InterlockedCompareExchange64((volatile LONGLONG *)(X), \
+ (LONGLONG)(Y),(LONGLONG)(Z))
+#define IL_COMP_EXCHGptr InterlockedCompareExchangePointer
+
+#define make_atomic_cas_body(S) \
+ int ## S initial_cmp= *cmp; \
+ int ## S initial_a= IL_COMP_EXCHG ## S (a, set, initial_cmp); \
+ if (!(ret= (initial_a == initial_cmp))) *cmp= initial_a;
+
+#ifndef _M_IX86
+/* Use full set of optimised functions on WIN64 */
+#define IL_EXCHG_ADD32(X,Y) \
+ InterlockedExchangeAdd((volatile LONG *)(X),(Y))
+#define IL_EXCHG_ADD64(X,Y) \
+ InterlockedExchangeAdd64((volatile LONGLONG *)(X),(LONGLONG)(Y))
+#define IL_EXCHG32(X,Y) \
+ InterlockedExchange((volatile LONG *)(X),(Y))
+#define IL_EXCHG64(X,Y) \
+ InterlockedExchange64((volatile LONGLONG *)(X),(LONGLONG)(Y))
+#define IL_EXCHGptr InterlockedExchangePointer
+
+#define make_atomic_add_body(S) \
+ v= IL_EXCHG_ADD ## S (a, v)
+#define make_atomic_swap_body(S) \
+ v= IL_EXCHG ## S (a, v)
+#define make_atomic_load_body(S) \
+ ret= 0; /* avoid compiler warning */ \
+ ret= IL_COMP_EXCHG ## S (a, ret, ret);
+#endif
+/*
+ my_yield_processor (equivalent of x86 PAUSE instruction) should be used
+ to improve performance on hyperthreaded CPUs. Intel recommends to use it in
+ spin loops also on non-HT machines to reduce power consumption (see e.g
+ http://softwarecommunity.intel.com/articles/eng/2004.htm)
+
+ Running benchmarks for spinlocks implemented with InterlockedCompareExchange
+ and YieldProcessor shows that much better performance is achieved by calling
+ YieldProcessor in a loop - that is, yielding longer. On Intel boxes setting
+ loop count in the range 200-300 brought best results.
+ */
+#ifndef YIELD_LOOPS
+#define YIELD_LOOPS 200
+#endif
+
+static __inline int my_yield_processor()
+{
+ int i;
+ for(i=0; i<YIELD_LOOPS; i++)
+ {
+#if (_MSC_VER <= 1310)
+ /* On older compilers YieldProcessor is not available, use inline assembly*/
+ __asm { rep nop }
+#else
+ YieldProcessor();
+#endif
+ }
+ return 1;
+}
+
+#define LF_BACKOFF my_yield_processor()
+#else /* cleanup */
+
+#undef IL_EXCHG_ADD32
+#undef IL_EXCHG_ADD64
+#undef IL_COMP_EXCHG32
+#undef IL_COMP_EXCHG64
+#undef IL_COMP_EXCHGptr
+#undef IL_EXCHG32
+#undef IL_EXCHG64
+#undef IL_EXCHGptr
+
+#endif
diff --git a/include/atomic/nolock.h b/include/atomic/nolock.h
new file mode 100644
index 00000000000..4c871473b60
--- /dev/null
+++ b/include/atomic/nolock.h
@@ -0,0 +1,69 @@
+#ifndef ATOMIC_NOLOCK_INCLUDED
+#define ATOMIC_NOLOCK_INCLUDED
+
+/* Copyright (C) 2006 MySQL AB
+
+ 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 */
+
+#if defined(__i386__) || defined(_MSC_VER) || defined(__x86_64__) \
+ || defined(HAVE_GCC_ATOMIC_BUILTINS) \
+ || defined(HAVE_SOLARIS_ATOMIC)
+
+# ifdef MY_ATOMIC_MODE_DUMMY
+# define LOCK_prefix ""
+# else
+# define LOCK_prefix "lock"
+# endif
+/*
+ We choose implementation as follows:
+ ------------------------------------
+ On Windows using Visual C++ the native implementation should be
+ preferrable. When using gcc we prefer the Solaris implementation
+ before the gcc because of stability preference, we choose gcc
+ builtins if available, otherwise we choose the somewhat broken
+ native x86 implementation. If neither Visual C++ or gcc we still
+ choose the Solaris implementation on Solaris (mainly for SunStudio
+ compilers).
+*/
+# if defined(_MSV_VER)
+# include "generic-msvc.h"
+# elif __GNUC__
+# if defined(HAVE_SOLARIS_ATOMIC)
+# include "solaris.h"
+# elif defined(HAVE_GCC_ATOMIC_BUILTINS)
+# include "gcc_builtins.h"
+# elif defined(__i386__) || defined(__x86_64__)
+# include "x86-gcc.h"
+# endif
+# elif defined(HAVE_SOLARIS_ATOMIC)
+# include "solaris.h"
+# endif
+#endif
+
+#if defined(make_atomic_cas_body)
+/*
+ Type not used so minimal size (emptry struct has different size between C
+ and C++, zero-length array is gcc-specific).
+*/
+typedef char my_atomic_rwlock_t __attribute__ ((unused));
+#define my_atomic_rwlock_destroy(name)
+#define my_atomic_rwlock_init(name)
+#define my_atomic_rwlock_rdlock(name)
+#define my_atomic_rwlock_wrlock(name)
+#define my_atomic_rwlock_rdunlock(name)
+#define my_atomic_rwlock_wrunlock(name)
+
+#endif
+
+#endif /* ATOMIC_NOLOCK_INCLUDED */
diff --git a/include/atomic/rwlock.h b/include/atomic/rwlock.h
new file mode 100644
index 00000000000..a31f8ed6ca1
--- /dev/null
+++ b/include/atomic/rwlock.h
@@ -0,0 +1,100 @@
+#ifndef ATOMIC_RWLOCK_INCLUDED
+#define ATOMIC_RWLOCK_INCLUDED
+
+/* Copyright (C) 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
+ 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 */
+
+#define MY_ATOMIC_MODE_RWLOCKS 1
+
+#ifdef MY_ATOMIC_MODE_DUMMY
+/*
+ the following can never be enabled by ./configure, one need to put #define in
+ a source to trigger the following warning. The resulting code will be broken,
+ it only makes sense to do it to see now test_atomic detects broken
+ implementations (another way is to run a UP build on an SMP box).
+*/
+#warning MY_ATOMIC_MODE_DUMMY and MY_ATOMIC_MODE_RWLOCKS are incompatible
+
+typedef char my_atomic_rwlock_t;
+
+#define my_atomic_rwlock_destroy(name)
+#define my_atomic_rwlock_init(name)
+#define my_atomic_rwlock_rdlock(name)
+#define my_atomic_rwlock_wrlock(name)
+#define my_atomic_rwlock_rdunlock(name)
+#define my_atomic_rwlock_wrunlock(name)
+#define MY_ATOMIC_MODE "dummy (non-atomic)"
+#else /* not MY_ATOMIC_MODE_DUMMY */
+
+typedef struct {pthread_mutex_t rw;} my_atomic_rwlock_t;
+
+#ifndef SAFE_MUTEX
+
+/*
+ we're using read-write lock macros but map them to mutex locks, and they're
+ faster. Still, having semantically rich API we can change the
+ underlying implementation, if necessary.
+*/
+#define my_atomic_rwlock_destroy(name) pthread_mutex_destroy(& (name)->rw)
+#define my_atomic_rwlock_init(name) pthread_mutex_init(& (name)->rw, 0)
+#define my_atomic_rwlock_rdlock(name) pthread_mutex_lock(& (name)->rw)
+#define my_atomic_rwlock_wrlock(name) pthread_mutex_lock(& (name)->rw)
+#define my_atomic_rwlock_rdunlock(name) pthread_mutex_unlock(& (name)->rw)
+#define my_atomic_rwlock_wrunlock(name) pthread_mutex_unlock(& (name)->rw)
+
+#else /* SAFE_MUTEX */
+
+/*
+ SAFE_MUTEX pollutes the compiling name space with macros
+ that alter pthread_mutex_t, pthread_mutex_init, etc.
+ Atomic operations should never use the safe mutex wrappers.
+ Unfortunately, there is no way to have both:
+ - safe mutex macros expanding pthread_mutex_lock to safe_mutex_lock
+ - my_atomic macros expanding to unmodified pthread_mutex_lock
+ inlined in the same compilation unit.
+ So, in case of SAFE_MUTEX, a function call is required.
+ Given that SAFE_MUTEX is a debugging facility,
+ this extra function call is not a performance concern for
+ production builds.
+*/
+C_MODE_START
+extern void plain_pthread_mutex_init(safe_mutex_t *);
+extern void plain_pthread_mutex_destroy(safe_mutex_t *);
+extern void plain_pthread_mutex_lock(safe_mutex_t *);
+extern void plain_pthread_mutex_unlock(safe_mutex_t *);
+C_MODE_END
+
+#define my_atomic_rwlock_destroy(name) plain_pthread_mutex_destroy(&(name)->rw)
+#define my_atomic_rwlock_init(name) plain_pthread_mutex_init(&(name)->rw)
+#define my_atomic_rwlock_rdlock(name) plain_pthread_mutex_lock(&(name)->rw)
+#define my_atomic_rwlock_wrlock(name) plain_pthread_mutex_lock(&(name)->rw)
+#define my_atomic_rwlock_rdunlock(name) plain_pthread_mutex_unlock(&(name)->rw)
+#define my_atomic_rwlock_wrunlock(name) plain_pthread_mutex_unlock(&(name)->rw)
+
+#endif /* SAFE_MUTEX */
+
+#define MY_ATOMIC_MODE "mutex"
+#ifndef MY_ATOMIC_MODE_RWLOCKS
+#define MY_ATOMIC_MODE_RWLOCKS 1
+#endif
+#endif
+
+#define make_atomic_add_body(S) int ## S sav; sav= *a; *a+= v; v=sav;
+#define make_atomic_fas_body(S) int ## S sav; sav= *a; *a= v; v=sav;
+#define make_atomic_cas_body(S) if ((ret= (*a == *cmp))) *a= set; else *cmp=*a;
+#define make_atomic_load_body(S) ret= *a;
+#define make_atomic_store_body(S) *a= v;
+
+#endif /* ATOMIC_RWLOCK_INCLUDED */
diff --git a/include/atomic/solaris.h b/include/atomic/solaris.h
new file mode 100644
index 00000000000..5643f878cd2
--- /dev/null
+++ b/include/atomic/solaris.h
@@ -0,0 +1,72 @@
+/* Copyright (C) 2008 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
+ 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 _atomic_h_cleanup_
+#define _atomic_h_cleanup_ "atomic/solaris.h"
+
+#include <atomic.h>
+
+#define MY_ATOMIC_MODE "solaris-atomic"
+
+#if defined(__GNUC__)
+#define atomic_typeof(T,V) __typeof__(V)
+#else
+#define atomic_typeof(T,V) T
+#endif
+
+#define uintptr_t void *
+#define atomic_or_ptr_nv(X,Y) (void *)atomic_or_ulong_nv((volatile ulong_t *)X, Y)
+
+#define make_atomic_cas_body(S) \
+ atomic_typeof(uint ## S ## _t, *cmp) sav; \
+ sav = atomic_cas_ ## S( \
+ (volatile uint ## S ## _t *)a, \
+ (uint ## S ## _t)*cmp, \
+ (uint ## S ## _t)set); \
+ if (! (ret= (sav == *cmp))) \
+ *cmp= sav;
+
+#define make_atomic_add_body(S) \
+ int ## S nv; /* new value */ \
+ nv= atomic_add_ ## S ## _nv((volatile uint ## S ## _t *)a, v); \
+ v= nv - v
+
+/* ------------------------------------------------------------------------ */
+
+#ifdef MY_ATOMIC_MODE_DUMMY
+
+#define make_atomic_load_body(S) ret= *a
+#define make_atomic_store_body(S) *a= v
+
+#else /* MY_ATOMIC_MODE_DUMMY */
+
+#define make_atomic_load_body(S) \
+ ret= atomic_or_ ## S ## _nv((volatile uint ## S ## _t *)a, 0)
+
+#define make_atomic_store_body(S) \
+ (void) atomic_swap_ ## S((volatile uint ## S ## _t *)a, (uint ## S ## _t)v)
+
+#endif
+
+#define make_atomic_fas_body(S) \
+ v= atomic_swap_ ## S((volatile uint ## S ## _t *)a, (uint ## S ## _t)v)
+
+#else /* cleanup */
+
+#undef uintptr_t
+#undef atomic_or_ptr_nv
+
+#endif
+
diff --git a/include/atomic/x86-gcc.h b/include/atomic/x86-gcc.h
new file mode 100644
index 00000000000..90602ef900c
--- /dev/null
+++ b/include/atomic/x86-gcc.h
@@ -0,0 +1,145 @@
+#ifndef ATOMIC_X86_GCC_INCLUDED
+#define ATOMIC_X86_GCC_INCLUDED
+
+/* Copyright (C) 2006 MySQL AB
+
+ 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 */
+
+/*
+ XXX 64-bit atomic operations can be implemented using
+ cmpxchg8b, if necessary. Though I've heard that not all 64-bit
+ architectures support double-word (128-bit) cas.
+*/
+
+/*
+ No special support of 8 and 16 bit operations are implemented here
+ currently.
+*/
+#undef MY_ATOMIC_HAS_8_AND_16
+
+#ifdef __x86_64__
+# ifdef MY_ATOMIC_NO_XADD
+# define MY_ATOMIC_MODE "gcc-amd64" LOCK_prefix "-no-xadd"
+# else
+# define MY_ATOMIC_MODE "gcc-amd64" LOCK_prefix
+# endif
+#else
+# ifdef MY_ATOMIC_NO_XADD
+# define MY_ATOMIC_MODE "gcc-x86" LOCK_prefix "-no-xadd"
+# else
+# define MY_ATOMIC_MODE "gcc-x86" LOCK_prefix
+# endif
+#endif
+
+/* fix -ansi errors while maintaining readability */
+#ifndef asm
+#define asm __asm__
+#endif
+
+#ifndef MY_ATOMIC_NO_XADD
+#define make_atomic_add_body(S) make_atomic_add_body ## S
+#define make_atomic_cas_body(S) make_atomic_cas_body ## S
+#endif
+
+#define make_atomic_add_body32 \
+ asm volatile (LOCK_prefix "; xadd %0, %1;" \
+ : "+r" (v), "=m" (*a) \
+ : "m" (*a) \
+ : "memory")
+
+#define make_atomic_cas_body32 \
+ __typeof__(*cmp) sav; \
+ asm volatile (LOCK_prefix "; cmpxchg %3, %0; setz %2;" \
+ : "=m" (*a), "=a" (sav), "=q" (ret) \
+ : "r" (set), "m" (*a), "a" (*cmp) \
+ : "memory"); \
+ if (!ret) \
+ *cmp= sav
+
+#ifdef __x86_64__
+#define make_atomic_add_body64 make_atomic_add_body32
+#define make_atomic_cas_body64 make_atomic_cas_body32
+
+#define make_atomic_fas_body(S) \
+ asm volatile ("xchg %0, %1;" \
+ : "+r" (v), "=m" (*a) \
+ : "m" (*a) \
+ : "memory")
+
+/*
+ Actually 32-bit reads/writes are always atomic on x86
+ But we add LOCK_prefix here anyway to force memory barriers
+*/
+#define make_atomic_load_body(S) \
+ ret=0; \
+ asm volatile (LOCK_prefix "; cmpxchg %2, %0" \
+ : "=m" (*a), "=a" (ret) \
+ : "r" (ret), "m" (*a) \
+ : "memory")
+#define make_atomic_store_body(S) \
+ asm volatile ("; xchg %0, %1;" \
+ : "=m" (*a), "+r" (v) \
+ : "m" (*a) \
+ : "memory")
+
+#else
+/*
+ Use default implementations of 64-bit operations since we solved
+ the 64-bit problem on 32-bit platforms for CAS, no need to solve it
+ once more for ADD, LOAD, STORE and FAS as well.
+ Since we already added add32 support, we need to define add64
+ here, but we haven't defined fas, load and store at all, so
+ we can fallback on default implementations.
+*/
+#define make_atomic_add_body64 \
+ int64 tmp=*a; \
+ while (!my_atomic_cas64(a, &tmp, tmp+v)) ; \
+ v=tmp;
+
+/*
+ On some platforms (e.g. Mac OS X and Solaris) the ebx register
+ is held as a pointer to the global offset table. Thus we're not
+ allowed to use the b-register on those platforms when compiling
+ PIC code, to avoid this we push ebx and pop ebx. The new value
+ is copied directly from memory to avoid problems with a implicit
+ manipulation of the stack pointer by the push.
+
+ cmpxchg8b works on both 32-bit platforms and 64-bit platforms but
+ the code here is only used on 32-bit platforms, on 64-bit
+ platforms the much simpler make_atomic_cas_body32 will work
+ fine.
+*/
+#define make_atomic_cas_body64 \
+ asm volatile ("push %%ebx;" \
+ "movl (%%ecx), %%ebx;" \
+ "movl 4(%%ecx), %%ecx;" \
+ LOCK_prefix "; cmpxchg8b %0;" \
+ "setz %2; pop %%ebx" \
+ : "=m" (*a), "+A" (*cmp), "=c" (ret) \
+ : "c" (&set), "m" (*a) \
+ : "memory", "esp")
+#endif
+
+/*
+ The implementation of make_atomic_cas_body32 is adaptable to
+ the OS word size, so on 64-bit platforms it will automatically
+ adapt to 64-bits and so it will work also on 64-bit platforms
+*/
+#define make_atomic_cas_bodyptr make_atomic_cas_body32
+
+#ifdef MY_ATOMIC_MODE_DUMMY
+#define make_atomic_load_body(S) ret=*a
+#define make_atomic_store_body(S) *a=v
+#endif
+#endif /* ATOMIC_X86_GCC_INCLUDED */
diff --git a/include/config-netware.h b/include/config-netware.h
deleted file mode 100644
index 4b9e1437170..00000000000
--- a/include/config-netware.h
+++ /dev/null
@@ -1,162 +0,0 @@
-/* Copyright (C) 2000 MySQL AB
-
- 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 */
-
-/* Header for NetWare compatible with MySQL */
-
-#ifndef _config_netware_h
-#define _config_netware_h
-
-#define __event_h__
-#define _EVENT_H_
-/*
- These two #define(s) are needed as both libc of NetWare and MySQL have
- files named event.h which causes compilation errors.
-*/
-
-
-/* required headers */
-#include <unistd.h>
-#include <stdio.h>
-#include <errno.h>
-#include <screen.h>
-#include <limits.h>
-#include <signal.h>
-#include <errno.h>
-#include <stdbool.h>
-#include <stdlib.h>
-#include <sys/types.h>
-#include <time.h>
-#include <sys/time.h>
-#include <pthread.h>
-#include <termios.h>
-
-#undef _EVENT_H_
-/*
- This #undef exists here because both libc of NetWare and MySQL have
- files named event.h which causes compilation errors.
-*/
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/* required adjustments */
-#undef HAVE_READDIR_R
-#undef HAVE_RWLOCK_INIT
-#undef HAVE_SCHED_H
-#undef HAVE_SYS_MMAN_H
-#undef HAVE_SYNCH_H
-#undef HAVE_MMAP
-#undef HAVE_RINT
-
-#define HAVE_PTHREAD_ATTR_SETSTACKSIZE 1
-#define HAVE_PTHREAD_SIGMASK 1
-#define HAVE_PTHREAD_YIELD_ZERO_ARG 1
-#define HAVE_BROKEN_REALPATH 1
-
-/* changes made to make use of LibC-June-2004 for building purpose */
-#undef HAVE_POSIX_SIGNALS
-#undef HAVE_PTHREAD_ATTR_SETSCOPE
-#undef HAVE_ALLOC_A
-#undef HAVE_FINITE
-#undef HAVE_GETPWNAM
-#undef HAVE_GETPWUID
-#undef HAVE_PTHREAD_SETSCHEDPARAM
-#undef HAVE_READLINK
-#undef HAVE_STPCPY
-/* changes end */
-
-/* Changes made to make use of LibC-June-2005 for building purpose */
-#undef HAVE_GETPASS
-#undef HAVE_GETRLIMIT
-#undef HAVE_GETRUSAGE
-#undef HAVE_INITGROUPS
-/* Changes end - LibC-June-2005 */
-
-/* no libc crypt() function */
-#ifdef HAVE_OPENSSL
- #define HAVE_CRYPT 1
-#else
- #undef HAVE_CRYPT
-#endif /* HAVE_OPENSSL */
-
-/* Netware has an ancient zlib */
-#undef HAVE_COMPRESS
-#define HAVE_COMPRESS
-#undef HAVE_ARCHIVE_DB
-
-/* include the old function apis */
-#define USE_OLD_FUNCTIONS 1
-
-/* no case sensitivity */
-#define FN_NO_CASE_SENCE 1
-
-/* the thread alarm is not used */
-#define DONT_USE_THR_ALARM 1
-
-/* signals do not interrupt sockets */
-#define SIGNALS_DONT_BREAK_READ 1
-
-/* signal by closing the sockets */
-#define SIGNAL_WITH_VIO_CLOSE 1
-
-/* On NetWare, stack grows towards lower address */
-#define STACK_DIRECTION -1
-
-/* On NetWare, we need to set stack size for threads, otherwise default 16K is used */
-#define NW_THD_STACKSIZE 65536
-
-/* On NetWare, to fix the problem with the deletion of open files */
-#define CANT_DELETE_OPEN_FILES 1
-
-#define FN_LIBCHAR '\\'
-#define FN_ROOTDIR "\\"
-#define FN_DEVCHAR ':'
-
-/* default directory information */
-#define DEFAULT_MYSQL_HOME "sys:/mysql"
-#define PACKAGE "mysql"
-#define DEFAULT_BASEDIR "sys:/"
-#define SHAREDIR "share/"
-#define DEFAULT_CHARSET_HOME "sys:/mysql/"
-#define MYSQL_DATADIR "data/"
-
-/* 64-bit file system calls */
-#define SIZEOF_OFF_T 8
-#define off_t off64_t
-#define chsize chsize64
-#define ftruncate ftruncate64
-#define lseek lseek64
-#define pread pread64
-#define pwrite pwrite64
-#define tell tell64
-
-/* do not use the extended time in LibC sys\stat.h */
-#define _POSIX_SOURCE
-
-/* Some macros for portability */
-
-#define set_timespec(ABSTIME,SEC) { (ABSTIME).tv_sec=time(NULL)+(SEC); (ABSTIME).tv_nsec=0; }
-
-/* extra protection against CPU Hogs on NetWare */
-#define NETWARE_YIELD pthread_yield()
-/* Screen mode for help texts */
-#define NETWARE_SET_SCREEN_MODE(A) setscreenmode(A)
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _config_netware_h */
diff --git a/include/config-win.h b/include/config-win.h
deleted file mode 100644
index da9b1fc00c3..00000000000
--- a/include/config-win.h
+++ /dev/null
@@ -1,412 +0,0 @@
-/* Copyright 2000-2008 MySQL AB, 2008 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 */
-
-/* Defines for Win32 to make it compatible for MySQL */
-
-#define BIG_TABLES
-
-#if defined(_MSC_VER) && _MSC_VER >= 1400
-/* Avoid endless warnings about sprintf() etc. being unsafe. */
-#define _CRT_SECURE_NO_DEPRECATE 1
-#endif
-
-#include <sys/locking.h>
-#include <winsock2.h>
-#include <fcntl.h>
-#include <io.h>
-#include <malloc.h>
-
-#define HAVE_SMEM 1
-
-#if defined(_WIN64) || defined(WIN64)
-#define SYSTEM_TYPE "Win64"
-#elif defined(_WIN32) || defined(WIN32)
-#define SYSTEM_TYPE "Win32"
-#else
-#define SYSTEM_TYPE "Windows"
-#endif
-
-#if defined(_M_IA64)
-#define MACHINE_TYPE "ia64"
-#elif defined(_M_IX86)
-#define MACHINE_TYPE "ia32"
-#elif defined(_M_ALPHA)
-#define MACHINE_TYPE "axp"
-#else
-#define MACHINE_TYPE "unknown" /* Define to machine type name */
-#endif
-
-#if !(defined(_WIN64) || defined(WIN64))
-#ifndef _WIN32
-#define _WIN32 /* Compatible with old source */
-#endif
-#ifndef __WIN32__
-#define __WIN32__
-#endif
-#endif /* _WIN64 */
-#ifndef __WIN__
-#define __WIN__ /* To make it easier in VC++ */
-#endif
-
-#ifndef MAX_INDEXES
-#define MAX_INDEXES 64
-#endif
-
-/* File and lock constants */
-#define O_SHARE 0x1000 /* Open file in sharing mode */
-#ifdef __BORLANDC__
-#define F_RDLCK LK_NBLCK /* read lock */
-#define F_WRLCK LK_NBRLCK /* write lock */
-#define F_UNLCK LK_UNLCK /* remove lock(s) */
-#else
-#define F_RDLCK _LK_NBLCK /* read lock */
-#define F_WRLCK _LK_NBRLCK /* write lock */
-#define F_UNLCK _LK_UNLCK /* remove lock(s) */
-#endif
-
-#define F_EXCLUSIVE 1 /* We have only exclusive locking */
-#define F_TO_EOF (INT_MAX32/2) /* size for lock of all file */
-#define F_OK 0 /* parameter to access() */
-#define W_OK 2
-
-#define S_IROTH S_IREAD /* for my_lib */
-
-#ifdef __BORLANDC__
-#define FILE_BINARY O_BINARY /* my_fopen in binary mode */
-#define O_TEMPORARY 0
-#define O_SHORT_LIVED 0
-#define SH_DENYNO _SH_DENYNO
-#else
-#define O_BINARY _O_BINARY /* compability with older style names */
-#define FILE_BINARY _O_BINARY /* my_fopen in binary mode */
-#define O_TEMPORARY _O_TEMPORARY
-#define O_SHORT_LIVED _O_SHORT_LIVED
-#define SH_DENYNO _SH_DENYNO
-#endif
-#define NO_OPEN_3 /* For my_create() */
-
-#define SIGQUIT SIGTERM /* No SIGQUIT */
-
-#undef _REENTRANT /* Crashes something for win32 */
-#undef SAFE_MUTEX /* Can't be used on windows */
-
-#if defined(_MSC_VER) && _MSC_VER >= 1310
-#define LL(A) A##ll
-#define ULL(A) A##ull
-#else
-#define LL(A) ((__int64) A)
-#define ULL(A) ((unsigned __int64) A)
-#endif
-
-#define LONGLONG_MIN LL(0x8000000000000000)
-#define LONGLONG_MAX LL(0x7FFFFFFFFFFFFFFF)
-#define ULONGLONG_MAX ULL(0xFFFFFFFFFFFFFFFF)
-
-/* Type information */
-
-#if !defined(HAVE_UINT)
-#undef HAVE_UINT
-#define HAVE_UINT
-typedef unsigned short ushort;
-typedef unsigned int uint;
-#endif /* !defined(HAVE_UINT) */
-
-typedef unsigned __int64 ulonglong; /* Microsofts 64 bit types */
-typedef __int64 longlong;
-#ifndef HAVE_SIGSET_T
-typedef int sigset_t;
-#endif
-#define longlong_defined
-/*
- off_t should not be __int64 because of conflicts in header files;
- Use my_off_t or os_off_t instead
-*/
-#ifndef HAVE_OFF_T
-typedef long off_t;
-#endif
-typedef __int64 os_off_t;
-#ifdef _WIN64
-typedef UINT_PTR rf_SetTimer;
-#else
-#ifndef HAVE_SIZE_T
-typedef unsigned int size_t;
-#endif
-typedef uint rf_SetTimer;
-#endif
-
-#define Socket_defined
-#define my_socket SOCKET
-#define SIGPIPE SIGINT
-#define RETQSORTTYPE void
-#define QSORT_TYPE_IS_VOID
-#define RETSIGTYPE void
-#define SOCKET_SIZE_TYPE int
-#define my_socket_defined
-#define byte_defined
-#define HUGE_PTR
-#define STDCALL __stdcall /* Used by libmysql.dll */
-#define isnan(X) _isnan(X)
-#define finite(X) _finite(X)
-
-#ifndef MYSQL_CLIENT_NO_THREADS
-#define THREAD
-#endif
-#define VOID_SIGHANDLER
-#define SIZEOF_CHAR 1
-#define SIZEOF_INT 4
-#define SIZEOF_LONG 4
-#define SIZEOF_LONG_LONG 8
-#define SIZEOF_OFF_T 8
-#ifdef _WIN64
-#define SIZEOF_CHARP 8
-#else
-#define SIZEOF_CHARP 4
-#endif
-#define HAVE_BROKEN_NETINET_INCLUDES
-#ifdef __NT__
-#define HAVE_NAMED_PIPE /* We can only create pipes on NT */
-#endif
-
-/* ERROR is defined in wingdi.h */
-#undef ERROR
-
-/* We need to close files to break connections on shutdown */
-#ifndef SIGNAL_WITH_VIO_CLOSE
-#define SIGNAL_WITH_VIO_CLOSE
-#endif
-
-/* All windows servers should support .sym files */
-#undef USE_SYMDIR
-#define USE_SYMDIR
-
-/* If LOAD DATA LOCAL INFILE should be enabled by default */
-#define ENABLED_LOCAL_INFILE 1
-
-/* If query profiling should be enabled by default */
-#define ENABLED_PROFILING 1
-
-/* Convert some simple functions to Posix */
-
-#define my_sigset(A,B) signal((A),(B))
-#define finite(A) _finite(A)
-#define sleep(A) Sleep((A)*1000)
-#define popen(A,B) _popen((A),(B))
-#define pclose(A) _pclose(A)
-
-#ifndef __BORLANDC__
-#define access(A,B) _access(A,B)
-#endif
-
-#if !defined(__cplusplus)
-#define inline __inline
-#endif /* __cplusplus */
-
-#ifdef _WIN64
-#define ulonglong2double(A) ((double) (ulonglong) (A))
-#define my_off_t2double(A) ((double) (my_off_t) (A))
-
-#else
-inline double ulonglong2double(ulonglong value)
-{
- longlong nr=(longlong) value;
- if (nr >= 0)
- return (double) nr;
- return (18446744073709551616.0 + (double) nr);
-}
-#define my_off_t2double(A) ulonglong2double(A)
-#endif /* _WIN64 */
-
-inline ulonglong double2ulonglong(double d)
-{
- double t= d - (double) 0x8000000000000000ULL;
-
- if (t >= 0)
- return ((ulonglong) t) + 0x8000000000000000ULL;
- return (ulonglong) d;
-}
-
-#if SIZEOF_OFF_T > 4
-#define lseek(A,B,C) _lseeki64((A),(longlong) (B),(C))
-#define tell(A) _telli64(A)
-#endif
-
-#define STACK_DIRECTION -1
-
-/* Difference between GetSystemTimeAsFileTime() and now() */
-#define OFFSET_TO_EPOCH ULL(116444736000000000)
-
-#define HAVE_PERROR
-#define HAVE_VFPRINT
-#define HAVE_RENAME /* Have rename() as function */
-#define HAVE_BINARY_STREAMS /* Have "b" flag in streams */
-#define HAVE_LONG_JMP /* Have long jump function */
-#define HAVE_LOCKING /* have locking() call */
-#define HAVE_ERRNO_AS_DEFINE /* errno is a define */
-#define HAVE_STDLIB /* everything is include in this file */
-#define HAVE_MEMCPY
-#define HAVE_MEMMOVE
-#define HAVE_GETCWD
-#define HAVE_TELL
-#define HAVE_TZNAME
-#define HAVE_PUTENV
-#define HAVE_SELECT
-#define HAVE_SETLOCALE
-#define HAVE_SOCKET /* Giangi */
-#define HAVE_FLOAT_H
-#define HAVE_LIMITS_H
-#define HAVE_STDDEF_H
-#define NO_FCNTL_NONBLOCK /* No FCNTL */
-#define HAVE_ALLOCA
-#define HAVE_STRPBRK
-#define HAVE_STRSTR
-#define HAVE_COMPRESS
-#define HAVE_CREATESEMAPHORE
-#define HAVE_ISNAN
-#define HAVE_FINITE
-#define HAVE_QUERY_CACHE
-#define SPRINTF_RETURNS_INT
-#define HAVE_SETFILEPOINTER
-#define HAVE_VIO_READ_BUFF
-#if defined(_MSC_VER) && _MSC_VER >= 1400
-/* strnlen() appeared in Studio 2005 */
-#define HAVE_STRNLEN
-#endif
-#define HAVE_WINSOCK2
-
-#define strcasecmp stricmp
-#define strncasecmp strnicmp
-
-#ifndef __NT__
-#undef FILE_SHARE_DELETE
-#define FILE_SHARE_DELETE 0 /* Not implemented on Win 98/ME */
-#endif
-
-#ifdef NOT_USED
-#define HAVE_SNPRINTF /* Gave link error */
-#define _snprintf snprintf
-#endif
-
-#ifdef _MSC_VER
-#define HAVE_LDIV /* The optimizer breaks in zortech for ldiv */
-#define HAVE_ANSI_INCLUDE
-#define HAVE_SYS_UTIME_H
-#define HAVE_STRTOUL
-#endif
-#define my_reinterpret_cast(A) reinterpret_cast <A>
-#define my_const_cast(A) const_cast<A>
-
-
-/* MYSQL OPTIONS */
-
-#ifdef _CUSTOMCONFIG_
-#include <custom_conf.h>
-#else
-#ifndef CMAKE_CONFIGD
-#define DEFAULT_MYSQL_HOME "c:\\mysql"
-#define MYSQL_DATADIR "c:\\mysql\\data"
-#define PACKAGE "mysql"
-#define DEFAULT_BASEDIR "C:\\"
-#define SHAREDIR "share"
-#define DEFAULT_CHARSET_HOME "C:/mysql/"
-#endif
-#endif
-#ifndef DEFAULT_HOME_ENV
-#define DEFAULT_HOME_ENV MYSQL_HOME
-#endif
-#ifndef DEFAULT_GROUP_SUFFIX_ENV
-#define DEFAULT_GROUP_SUFFIX_ENV MYSQL_GROUP_SUFFIX
-#endif
-
-/* File name handling */
-
-#define FN_LIBCHAR '\\'
-#define FN_ROOTDIR "\\"
-#define FN_DEVCHAR ':'
-#define FN_NETWORK_DRIVES /* Uses \\ to indicate network drives */
-#define FN_NO_CASE_SENCE /* Files are not case-sensitive */
-#define OS_FILE_LIMIT 2048
-
-#define DO_NOT_REMOVE_THREAD_WRAPPERS
-#define thread_safe_increment(V,L) InterlockedIncrement((long*) &(V))
-#define thread_safe_decrement(V,L) InterlockedDecrement((long*) &(V))
-/* The following is only used for statistics, so it should be good enough */
-#ifdef __NT__ /* This should also work on Win98 but .. */
-#define thread_safe_add(V,C,L) InterlockedExchangeAdd((long*) &(V),(C))
-#define thread_safe_sub(V,C,L) InterlockedExchangeAdd((long*) &(V),-(long) (C))
-#endif
-
-#define shared_memory_buffer_length 16000
-#define default_shared_memory_base_name "MYSQL"
-
-#define HAVE_SPATIAL 1
-#define HAVE_RTREE_KEYS 1
-
-#define HAVE_OPENSSL 1
-#define HAVE_YASSL 1
-
-#define COMMUNITY_SERVER 1
-#define ENABLED_PROFILING 1
-
-/*
- Our Windows binaries include all character sets which MySQL supports.
- Any changes to the available character sets must also go into
- config/ac-macros/character_sets.m4
-*/
-
-#define MYSQL_DEFAULT_CHARSET_NAME "latin1"
-#define MYSQL_DEFAULT_COLLATION_NAME "latin1_swedish_ci"
-
-#define USE_MB 1
-#define USE_MB_IDENT 1
-#define USE_STRCOLL 1
-
-#define HAVE_CHARSET_armscii8
-#define HAVE_CHARSET_ascii
-#define HAVE_CHARSET_big5 1
-#define HAVE_CHARSET_cp1250 1
-#define HAVE_CHARSET_cp1251
-#define HAVE_CHARSET_cp1256
-#define HAVE_CHARSET_cp1257
-#define HAVE_CHARSET_cp850
-#define HAVE_CHARSET_cp852
-#define HAVE_CHARSET_cp866
-#define HAVE_CHARSET_cp932 1
-#define HAVE_CHARSET_dec8
-#define HAVE_CHARSET_eucjpms 1
-#define HAVE_CHARSET_euckr 1
-#define HAVE_CHARSET_gb2312 1
-#define HAVE_CHARSET_gbk 1
-#define HAVE_CHARSET_geostd8
-#define HAVE_CHARSET_greek
-#define HAVE_CHARSET_hebrew
-#define HAVE_CHARSET_hp8
-#define HAVE_CHARSET_keybcs2
-#define HAVE_CHARSET_koi8r
-#define HAVE_CHARSET_koi8u
-#define HAVE_CHARSET_latin1 1
-#define HAVE_CHARSET_latin2 1
-#define HAVE_CHARSET_latin5
-#define HAVE_CHARSET_latin7
-#define HAVE_CHARSET_macce
-#define HAVE_CHARSET_macroman
-#define HAVE_CHARSET_sjis 1
-#define HAVE_CHARSET_swe7
-#define HAVE_CHARSET_tis620 1
-#define HAVE_CHARSET_ucs2 1
-#define HAVE_CHARSET_ujis 1
-#define HAVE_CHARSET_utf8 1
-
-#define HAVE_UCA_COLLATIONS 1
-#define HAVE_BOOL 1
diff --git a/include/errmsg.h b/include/errmsg.h
index a6d8c770de8..f1d7dd65f97 100644
--- a/include/errmsg.h
+++ b/include/errmsg.h
@@ -1,3 +1,6 @@
+#ifndef ERRMSG_INCLUDED
+#define ERRMSG_INCLUDED
+
/* Copyright (C) 2000 MySQL AB
This program is free software; you can redistribute it and/or modify
@@ -97,6 +100,9 @@ extern const char *client_errors[]; /* Error messages */
#define CR_SERVER_LOST_EXTENDED 2055
#define CR_STMT_CLOSED 2056
#define CR_NEW_STMT_METADATA 2057
-#define CR_ERROR_LAST /*Copy last error nr:*/ 2057
+#define CR_ALREADY_CONNECTED 2058
+#define CR_AUTH_PLUGIN_CANNOT_LOAD 2059
+#define CR_ERROR_LAST /*Copy last error nr:*/ 2059
/* Add error numbers before CR_ERROR_LAST and change it accordingly. */
+#endif /* ERRMSG_INCLUDED */
diff --git a/include/ft_global.h b/include/ft_global.h
index 752371d6bc6..ad56bce678b 100644
--- a/include/ft_global.h
+++ b/include/ft_global.h
@@ -28,6 +28,8 @@ extern "C" {
#define HA_FT_MAXBYTELEN 254
#define HA_FT_MAXCHARLEN (HA_FT_MAXBYTELEN/3)
+#define DEFAULT_FTB_SYNTAX "+ -><()~*:\"\"&|"
+
typedef struct st_ft_info FT_INFO;
struct _ft_vft
{
@@ -51,7 +53,7 @@ extern const char *ft_precompiled_stopwords[];
extern ulong ft_min_word_len;
extern ulong ft_max_word_len;
extern ulong ft_query_expansion_limit;
-extern char ft_boolean_syntax[15];
+extern const char *ft_boolean_syntax;
extern struct st_mysql_ftparser ft_default_parser;
int ft_init_stopwords(void);
diff --git a/include/hash.h b/include/hash.h
index 629b404e8a7..d390cb7d4e6 100644
--- a/include/hash.h
+++ b/include/hash.h
@@ -17,43 +17,24 @@
#ifndef _hash_h
#define _hash_h
-#ifdef __cplusplus
-extern "C" {
-#endif
+
+#include "my_global.h" /* uchar */
+#include "my_sys.h" /* DYNAMIC_ARRAY */
/*
- There was a problem on MacOSX with a shared object ha_example.so.
- It used hash_search(). During build of ha_example.so no libmysys
- was specified. Since MacOSX had a hash_search() in the system
- library, it built the shared object so that the dynamic linker
- linked hash_search() to the system library, which caused a crash
- when called. To come around this, we renamed hash_search() to
- my_hash_search(), as we did long ago with hash_insert() and
- hash_reset(). However, this time we made the move complete with
- all names. To keep compatibility, we redefine the old names.
- Since every C and C++ file, that uses HASH, needs to include
- this file, the change is complete. Both names could be used
- in the code, but the my_* versions are recommended now.
+ This forward declaration is used from C files where the real
+ definition is included before. Since C does not allow repeated
+ typedef declarations, even when identical, the definition may not be
+ repeated.
*/
-#define hash_get_key my_hash_get_key
-#define hash_free_key my_hash_free_key
-#define hash_init my_hash_init
-#define hash_init2 my_hash_init2
-#define _hash_init _my_hash_init
-#define hash_free my_hash_free
-#define hash_reset my_hash_reset
-#define hash_element my_hash_element
-#define hash_search my_hash_search
-#define hash_first my_hash_first
-#define hash_next my_hash_next
-#define hash_insert my_hash_insert
-#define hash_delete my_hash_delete
-#define hash_update my_hash_update
-#define hash_replace my_hash_replace
-#define hash_check my_hash_check
-#define hash_clear my_hash_clear
-#define hash_inited my_hash_inited
-#define hash_init_opt my_hash_init_opt
+#ifndef CHARSET_INFO_DEFINED
+#define CHARSET_INFO_DEFINED
+typedef struct charset_info_st CHARSET_INFO;
+#endif /* CHARSET_INFO_DEFINED */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
/*
Overhead to store an element in hash
@@ -64,6 +45,7 @@ extern "C" {
/* flags for hash_init */
#define HASH_UNIQUE 1 /* hash_insert fails on duplicate key */
+typedef uint my_hash_value_type;
typedef uchar *(*my_hash_get_key)(const uchar *,size_t*,my_bool);
typedef void (*my_hash_free_key)(void *);
@@ -82,20 +64,30 @@ typedef struct st_hash {
typedef uint HASH_SEARCH_STATE;
#define my_hash_init(A,B,C,D,E,F,G,H) \
- _my_hash_init(A,0,B,C,D,E,F,G,H CALLER_INFO)
+ _my_hash_init(A,0,B,C,D,E,F,G,H)
#define my_hash_init2(A,B,C,D,E,F,G,H,I) \
- _my_hash_init(A,B,C,D,E,F,G,H,I CALLER_INFO)
+ _my_hash_init(A,B,C,D,E,F,G,H,I)
my_bool _my_hash_init(HASH *hash, uint growth_size, CHARSET_INFO *charset,
ulong default_array_elements, size_t key_offset,
size_t key_length, my_hash_get_key get_key,
void (*free_element)(void*),
- uint flags CALLER_INFO_PROTO);
+ uint flags);
void my_hash_free(HASH *tree);
void my_hash_reset(HASH *hash);
uchar *my_hash_element(HASH *hash, ulong idx);
uchar *my_hash_search(const HASH *info, const uchar *key, size_t length);
+uchar *my_hash_search_using_hash_value(const HASH *info,
+ my_hash_value_type hash_value,
+ const uchar *key, size_t length);
+my_hash_value_type my_calc_hash(const HASH *info,
+ const uchar *key, size_t length);
uchar *my_hash_first(const HASH *info, const uchar *key, size_t length,
HASH_SEARCH_STATE *state);
+uchar *my_hash_first_from_hash_value(const HASH *info,
+ my_hash_value_type hash_value,
+ const uchar *key,
+ size_t length,
+ HASH_SEARCH_STATE *state);
uchar *my_hash_next(const HASH *info, const uchar *key, size_t length,
HASH_SEARCH_STATE *state);
my_bool my_hash_insert(HASH *info, const uchar *data);
@@ -108,7 +100,7 @@ my_bool my_hash_check(HASH *hash); /* Only in debug library */
#define my_hash_clear(H) bzero((char*) (H), sizeof(*(H)))
#define my_hash_inited(H) ((H)->blength != 0)
#define my_hash_init_opt(A,B,C,D,E,F,G,H) \
- (!my_hash_inited(A) && _my_hash_init(A,0,B,C,D,E,F,G, H CALLER_INFO))
+ (!my_hash_inited(A) && _my_hash_init(A,0,B,C,D,E,F,G,H))
#ifdef __cplusplus
}
diff --git a/include/heap.h b/include/heap.h
index 4a1c7d419ed..a585371e18f 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;
@@ -184,12 +184,22 @@ typedef struct st_heap_info
typedef struct st_heap_create_info
{
+ HP_KEYDEF *keydef;
+ ulong max_records;
+ ulong min_records;
uint auto_key; /* keynr [1 - maxkey] for auto key */
uint auto_key_type;
+ uint keys;
+ uint reclength;
ulonglong max_table_size;
ulonglong auto_increment;
my_bool with_auto_increment;
my_bool internal_table;
+ /*
+ TRUE if heap_create should 'pin' the created share by setting
+ open_count to 1. Is only looked at if not internal_table.
+ */
+ my_bool pin_share;
} HP_CREATE_INFO;
/* Prototypes for heap-functions */
@@ -197,6 +207,7 @@ typedef struct st_heap_create_info
extern HP_INFO *heap_open(const char *name, int mode);
extern HP_INFO *heap_open_from_share(HP_SHARE *share, int mode);
extern HP_INFO *heap_open_from_share_and_register(HP_SHARE *share, int mode);
+extern void heap_release_share(HP_SHARE *share, my_bool internal_table);
extern int heap_close(HP_INFO *info);
extern int heap_write(HP_INFO *info,const uchar *buff);
extern int heap_update(HP_INFO *info,const uchar *old,const uchar *newdata);
@@ -205,9 +216,9 @@ extern int heap_scan_init(HP_INFO *info);
extern int heap_scan(register HP_INFO *info, uchar *record);
extern int heap_delete(HP_INFO *info,const uchar *buff);
extern int heap_info(HP_INFO *info,HEAPINFO *x,int flag);
-extern int heap_create(const char *name, uint keys, HP_KEYDEF *keydef,
- uint reclength, ulong max_records, ulong min_records,
- HP_CREATE_INFO *create_info, HP_SHARE **share);
+extern int heap_create(const char *name,
+ HP_CREATE_INFO *create_info, HP_SHARE **share,
+ my_bool *created_new_share);
extern int heap_delete_table(const char *name);
extern void heap_drop_table(HP_INFO *info);
extern int heap_extra(HP_INFO *info,enum ha_extra_function function);
diff --git a/include/keycache.h b/include/keycache.h
index a6005bae878..fefa31afd87 100644
--- a/include/keycache.h
+++ b/include/keycache.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 2003 MySQL AB
+/* Copyright (C) 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
@@ -17,6 +17,9 @@
#ifndef _keycache_h
#define _keycache_h
+
+#include "my_sys.h" /* flush_type */
+
C_MODE_START
/* declare structures that is used by st_key_cache */
@@ -67,10 +70,10 @@ typedef struct st_key_cache
HASH_LINK *free_hash_list; /* list of free hash links */
BLOCK_LINK *free_block_list; /* list of free blocks */
BLOCK_LINK *block_root; /* memory for block links */
- uchar HUGE_PTR *block_mem; /* memory for block buffers */
+ uchar *block_mem; /* memory for block buffers */
BLOCK_LINK *used_last; /* ptr to the last block of the LRU chain */
BLOCK_LINK *used_ins; /* ptr to the insertion block in LRU chain */
- pthread_mutex_t cache_lock; /* to lock access to the cache structure */
+ mysql_mutex_t cache_lock; /* to lock access to the cache structure */
KEYCACHE_WQUEUE resize_queue; /* threads waiting during resize operation */
/*
Waiting for a zero resize count. Using a queue for symmetry though
@@ -87,10 +90,10 @@ typedef struct st_key_cache
initializing the key cache.
*/
- ulonglong param_buff_size; /* size the memory allocated for the cache */
- ulong param_block_size; /* size of the blocks in the key cache */
- ulong param_division_limit; /* min. percentage of warm blocks */
- ulong param_age_threshold; /* determines when hot block is downgraded */
+ ulonglong param_buff_size; /* size the memory allocated for the cache */
+ ulonglong param_block_size; /* size of the blocks in the key cache */
+ ulonglong param_division_limit; /* min. percentage of warm blocks */
+ ulonglong param_age_threshold; /* determines when hot block is downgraded */
/* Statistics variables. These are reset in reset_key_cache_counters(). */
ulong global_blocks_changed; /* number of currently dirty blocks */
diff --git a/include/lf.h b/include/lf.h
new file mode 100644
index 00000000000..e9fb094493f
--- /dev/null
+++ b/include/lf.h
@@ -0,0 +1,265 @@
+/* Copyright (C) 2007-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
+ 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 _lf_h
+#define _lf_h
+
+#include <my_atomic.h>
+
+C_MODE_START
+
+/*
+ Helpers to define both func() and _func(), where
+ func() is a _func() protected by my_atomic_rwlock_wrlock()
+*/
+
+#define lock_wrap(f, t, proto_args, args, lock) \
+t _ ## f proto_args; \
+static inline t f proto_args \
+{ \
+ t ret; \
+ my_atomic_rwlock_wrlock(lock); \
+ ret= _ ## f args; \
+ my_atomic_rwlock_wrunlock(lock); \
+ return ret; \
+}
+
+#define lock_wrap_void(f, proto_args, args, lock) \
+void _ ## f proto_args; \
+static inline void f proto_args \
+{ \
+ my_atomic_rwlock_wrlock(lock); \
+ _ ## f args; \
+ my_atomic_rwlock_wrunlock(lock); \
+}
+
+#define nolock_wrap(f, t, proto_args, args) \
+t _ ## f proto_args; \
+static inline t f proto_args \
+{ \
+ return _ ## f args; \
+}
+
+#define nolock_wrap_void(f, proto_args, args) \
+void _ ## f proto_args; \
+static inline void f proto_args \
+{ \
+ _ ## f args; \
+}
+
+/*
+ wait-free dynamic array, see lf_dynarray.c
+
+ 4 levels of 256 elements each mean 4311810304 elements in an array - it
+ should be enough for a while
+*/
+#define LF_DYNARRAY_LEVEL_LENGTH 256
+#define LF_DYNARRAY_LEVELS 4
+
+typedef struct {
+ void * volatile level[LF_DYNARRAY_LEVELS];
+ uint size_of_element;
+ my_atomic_rwlock_t lock;
+} LF_DYNARRAY;
+
+typedef int (*lf_dynarray_func)(void *, void *);
+
+void lf_dynarray_init(LF_DYNARRAY *array, uint element_size);
+void lf_dynarray_destroy(LF_DYNARRAY *array);
+
+nolock_wrap(lf_dynarray_value, void *,
+ (LF_DYNARRAY *array, uint idx),
+ (array, idx))
+lock_wrap(lf_dynarray_lvalue, void *,
+ (LF_DYNARRAY *array, uint idx),
+ (array, idx),
+ &array->lock)
+nolock_wrap(lf_dynarray_iterate, int,
+ (LF_DYNARRAY *array, lf_dynarray_func func, void *arg),
+ (array, func, arg))
+
+/*
+ pin manager for memory allocator, lf_alloc-pin.c
+*/
+
+#define LF_PINBOX_PINS 4
+#define LF_PURGATORY_SIZE 10
+
+typedef void lf_pinbox_free_func(void *, void *, void*);
+
+typedef struct {
+ LF_DYNARRAY pinarray;
+ lf_pinbox_free_func *free_func;
+ void *free_func_arg;
+ uint free_ptr_offset;
+ uint32 volatile pinstack_top_ver; /* this is a versioned pointer */
+ uint32 volatile pins_in_array; /* number of elements in array */
+} LF_PINBOX;
+
+typedef struct {
+ void * volatile pin[LF_PINBOX_PINS];
+ LF_PINBOX *pinbox;
+ void **stack_ends_here;
+ void *purgatory;
+ uint32 purgatory_count;
+ uint32 volatile link;
+/* we want sizeof(LF_PINS) to be 64 to avoid false sharing */
+#if SIZEOF_INT*2+SIZEOF_CHARP*(LF_PINBOX_PINS+3) != 64
+ char pad[64-sizeof(uint32)*2-sizeof(void*)*(LF_PINBOX_PINS+3)];
+#endif
+} LF_PINS;
+
+/*
+ shortcut macros to do an atomic_wrlock on a structure that uses pins
+ (e.g. lf_hash).
+*/
+#define lf_rwlock_by_pins(PINS) \
+ my_atomic_rwlock_wrlock(&(PINS)->pinbox->pinarray.lock)
+#define lf_rwunlock_by_pins(PINS) \
+ my_atomic_rwlock_wrunlock(&(PINS)->pinbox->pinarray.lock)
+
+/*
+ compile-time assert, to require "no less than N" pins
+ it's enough if it'll fail on at least one compiler, so
+ we'll enable it on GCC only, which supports zero-length arrays.
+*/
+#if defined(__GNUC__) && defined(MY_LF_EXTRA_DEBUG)
+#define LF_REQUIRE_PINS(N) \
+ static const char require_pins[LF_PINBOX_PINS-N] \
+ __attribute__ ((unused)); \
+ static const int LF_NUM_PINS_IN_THIS_FILE= N;
+#define _lf_pin(PINS, PIN, ADDR) \
+ ( \
+ assert(PIN < LF_NUM_PINS_IN_THIS_FILE), \
+ my_atomic_storeptr(&(PINS)->pin[PIN], (ADDR)) \
+ )
+#else
+#define LF_REQUIRE_PINS(N)
+#define _lf_pin(PINS, PIN, ADDR) my_atomic_storeptr(&(PINS)->pin[PIN], (ADDR))
+#endif
+
+#define _lf_unpin(PINS, PIN) _lf_pin(PINS, PIN, NULL)
+#define lf_pin(PINS, PIN, ADDR) \
+ do { \
+ lf_rwlock_by_pins(PINS); \
+ _lf_pin(PINS, PIN, ADDR); \
+ lf_rwunlock_by_pins(PINS); \
+ } while (0)
+#define lf_unpin(PINS, PIN) lf_pin(PINS, PIN, NULL)
+#define _lf_assert_pin(PINS, PIN) assert((PINS)->pin[PIN] != 0)
+#define _lf_assert_unpin(PINS, PIN) assert((PINS)->pin[PIN] == 0)
+
+void lf_pinbox_init(LF_PINBOX *pinbox, uint free_ptr_offset,
+ lf_pinbox_free_func *free_func, void * free_func_arg);
+void lf_pinbox_destroy(LF_PINBOX *pinbox);
+
+lock_wrap(lf_pinbox_get_pins, LF_PINS *,
+ (LF_PINBOX *pinbox),
+ (pinbox),
+ &pinbox->pinarray.lock)
+lock_wrap_void(lf_pinbox_put_pins,
+ (LF_PINS *pins),
+ (pins),
+ &pins->pinbox->pinarray.lock)
+lock_wrap_void(lf_pinbox_free,
+ (LF_PINS *pins, void *addr),
+ (pins, addr),
+ &pins->pinbox->pinarray.lock)
+
+/*
+ memory allocator, lf_alloc-pin.c
+*/
+
+typedef struct st_lf_allocator {
+ LF_PINBOX pinbox;
+ uchar * volatile top;
+ uint element_size;
+ uint32 volatile mallocs;
+} LF_ALLOCATOR;
+
+void lf_alloc_init(LF_ALLOCATOR *allocator, uint size, uint free_ptr_offset);
+void lf_alloc_destroy(LF_ALLOCATOR *allocator);
+uint lf_alloc_pool_count(LF_ALLOCATOR *allocator);
+/*
+ shortcut macros to access underlying pinbox functions from an LF_ALLOCATOR
+ see _lf_pinbox_get_pins() and _lf_pinbox_put_pins()
+*/
+#define _lf_alloc_free(PINS, PTR) _lf_pinbox_free((PINS), (PTR))
+#define lf_alloc_free(PINS, PTR) lf_pinbox_free((PINS), (PTR))
+#define _lf_alloc_get_pins(A) _lf_pinbox_get_pins(&(A)->pinbox)
+#define lf_alloc_get_pins(A) lf_pinbox_get_pins(&(A)->pinbox)
+#define _lf_alloc_put_pins(PINS) _lf_pinbox_put_pins(PINS)
+#define lf_alloc_put_pins(PINS) lf_pinbox_put_pins(PINS)
+#define lf_alloc_direct_free(ALLOC, ADDR) my_free((ADDR))
+
+lock_wrap(lf_alloc_new, void *,
+ (LF_PINS *pins),
+ (pins),
+ &pins->pinbox->pinarray.lock)
+
+C_MODE_END
+
+/*
+ extendible hash, lf_hash.c
+*/
+#include <hash.h>
+
+C_MODE_START
+
+#define LF_HASH_UNIQUE 1
+
+/* lf_hash overhead per element is sizeof(LF_SLIST). */
+
+typedef struct {
+ LF_DYNARRAY array; /* hash itself */
+ LF_ALLOCATOR alloc; /* allocator for elements */
+ my_hash_get_key get_key; /* see HASH */
+ CHARSET_INFO *charset; /* see HASH */
+ uint key_offset, key_length; /* see HASH */
+ uint element_size; /* size of memcpy'ed area on insert */
+ uint flags; /* LF_HASH_UNIQUE, etc */
+ int32 volatile size; /* size of array */
+ int32 volatile count; /* number of elements in the hash */
+} LF_HASH;
+
+void lf_hash_init(LF_HASH *hash, uint element_size, uint flags,
+ uint key_offset, uint key_length, my_hash_get_key get_key,
+ CHARSET_INFO *charset);
+void lf_hash_destroy(LF_HASH *hash);
+int lf_hash_insert(LF_HASH *hash, LF_PINS *pins, const void *data);
+void *lf_hash_search(LF_HASH *hash, LF_PINS *pins, const void *key, uint keylen);
+int lf_hash_delete(LF_HASH *hash, LF_PINS *pins, const void *key, uint keylen);
+/*
+ shortcut macros to access underlying pinbox functions from an LF_HASH
+ see _lf_pinbox_get_pins() and _lf_pinbox_put_pins()
+*/
+#define _lf_hash_get_pins(HASH) _lf_alloc_get_pins(&(HASH)->alloc)
+#define lf_hash_get_pins(HASH) lf_alloc_get_pins(&(HASH)->alloc)
+#define _lf_hash_put_pins(PINS) _lf_pinbox_put_pins(PINS)
+#define lf_hash_put_pins(PINS) lf_pinbox_put_pins(PINS)
+#define lf_hash_search_unpin(PINS) lf_unpin((PINS), 2)
+/*
+ cleanup
+*/
+
+#undef lock_wrap_void
+#undef lock_wrap
+#undef nolock_wrap_void
+#undef nolock_wrap
+
+C_MODE_END
+
+#endif
+
diff --git a/include/m_ctype.h b/include/m_ctype.h
index 451c8db549b..c054de8d7fd 100644
--- a/include/m_ctype.h
+++ b/include/m_ctype.h
@@ -15,13 +15,13 @@
/*
A better inplementation of the UNIX ctype(3) library.
- Notes: my_global.h should be included before ctype.h
*/
#ifndef _m_ctype_h
#define _m_ctype_h
#include <my_attribute.h>
+#include "my_global.h" /* uint16, uchar */
#ifdef __cplusplus
extern "C" {
@@ -38,11 +38,29 @@ extern "C" {
#define my_wc_t ulong
+#define MY_CS_REPLACEMENT_CHARACTER 0xFFFD
+
+/*
+ On i386 we store Unicode->CS conversion tables for
+ some character sets using Big-endian order,
+ to copy two bytes at onces.
+ This gives some performance improvement.
+*/
+#ifdef __i386__
+#define MB2(x) (((x) >> 8) + (((x) & 0xFF) << 8))
+#define MY_PUT_MB2(s, code) { *((uint16*)(s))= (code); }
+#else
+#define MB2(x) (x)
+#define MY_PUT_MB2(s, code) { (s)[0]= code >> 8; (s)[1]= code & 0xFF; }
+#endif
+
+
+
typedef struct unicase_info_st
{
- uint16 toupper;
- uint16 tolower;
- uint16 sort;
+ uint32 toupper;
+ uint32 tolower;
+ uint32 sort;
} MY_UNICASE_INFO;
@@ -81,12 +99,14 @@ extern MY_UNI_CTYPE my_uni_ctype[256];
#define MY_CS_BINSORT 16 /* if binary sort order */
#define MY_CS_PRIMARY 32 /* if primary collation */
#define MY_CS_STRNXFRM 64 /* if strnxfrm is used for sort */
-#define MY_CS_UNICODE 128 /* is a charset is full unicode */
+#define MY_CS_UNICODE 128 /* is a charset is BMP Unicode */
#define MY_CS_READY 256 /* if a charset is initialized */
#define MY_CS_AVAILABLE 512 /* If either compiled-in or loaded*/
#define MY_CS_CSSORT 1024 /* if case sensitive sort order */
#define MY_CS_HIDDEN 2048 /* don't display in SHOW */
#define MY_CS_PUREASCII 4096 /* if a charset is pure ascii */
+#define MY_CS_NONASCII 8192 /* if not ASCII-compatible */
+#define MY_CS_UNICODE_SUPPLEMENT 16384 /* Non-BMP Unicode characters */
#define MY_CHARSET_UNDEFINED 0
/* Character repertoire flags */
@@ -94,7 +114,6 @@ extern MY_UNI_CTYPE my_uni_ctype[256];
#define MY_REPERTOIRE_EXTENDED 2 /* Extended characters: U+0080..U+FFFF */
#define MY_REPERTOIRE_UNICODE30 3 /* ASCII | EXTENDED: U+0000..U+FFFF */
-
typedef struct my_uni_idx_st
{
uint16 from;
@@ -246,6 +265,12 @@ extern MY_CHARSET_HANDLER my_charset_8bit_handler;
extern MY_CHARSET_HANDLER my_charset_ucs2_handler;
+/*
+ We define this CHARSET_INFO_DEFINED here to prevent a repeat of the
+ typedef in hash.c, which will cause a compiler error.
+*/
+#define CHARSET_INFO_DEFINED
+
/* See strings/CHARSET_INFO.txt about information on this structure */
typedef struct charset_info_st
{
@@ -286,10 +311,14 @@ typedef struct charset_info_st
extern MYSQL_PLUGIN_IMPORT CHARSET_INFO my_charset_bin;
+extern MYSQL_PLUGIN_IMPORT CHARSET_INFO my_charset_latin1;
+extern MYSQL_PLUGIN_IMPORT CHARSET_INFO my_charset_filename;
+
extern CHARSET_INFO my_charset_big5_chinese_ci;
extern CHARSET_INFO my_charset_big5_bin;
extern CHARSET_INFO my_charset_cp932_japanese_ci;
extern CHARSET_INFO my_charset_cp932_bin;
+extern CHARSET_INFO my_charset_cp1250_czech_ci;
extern CHARSET_INFO my_charset_eucjpms_japanese_ci;
extern CHARSET_INFO my_charset_eucjpms_bin;
extern CHARSET_INFO my_charset_euckr_korean_ci;
@@ -298,7 +327,6 @@ extern CHARSET_INFO my_charset_gb2312_chinese_ci;
extern CHARSET_INFO my_charset_gb2312_bin;
extern CHARSET_INFO my_charset_gbk_chinese_ci;
extern CHARSET_INFO my_charset_gbk_bin;
-extern MYSQL_PLUGIN_IMPORT CHARSET_INFO my_charset_latin1;
extern CHARSET_INFO my_charset_latin1_german2_ci;
extern CHARSET_INFO my_charset_latin1_bin;
extern CHARSET_INFO my_charset_latin2_czech_ci;
@@ -311,11 +339,48 @@ extern CHARSET_INFO my_charset_ucs2_bin;
extern CHARSET_INFO my_charset_ucs2_unicode_ci;
extern CHARSET_INFO my_charset_ujis_japanese_ci;
extern CHARSET_INFO my_charset_ujis_bin;
+extern CHARSET_INFO my_charset_utf16_bin;
+extern CHARSET_INFO my_charset_utf16_general_ci;
+extern CHARSET_INFO my_charset_utf16_unicode_ci;
+extern CHARSET_INFO my_charset_utf32_bin;
+extern CHARSET_INFO my_charset_utf32_general_ci;
+extern CHARSET_INFO my_charset_utf32_unicode_ci;
+
extern CHARSET_INFO my_charset_utf8_general_ci;
extern CHARSET_INFO my_charset_utf8_unicode_ci;
extern CHARSET_INFO my_charset_utf8_bin;
-extern CHARSET_INFO my_charset_cp1250_czech_ci;
-extern MYSQL_PLUGIN_IMPORT CHARSET_INFO my_charset_filename;
+extern CHARSET_INFO my_charset_utf8mb4_bin;
+extern CHARSET_INFO my_charset_utf8mb4_general_ci;
+extern CHARSET_INFO my_charset_utf8mb4_unicode_ci;
+#define MY_UTF8MB3 "utf8"
+#define MY_UTF8MB4 "utf8mb4"
+
+
+/* Helper functions to handle contraction */
+static inline my_bool
+my_cs_have_contractions(CHARSET_INFO *cs)
+{
+ return cs->contractions != NULL;
+}
+
+static inline my_bool
+my_cs_can_be_contraction_head(CHARSET_INFO *cs, my_wc_t wc)
+{
+ return ((const char *)cs->contractions)[0x40*0x40 + (wc & 0xFF)];
+}
+
+static inline my_bool
+my_cs_can_be_contraction_tail(CHARSET_INFO *cs, my_wc_t wc)
+{
+ return ((const char *)cs->contractions)[0x40*0x40 + (wc & 0xFF)];
+}
+
+static inline uint16*
+my_cs_contraction2_weight(CHARSET_INFO *cs, my_wc_t wc1, my_wc_t wc2)
+{
+ return &cs->contractions[(wc1 - 0x40) * 0x40 + wc2 - 0x40];
+}
+
/* declarations for simple charsets */
extern size_t my_strnxfrm_simple(CHARSET_INFO *, uchar *, size_t,
@@ -391,6 +456,7 @@ ulonglong my_strntoull10rnd_ucs2(CHARSET_INFO *cs,
void my_fill_8bit(CHARSET_INFO *cs, char* to, size_t l, int fill);
+/* For 8-bit character set */
my_bool my_like_range_simple(CHARSET_INFO *cs,
const char *ptr, size_t ptr_length,
pbool escape, pbool w_one, pbool w_many,
@@ -398,6 +464,7 @@ my_bool my_like_range_simple(CHARSET_INFO *cs,
char *min_str, char *max_str,
size_t *min_length, size_t *max_length);
+/* For ASCII-based multi-byte character sets with mbminlen=1 */
my_bool my_like_range_mb(CHARSET_INFO *cs,
const char *ptr, size_t ptr_length,
pbool escape, pbool w_one, pbool w_many,
@@ -405,13 +472,13 @@ my_bool my_like_range_mb(CHARSET_INFO *cs,
char *min_str, char *max_str,
size_t *min_length, size_t *max_length);
-my_bool my_like_range_ucs2(CHARSET_INFO *cs,
- const char *ptr, size_t ptr_length,
- pbool escape, pbool w_one, pbool w_many,
- size_t res_length,
- char *min_str, char *max_str,
- size_t *min_length, size_t *max_length);
-
+/* For other character sets, with arbitrary mbminlen and mbmaxlen numbers */
+my_bool my_like_range_generic(CHARSET_INFO *cs,
+ const char *ptr, size_t ptr_length,
+ pbool escape, pbool w_one, pbool w_many,
+ size_t res_length,
+ char *min_str, char *max_str,
+ size_t *min_length, size_t *max_length);
int my_wildcmp_8bit(CHARSET_INFO *,
const char *str,const char *str_end,
@@ -438,6 +505,14 @@ extern size_t my_caseup_mb(CHARSET_INFO *, char *src, size_t srclen,
char *dst, size_t dstlen);
extern size_t my_casedn_mb(CHARSET_INFO *, char *src, size_t srclen,
char *dst, size_t dstlen);
+extern size_t my_caseup_mb_varlen(CHARSET_INFO *, char *src, size_t srclen,
+ char *dst, size_t dstlen);
+extern size_t my_casedn_mb_varlen(CHARSET_INFO *, char *src, size_t srclen,
+ char *dst, size_t dstlen);
+extern size_t my_caseup_ujis(CHARSET_INFO *, char *src, size_t srclen,
+ char *dst, size_t dstlen);
+extern size_t my_casedn_ujis(CHARSET_INFO *, char *src, size_t srclen,
+ char *dst, size_t dstlen);
extern int my_strcasecmp_mb(CHARSET_INFO * cs,const char *, const char *);
int my_wildcmp_mb(CHARSET_INFO *,
@@ -454,6 +529,36 @@ uint my_instr_mb(struct charset_info_st *,
const char *s, size_t s_length,
my_match_t *match, uint nmatch);
+int my_strnncoll_mb_bin(CHARSET_INFO * cs,
+ const uchar *s, size_t slen,
+ const uchar *t, size_t tlen,
+ my_bool t_is_prefix);
+
+int my_strnncollsp_mb_bin(CHARSET_INFO *cs,
+ const uchar *a, size_t a_length,
+ const uchar *b, size_t b_length,
+ my_bool diff_if_only_endspace_difference);
+
+int my_wildcmp_mb_bin(CHARSET_INFO *cs,
+ const char *str,const char *str_end,
+ const char *wildstr,const char *wildend,
+ int escape, int w_one, int w_many);
+
+int my_strcasecmp_mb_bin(CHARSET_INFO * cs __attribute__((unused)),
+ const char *s, const char *t);
+
+void my_hash_sort_mb_bin(CHARSET_INFO *cs __attribute__((unused)),
+ const uchar *key, size_t len,ulong *nr1, ulong *nr2);
+
+size_t my_strnxfrm_unicode(CHARSET_INFO *,
+ uchar *dst, size_t dstlen,
+ const uchar *src, size_t srclen);
+
+size_t my_strnxfrm_unicode_full_bin(CHARSET_INFO *,
+ uchar *dst, size_t dstlen,
+ const uchar *src, size_t srclen);
+size_t my_strnxfrmlen_unicode_full_bin(CHARSET_INFO *, size_t);
+
int my_wildcmp_unicode(CHARSET_INFO *cs,
const char *str, const char *str_end,
const char *wildstr, const char *wildend,
@@ -474,6 +579,10 @@ my_bool my_charset_is_ascii_based(CHARSET_INFO *cs);
my_bool my_charset_is_8bit_pure_ascii(CHARSET_INFO *cs);
uint my_charset_repertoire(CHARSET_INFO *cs);
+my_bool my_charset_is_ascii_compatible(CHARSET_INFO *cs);
+
+extern size_t my_vsnprintf_ex(CHARSET_INFO *cs, char *to, size_t n,
+ const char* fmt, va_list ap);
#define _MY_U 01 /* Upper case */
#define _MY_L 02 /* Lower case */
diff --git a/include/m_string.h b/include/m_string.h
index 0d248ea0ad3..d2194858589 100644
--- a/include/m_string.h
+++ b/include/m_string.h
@@ -20,6 +20,9 @@
#ifndef _m_string_h
#define _m_string_h
+
+#include "my_global.h" /* HAVE_* */
+
#ifndef __USE_GNU
#define __USE_GNU /* We want to use stpcpy */
#endif
@@ -49,8 +52,6 @@
# define memmove(d, s, n) bmove ((d), (s), (n))
#elif defined(HAVE_MEMMOVE)
# define bmove(d, s, n) memmove((d), (s), (n))
-#else
-# define memmove(d, s, n) bmove((d), (s), (n)) /* our bmove */
#endif
/* Unixware 7 */
@@ -83,53 +84,23 @@ extern char *stpcpy(char *, const char *); /* For AIX with gcc 2.95.3 */
#endif
/* Declared in int2str() */
-extern char NEAR _dig_vec_upper[];
-extern char NEAR _dig_vec_lower[];
-
-/* Defined in strtod.c */
-extern const double log_10[309];
+extern char _dig_vec_upper[];
+extern char _dig_vec_lower[];
#ifndef strmov
#define strmov_overlapp(A,B) strmov(A,B)
#define strmake_overlapp(A,B,C) strmake(A,B,C)
#endif
-#ifdef BAD_MEMCPY /* Problem with gcc on Alpha */
-#define memcpy_fixed(A,B,C) bmove((A),(B),(C))
-#else
-#define memcpy_fixed(A,B,C) memcpy((A),(B),(C))
-#endif
-
-#if (!defined(USE_BMOVE512) || defined(HAVE_purify)) && !defined(bmove512)
-#define bmove512(A,B,C) memcpy(A,B,C)
-#endif
-
/* Prototypes for string functions */
-#if !defined(bfill) && !defined(HAVE_BFILL)
-extern void bfill(uchar *dst,size_t len,pchar fill);
-#endif
-
-#ifndef bmove512
-extern void bmove512(uchar *dst,const uchar *src,size_t len);
-#endif
-
-#if !defined(HAVE_BMOVE) && !defined(bmove)
-extern void bmove(uuchar *dst, const uchar *src,size_t len);
-#endif
-
extern void bmove_upp(uchar *dst,const uchar *src,size_t len);
extern void bchange(uchar *dst,size_t old_len,const uchar *src,
size_t new_len,size_t tot_len);
extern void strappend(char *s,size_t len,pchar fill);
extern char *strend(const char *s);
extern char *strcend(const char *, pchar);
-extern char *strfield(char *src,int fields,int chars,int blanks,
- int tabch);
extern char *strfill(char * s,size_t len,pchar fill);
-extern size_t strinstr(const char *str,const char *search);
-extern size_t r_strinstr(const char *str, size_t from, const char *search);
-extern char *strkey(char *dst,char *head,char *tail,char *flags);
extern char *strmake(char *dst,const char *src,size_t length);
#ifndef strmov
@@ -137,45 +108,55 @@ extern char *strmov(char *dst,const char *src);
#else
extern char *strmov_overlapp(char *dst,const char *src);
#endif
-extern char *strnmov(char *dst,const char *src,size_t n);
-extern char *strsuff(const char *src,const char *suffix);
-extern char *strcont(const char *src,const char *set);
-extern char *strxcat _VARARGS((char *dst,const char *src, ...));
-extern char *strxmov _VARARGS((char *dst,const char *src, ...));
-extern char *strxcpy _VARARGS((char *dst,const char *src, ...));
-extern char *strxncat _VARARGS((char *dst,size_t len, const char *src, ...));
-extern char *strxnmov _VARARGS((char *dst,size_t len, const char *src, ...));
-extern char *strxncpy _VARARGS((char *dst,size_t len, const char *src, ...));
+extern char *strnmov(char *dst, const char *src, size_t n);
+extern char *strcont(const char *src, const char *set);
+extern char *strxmov(char *dst, const char *src, ...);
+extern char *strxnmov(char *dst, size_t len, const char *src, ...);
/* Prototypes of normal stringfunctions (with may ours) */
-
-#ifdef WANT_STRING_PROTOTYPES
-extern char *strcat(char *, const char *);
-extern char *strchr(const char *, pchar);
-extern char *strrchr(const char *, pchar);
-extern char *strcpy(char *, const char *);
-extern int strcmp(const char *, const char *);
-#ifndef __GNUC__
-extern size_t strlen(const char *);
-#endif
-#endif
#ifndef HAVE_STRNLEN
extern size_t strnlen(const char *s, size_t n);
#endif
-#if !defined(__cplusplus)
-#ifndef HAVE_STRPBRK
-extern char *strpbrk(const char *, const char *);
-#endif
-#ifndef HAVE_STRSTR
-extern char *strstr(const char *, const char *);
-#endif
-#endif
extern int is_prefix(const char *, const char *);
/* Conversion routines */
+typedef enum {
+ MY_GCVT_ARG_FLOAT,
+ MY_GCVT_ARG_DOUBLE
+} my_gcvt_arg_type;
+
double my_strtod(const char *str, char **end, int *error);
double my_atof(const char *nptr);
+size_t my_fcvt(double x, int precision, char *to, my_bool *error);
+size_t my_gcvt(double x, my_gcvt_arg_type type, int width, char *to,
+ my_bool *error);
+
+#define NOT_FIXED_DEC 31
+
+/*
+ The longest string my_fcvt can return is 311 + "precision" bytes.
+ Here we assume that we never cal my_fcvt() with precision >= NOT_FIXED_DEC
+ (+ 1 byte for the terminating '\0').
+*/
+#define FLOATING_POINT_BUFFER (311 + NOT_FIXED_DEC)
+
+/*
+ We want to use the 'e' format in some cases even if we have enough space
+ for the 'f' one just to mimic sprintf("%.15g") behavior for large integers,
+ and to improve it for numbers < 10^(-4).
+ That is, for |x| < 1 we require |x| >= 10^(-15), and for |x| > 1 we require
+ it to be integer and be <= 10^DBL_DIG for the 'f' format to be used.
+ We don't lose precision, but make cases like "1e200" or "0.00001" look nicer.
+*/
+#define MAX_DECPT_FOR_F_FORMAT DBL_DIG
+
+/*
+ The maximum possible field width for my_gcvt() conversion.
+ (DBL_DIG + 2) significant digits + sign + "." + ("e-NNN" or
+ MAX_DECPT_FOR_F_FORMAT zeros for cases when |x|<1 and the 'f' format is used).
+*/
+#define MY_GCVT_MAX_FIELD_WIDTH (DBL_DIG + 4 + max(5, MAX_DECPT_FOR_F_FORMAT)) \
extern char *llstr(longlong value,char *buff);
extern char *ullstr(longlong value,char *buff);
@@ -190,7 +171,7 @@ extern char *str2int(const char *src,int radix,long lower,long upper,
long *val);
longlong my_strtoll10(const char *nptr, char **endptr, int *error);
#if SIZEOF_LONG == SIZEOF_LONG_LONG
-#define longlong2str(A,B,C) int2str((A),(B),(C),1)
+#define ll2str(A,B,C,D) int2str((A),(B),(C),(D))
#define longlong10_to_str(A,B,C) int10_to_str((A),(B),(C))
#undef strtoll
#define strtoll(A,B,C) strtol((A),(B),(C))
@@ -203,7 +184,7 @@ longlong my_strtoll10(const char *nptr, char **endptr, int *error);
#endif
#else
#ifdef HAVE_LONG_LONG
-extern char *longlong2str(longlong val,char *dst,int radix);
+extern char *ll2str(longlong val,char *dst,int radix, int upcase);
extern char *longlong10_to_str(longlong val,char *dst,int radix);
#if (!defined(HAVE_STRTOULL) || defined(NO_STRTOLL_PROTO))
extern longlong strtoll(const char *str, char **ptr, int base);
@@ -211,13 +192,7 @@ extern ulonglong strtoull(const char *str, char **ptr, int base);
#endif
#endif
#endif
-
-/* my_vsnprintf.c */
-
-extern size_t my_vsnprintf(char *str, size_t n,
- const char *format, va_list ap);
-extern size_t my_snprintf(char *to, size_t n, const char *fmt, ...)
- ATTRIBUTE_FORMAT(printf, 3, 4);
+#define longlong2str(A,B,C) ll2str((A),(B),(C),1)
#if defined(__cplusplus)
}
@@ -225,20 +200,96 @@ extern size_t my_snprintf(char *to, size_t n, const char *fmt, ...)
/*
LEX_STRING -- a pair of a C-string and its length.
+ (it's part of the plugin API as a MYSQL_LEX_STRING)
*/
-#ifndef _my_plugin_h
-/* This definition must match the one given in mysql/plugin.h */
-struct st_mysql_lex_string
-{
- char *str;
- size_t length;
-};
-#endif
+#include <mysql/plugin.h>
typedef struct st_mysql_lex_string LEX_STRING;
#define STRING_WITH_LEN(X) (X), ((size_t) (sizeof(X) - 1))
#define USTRING_WITH_LEN(X) ((uchar*) X), ((size_t) (sizeof(X) - 1))
#define C_STRING_WITH_LEN(X) ((char *) (X)), ((size_t) (sizeof(X) - 1))
+struct st_mysql_const_lex_string
+{
+ const char *str;
+ size_t length;
+};
+typedef struct st_mysql_const_lex_string LEX_CSTRING;
+
+/* SPACE_INT is a word that contains only spaces */
+#if SIZEOF_INT == 4
+#define SPACE_INT 0x20202020
+#elif SIZEOF_INT == 8
+#define SPACE_INT 0x2020202020202020
+#else
+#error define the appropriate constant for a word full of spaces
+#endif
+
+/**
+ Skip trailing space.
+
+ On most systems reading memory in larger chunks (ideally equal to the size of
+ the chinks that the machine physically reads from memory) causes fewer memory
+ access loops and hence increased performance.
+ This is why the 'int' type is used : it's closest to that (according to how
+ it's defined in C).
+ So when we determine the amount of whitespace at the end of a string we do
+ the following :
+ 1. We divide the string into 3 zones :
+ a) from the start of the string (__start) to the first multiple
+ of sizeof(int) (__start_words)
+ b) from the end of the string (__end) to the last multiple of sizeof(int)
+ (__end_words)
+ c) a zone that is aligned to sizeof(int) and can be safely accessed
+ through an int *
+ 2. We start comparing backwards from (c) char-by-char. If all we find is
+ space then we continue
+ 3. If there are elements in zone (b) we compare them as unsigned ints to a
+ int mask (SPACE_INT) consisting of all spaces
+ 4. Finally we compare the remaining part (a) of the string char by char.
+ This covers for the last non-space unsigned int from 3. (if any)
+
+ This algorithm works well for relatively larger strings, but it will slow
+ the things down for smaller strings (because of the additional calculations
+ and checks compared to the naive method). Thus the barrier of length 20
+ is added.
+
+ @param ptr pointer to the input string
+ @param len the length of the string
+ @return the last non-space character
+*/
+
+static inline const uchar *skip_trailing_space(const uchar *ptr,size_t len)
+{
+ const uchar *end= ptr + len;
+
+ if (len > 20)
+ {
+ const uchar *end_words= (const uchar *)(intptr)
+ (((ulonglong)(intptr)end) / SIZEOF_INT * SIZEOF_INT);
+ const uchar *start_words= (const uchar *)(intptr)
+ ((((ulonglong)(intptr)ptr) + SIZEOF_INT - 1) / SIZEOF_INT * SIZEOF_INT);
+
+ DBUG_ASSERT(((ulonglong)(intptr)ptr) >= SIZEOF_INT);
+ if (end_words > ptr)
+ {
+ while (end > end_words && end[-1] == 0x20)
+ end--;
+ if (end[-1] == 0x20 && start_words < end_words)
+ while (end > start_words && ((unsigned *)end)[-1] == SPACE_INT)
+ end -= SIZEOF_INT;
+ }
+ }
+ while (end > ptr && end[-1] == 0x20)
+ end--;
+ return (end);
+}
+
+static inline void lex_string_set(LEX_STRING *lex_str, const char *c_str)
+{
+ lex_str->str= (char *) c_str;
+ lex_str->length= strlen(c_str);
+}
+
#endif
diff --git a/include/my_aes.h b/include/my_aes.h
index 1bbdf5663ea..2e2a66b4968 100644
--- a/include/my_aes.h
+++ b/include/my_aes.h
@@ -1,3 +1,6 @@
+#ifndef MY_AES_INCLUDED
+#define MY_AES_INCLUDED
+
/* Copyright (C) 2002 MySQL AB
This program is free software; you can redistribute it and/or modify
@@ -63,3 +66,5 @@ int my_aes_decrypt(const char *source, int source_length, char *dest,
int my_aes_get_size(int source_length);
C_MODE_END
+
+#endif /* MY_AES_INCLUDED */
diff --git a/include/my_alarm.h b/include/my_alarm.h
index c41c1d65e27..fa396cf02f9 100644
--- a/include/my_alarm.h
+++ b/include/my_alarm.h
@@ -33,15 +33,15 @@ extern ulong my_time_to_wait_for_lock;
#define ALARM_INIT my_have_got_alarm=0 ; \
alarm_old=(uint) alarm(MY_HOW_OFTEN_TO_ALARM); \
alarm_signal=signal(SIGALRM,my_set_alarm_variable);
-#define ALARM_END VOID(signal(SIGALRM,alarm_signal)); \
- VOID(alarm(alarm_old));
+#define ALARM_END (void) signal(SIGALRM,alarm_signal); \
+ (void) alarm(alarm_old);
#define ALARM_TEST my_have_got_alarm
#ifdef SIGNAL_HANDLER_RESET_ON_DELIVERY
-#define ALARM_REINIT VOID(alarm(MY_HOW_OFTEN_TO_ALARM)); \
- VOID(signal(SIGALRM,my_set_alarm_variable));\
+#define ALARM_REINIT (void) alarm(MY_HOW_OFTEN_TO_ALARM); \
+ (void) signal(SIGALRM,my_set_alarm_variable);\
my_have_got_alarm=0;
#else
-#define ALARM_REINIT VOID(alarm((uint) MY_HOW_OFTEN_TO_ALARM)); \
+#define ALARM_REINIT (void) alarm((uint) MY_HOW_OFTEN_TO_ALARM); \
my_have_got_alarm=0;
#endif /* SIGNAL_HANDLER_RESET_ON_DELIVERY */
#else
diff --git a/include/my_alloc.h b/include/my_alloc.h
index 93b7438a1df..4b1ffd3d444 100644
--- a/include/my_alloc.h
+++ b/include/my_alloc.h
@@ -23,6 +23,10 @@
#define ALLOC_MAX_BLOCK_TO_DROP 4096
#define ALLOC_MAX_BLOCK_USAGE_BEFORE_DROP 10
+#ifdef __cplusplus
+extern "C" {
+#endif
+
typedef struct st_used_mem
{ /* struct for once_alloc (block) */
struct st_used_mem *next; /* Next block in use */
@@ -48,4 +52,9 @@ typedef struct st_mem_root
void (*error_handler)(void);
} MEM_ROOT;
+
+#ifdef __cplusplus
+}
+#endif
+
#endif
diff --git a/include/my_atomic.h b/include/my_atomic.h
new file mode 100644
index 00000000000..c2d514012d9
--- /dev/null
+++ b/include/my_atomic.h
@@ -0,0 +1,287 @@
+#ifndef MY_ATOMIC_INCLUDED
+#define MY_ATOMIC_INCLUDED
+
+/* Copyright (C) 2006 MySQL AB
+
+ 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 */
+
+/*
+ This header defines five atomic operations:
+
+ my_atomic_add#(&var, what)
+ 'Fetch and Add'
+ add 'what' to *var, and return the old value of *var
+
+ my_atomic_fas#(&var, what)
+ 'Fetch And Store'
+ store 'what' in *var, and return the old value of *var
+
+ my_atomic_cas#(&var, &old, new)
+ An odd variation of 'Compare And Set/Swap'
+ if *var is equal to *old, then store 'new' in *var, and return TRUE
+ otherwise store *var in *old, and return FALSE
+ Usually, &old should not be accessed if the operation is successful.
+
+ my_atomic_load#(&var)
+ return *var
+
+ my_atomic_store#(&var, what)
+ store 'what' in *var
+
+ '#' is substituted by a size suffix - 8, 16, 32, 64, or ptr
+ (e.g. my_atomic_add8, my_atomic_fas32, my_atomic_casptr).
+
+ NOTE This operations are not always atomic, so they always must be
+ enclosed in my_atomic_rwlock_rdlock(lock)/my_atomic_rwlock_rdunlock(lock)
+ or my_atomic_rwlock_wrlock(lock)/my_atomic_rwlock_wrunlock(lock).
+ Hint: if a code block makes intensive use of atomic ops, it make sense
+ to take/release rwlock once for the whole block, not for every statement.
+
+ On architectures where these operations are really atomic, rwlocks will
+ be optimized away.
+ 8- and 16-bit atomics aren't implemented for windows (see generic-msvc.h),
+ but can be added, if necessary.
+*/
+
+#ifndef my_atomic_rwlock_init
+
+#define intptr void *
+/**
+ Currently we don't support 8-bit and 16-bit operations.
+ It can be added later if needed.
+*/
+#undef MY_ATOMIC_HAS_8_16
+
+#ifndef MY_ATOMIC_MODE_RWLOCKS
+/*
+ * Attempt to do atomic ops without locks
+ */
+#include "atomic/nolock.h"
+#endif
+
+#ifndef make_atomic_cas_body
+/* nolock.h was not able to generate even a CAS function, fall back */
+#include "atomic/rwlock.h"
+#endif
+
+/* define missing functions by using the already generated ones */
+#ifndef make_atomic_add_body
+#define make_atomic_add_body(S) \
+ int ## S tmp=*a; \
+ while (!my_atomic_cas ## S(a, &tmp, tmp+v)) ; \
+ v=tmp;
+#endif
+#ifndef make_atomic_fas_body
+#define make_atomic_fas_body(S) \
+ int ## S tmp=*a; \
+ while (!my_atomic_cas ## S(a, &tmp, v)) ; \
+ v=tmp;
+#endif
+#ifndef make_atomic_load_body
+#define make_atomic_load_body(S) \
+ ret= 0; /* avoid compiler warning */ \
+ (void)(my_atomic_cas ## S(a, &ret, ret));
+#endif
+#ifndef make_atomic_store_body
+#define make_atomic_store_body(S) \
+ (void)(my_atomic_fas ## S (a, v));
+#endif
+
+/*
+ transparent_union doesn't work in g++
+ Bug ?
+
+ Darwin's gcc doesn't want to put pointers in a transparent_union
+ when built with -arch ppc64. Complains:
+ warning: 'transparent_union' attribute ignored
+*/
+#if defined(__GNUC__) && !defined(__cplusplus) && \
+ ! (defined(__APPLE__) && (defined(_ARCH_PPC64) ||defined (_ARCH_PPC)))
+/*
+ we want to be able to use my_atomic_xxx functions with
+ both signed and unsigned integers. But gcc will issue a warning
+ "passing arg N of `my_atomic_XXX' as [un]signed due to prototype"
+ if the signedness of the argument doesn't match the prototype, or
+ "pointer targets in passing argument N of my_atomic_XXX differ in signedness"
+ if int* is used where uint* is expected (or vice versa).
+ Let's shut these warnings up
+*/
+#define make_transparent_unions(S) \
+ typedef union { \
+ int ## S i; \
+ uint ## S u; \
+ } U_ ## S __attribute__ ((transparent_union)); \
+ typedef union { \
+ int ## S volatile *i; \
+ uint ## S volatile *u; \
+ } Uv_ ## S __attribute__ ((transparent_union));
+#define uintptr intptr
+make_transparent_unions(8)
+make_transparent_unions(16)
+make_transparent_unions(32)
+make_transparent_unions(64)
+make_transparent_unions(ptr)
+#undef uintptr
+#undef make_transparent_unions
+#define a U_a.i
+#define cmp U_cmp.i
+#define v U_v.i
+#define set U_set.i
+#else
+#define U_8 int8
+#define U_16 int16
+#define U_32 int32
+#define U_64 int64
+#define U_ptr intptr
+#define Uv_8 int8
+#define Uv_16 int16
+#define Uv_32 int32
+#define Uv_64 int64
+#define Uv_ptr intptr
+#define U_a volatile *a
+#define U_cmp *cmp
+#define U_v v
+#define U_set set
+#endif /* __GCC__ transparent_union magic */
+
+#define make_atomic_cas(S) \
+static inline int my_atomic_cas ## S(Uv_ ## S U_a, \
+ Uv_ ## S U_cmp, U_ ## S U_set) \
+{ \
+ int8 ret; \
+ make_atomic_cas_body(S); \
+ return ret; \
+}
+
+#define make_atomic_add(S) \
+static inline int ## S my_atomic_add ## S( \
+ Uv_ ## S U_a, U_ ## S U_v) \
+{ \
+ make_atomic_add_body(S); \
+ return v; \
+}
+
+#define make_atomic_fas(S) \
+static inline int ## S my_atomic_fas ## S( \
+ Uv_ ## S U_a, U_ ## S U_v) \
+{ \
+ make_atomic_fas_body(S); \
+ return v; \
+}
+
+#define make_atomic_load(S) \
+static inline int ## S my_atomic_load ## S(Uv_ ## S U_a) \
+{ \
+ int ## S ret; \
+ make_atomic_load_body(S); \
+ return ret; \
+}
+
+#define make_atomic_store(S) \
+static inline void my_atomic_store ## S( \
+ Uv_ ## S U_a, U_ ## S U_v) \
+{ \
+ make_atomic_store_body(S); \
+}
+
+#ifdef MY_ATOMIC_HAS_8_16
+make_atomic_cas(8)
+make_atomic_cas(16)
+#endif
+make_atomic_cas(32)
+make_atomic_cas(64)
+make_atomic_cas(ptr)
+
+#ifdef MY_ATOMIC_HAS_8_16
+make_atomic_add(8)
+make_atomic_add(16)
+#endif
+make_atomic_add(32)
+make_atomic_add(64)
+
+#ifdef MY_ATOMIC_HAS_8_16
+make_atomic_load(8)
+make_atomic_load(16)
+#endif
+make_atomic_load(32)
+make_atomic_load(64)
+make_atomic_load(ptr)
+
+#ifdef MY_ATOMIC_HAS_8_16
+make_atomic_fas(8)
+make_atomic_fas(16)
+#endif
+make_atomic_fas(32)
+make_atomic_fas(64)
+make_atomic_fas(ptr)
+
+#ifdef MY_ATOMIC_HAS_8_16
+make_atomic_store(8)
+make_atomic_store(16)
+#endif
+make_atomic_store(32)
+make_atomic_store(64)
+make_atomic_store(ptr)
+
+#ifdef _atomic_h_cleanup_
+#include _atomic_h_cleanup_
+#undef _atomic_h_cleanup_
+#endif
+
+#undef U_8
+#undef U_16
+#undef U_32
+#undef U_64
+#undef U_ptr
+#undef Uv_8
+#undef Uv_16
+#undef Uv_32
+#undef Uv_64
+#undef Uv_ptr
+#undef a
+#undef cmp
+#undef v
+#undef set
+#undef U_a
+#undef U_cmp
+#undef U_v
+#undef U_set
+#undef make_atomic_add
+#undef make_atomic_cas
+#undef make_atomic_load
+#undef make_atomic_store
+#undef make_atomic_fas
+#undef make_atomic_add_body
+#undef make_atomic_cas_body
+#undef make_atomic_load_body
+#undef make_atomic_store_body
+#undef make_atomic_fas_body
+#undef intptr
+
+/*
+ the macro below defines (as an expression) the code that
+ will be run in spin-loops. Intel manuals recummend to have PAUSE there.
+ It is expected to be defined in include/atomic/ *.h files
+*/
+#ifndef LF_BACKOFF
+#define LF_BACKOFF (1)
+#endif
+
+#define MY_ATOMIC_OK 0
+#define MY_ATOMIC_NOT_1CPU 1
+extern int my_atomic_initialize();
+
+#endif
+
+#endif /* MY_ATOMIC_INCLUDED */
diff --git a/include/my_attribute.h b/include/my_attribute.h
index 8309d85f20a..d35b3013bdd 100644
--- a/include/my_attribute.h
+++ b/include/my_attribute.h
@@ -21,6 +21,12 @@
#ifndef _my_attribute_h
#define _my_attribute_h
+#if defined(__GNUC__)
+# ifndef GCC_VERSION
+# define GCC_VERSION (__GNUC__ * 1000 + __GNUC_MINOR__)
+# endif
+#endif
+
/*
Disable __attribute__() on gcc < 2.7, g++ < 3.4, and non-gcc compilers.
Some forms of __attribute__ are actually supported in earlier versions of
diff --git a/include/my_base.h b/include/my_base.h
index a01b2ec9b82..28dc55b1b84 100644
--- a/include/my_base.h
+++ b/include/my_base.h
@@ -191,10 +191,11 @@ enum ha_extra_function {
/* Inform handler that we will do a rename */
HA_EXTRA_PREPARE_FOR_RENAME,
/*
- Orders MERGE handler to attach or detach its child tables. Used at
- begin and end of a statement.
+ Special actions for MERGE tables.
*/
+ HA_EXTRA_ADD_CHILDREN_LIST,
HA_EXTRA_ATTACH_CHILDREN,
+ HA_EXTRA_IS_ATTACHED_CHILDREN,
HA_EXTRA_DETACH_CHILDREN
};
@@ -255,27 +256,27 @@ enum ha_base_keytype {
HA_BINARY_PACK_KEY | HA_FULLTEXT | HA_UNIQUE_CHECK | \
HA_SPATIAL | HA_NULL_ARE_EQUAL | HA_GENERATED_KEY)
-#define HA_KEY_HAS_PART_KEY_SEG 65536 /* Key contains partial segments */
+/*
+ Key contains partial segments.
+
+ This flag is internal to the MySQL server by design. It is not supposed
+ neither to be saved in FRM-files, nor to be passed to storage engines.
+ It is intended to pass information into internal static sort_keys(KEY *,
+ KEY *) function.
+
+ This flag can be calculated -- it's based on key lengths comparison.
+*/
+#define HA_KEY_HAS_PART_KEY_SEG 65536
/* Automatic bits in key-flag */
#define HA_SPACE_PACK_USED 4 /* Test for if SPACE_PACK used */
#define HA_VAR_LENGTH_KEY 8
#define HA_NULL_PART_KEY 64
+#define HA_USES_COMMENT 4096
#define HA_USES_PARSER 16384 /* Fulltext index uses [pre]parser */
#define HA_USES_BLOCK_SIZE ((uint) 32768)
#define HA_SORT_ALLOWS_SAME 512 /* Intern bit when sorting records */
-#if MYSQL_VERSION_ID < 0x50200
-/*
- Key has a part that can have end space. If this is an unique key
- we have to handle it differently from other unique keys as we can find
- many matching rows for one key (because end space are not compared)
-*/
-#define HA_END_SPACE_KEY 0 /* was: 4096 */
-#else
-#error HA_END_SPACE_KEY is obsolete, please remove it
-#endif
-
/* These flags can be added to key-seg-flag */
@@ -561,6 +562,8 @@ typedef ulong ha_rows;
#define HA_VARCHAR_PACKLENGTH(field_length) ((field_length) < 256 ? 1 :2)
/* invalidator function reference for Query Cache */
+C_MODE_START
typedef void (* invalidator_by_filename)(const char * filename);
+C_MODE_END
#endif /* _my_base_h */
diff --git a/include/my_bit.h b/include/my_bit.h
index 2e464e89049..b396b84b0d8 100644
--- a/include/my_bit.h
+++ b/include/my_bit.h
@@ -1,9 +1,11 @@
+#ifndef MY_BIT_INCLUDED
+#define MY_BIT_INCLUDED
+
/*
Some useful bit functions
*/
C_MODE_START
-#ifdef HAVE_INLINE
extern const char _my_bits_nbits[256];
extern const uchar _my_bits_reverse_table[256];
@@ -13,14 +15,14 @@ extern const uchar _my_bits_reverse_table[256];
This can be used to divide a number with value by doing a shift instead
*/
-STATIC_INLINE uint my_bit_log2(ulong value)
+static inline uint my_bit_log2(ulong value)
{
uint bit;
for (bit=0 ; value > 1 ; value>>=1, bit++) ;
return bit;
}
-STATIC_INLINE uint my_count_bits(ulonglong v)
+static inline uint my_count_bits(ulonglong v)
{
#if SIZEOF_LONG_LONG > 4
/* The following code is a bit faster on 16 bit machines than if we would
@@ -42,7 +44,7 @@ STATIC_INLINE uint my_count_bits(ulonglong v)
#endif
}
-STATIC_INLINE uint my_count_bits_ushort(ushort v)
+static inline uint my_count_bits_ushort(ushort v)
{
return _my_bits_nbits[v];
}
@@ -67,7 +69,7 @@ STATIC_INLINE uint my_count_bits_ushort(ushort v)
Comments shows how this works with 01100000000000000000000000001011
*/
-STATIC_INLINE uint32 my_round_up_to_next_power(uint32 v)
+static inline uint32 my_round_up_to_next_power(uint32 v)
{
v--; /* 01100000000000000000000000001010 */
v|= v >> 1; /* 01110000000000000000000000001111 */
@@ -78,7 +80,7 @@ STATIC_INLINE uint32 my_round_up_to_next_power(uint32 v)
return v+1; /* 10000000000000000000000000000000 */
}
-STATIC_INLINE uint32 my_clear_highest_bit(uint32 v)
+static inline uint32 my_clear_highest_bit(uint32 v)
{
uint32 w=v >> 1;
w|= w >> 1;
@@ -89,7 +91,7 @@ STATIC_INLINE uint32 my_clear_highest_bit(uint32 v)
return v & w;
}
-STATIC_INLINE uint32 my_reverse_bits(uint32 key)
+static inline uint32 my_reverse_bits(uint32 key)
{
return
(_my_bits_reverse_table[ key & 255] << 24) |
@@ -98,12 +100,6 @@ STATIC_INLINE uint32 my_reverse_bits(uint32 key)
_my_bits_reverse_table[(key>>24) ];
}
-#else /* HAVE_INLINE */
-extern uint my_bit_log2(ulong value);
-extern uint32 my_round_up_to_next_power(uint32 v);
-uint32 my_clear_highest_bit(uint32 v);
-uint32 my_reverse_bits(uint32 key);
-extern uint my_count_bits(ulonglong v);
-extern uint my_count_bits_ushort(ushort v);
-#endif /* HAVE_INLINE */
C_MODE_END
+
+#endif /* MY_BIT_INCLUDED */
diff --git a/include/my_bitmap.h b/include/my_bitmap.h
index ab69b2d671d..548eec14d6e 100644
--- a/include/my_bitmap.h
+++ b/include/my_bitmap.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000 MySQL AB
+/* Copyright (C) 2000 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
@@ -34,7 +34,7 @@ typedef struct st_bitmap
acquiring the mutex
*/
#ifdef THREAD
- pthread_mutex_t *mutex;
+ mysql_mutex_t *mutex;
#endif
} MY_BITMAP;
@@ -69,28 +69,6 @@ extern void bitmap_copy(MY_BITMAP *map, const MY_BITMAP *map2);
extern uint bitmap_lock_set_next(MY_BITMAP *map);
extern void bitmap_lock_clear_bit(MY_BITMAP *map, uint bitmap_bit);
-#ifdef NOT_USED
-extern uint bitmap_lock_bits_set(const MY_BITMAP *map);
-extern my_bool bitmap_lock_is_set_all(const MY_BITMAP *map);
-extern uint bitmap_lock_get_first(const MY_BITMAP *map);
-extern uint bitmap_lock_get_first_set(const MY_BITMAP *map);
-extern my_bool bitmap_lock_is_subset(const MY_BITMAP *map1,
- const MY_BITMAP *map2);
-extern my_bool bitmap_lock_is_prefix(const MY_BITMAP *map, uint prefix_size);
-extern my_bool bitmap_lock_is_set(const MY_BITMAP *map, uint bitmap_bit);
-extern my_bool bitmap_lock_is_clear_all(const MY_BITMAP *map);
-extern my_bool bitmap_lock_cmp(const MY_BITMAP *map1, const MY_BITMAP *map2);
-extern void bitmap_lock_set_all(MY_BITMAP *map);
-extern void bitmap_lock_clear_all(MY_BITMAP *map);
-extern void bitmap_lock_set_bit(MY_BITMAP *map, uint bitmap_bit);
-extern void bitmap_lock_flip_bit(MY_BITMAP *map, uint bitmap_bit);
-extern void bitmap_lock_set_prefix(MY_BITMAP *map, uint prefix_size);
-extern void bitmap_lock_intersect(MY_BITMAP *map, const MY_BITMAP *map2);
-extern void bitmap_lock_subtract(MY_BITMAP *map, const MY_BITMAP *map2);
-extern void bitmap_lock_union(MY_BITMAP *map, const MY_BITMAP *map2);
-extern void bitmap_lock_xor(MY_BITMAP *map, const MY_BITMAP *map2);
-extern void bitmap_lock_invert(MY_BITMAP *map);
-#endif
/* Fast, not thread safe, bitmap functions */
#define bitmap_buffer_size(bits) (((bits)+31)/32)*4
#define no_bytes_in_map(map) (((map)->n_bits + 7)/8)
diff --git a/include/my_dbug.h b/include/my_dbug.h
index f08e94a1882..e1cb3252601 100644
--- a/include/my_dbug.h
+++ b/include/my_dbug.h
@@ -26,102 +26,64 @@
#include <signal.h>
#endif /* not __WIN__ */
-#if defined(__cplusplus) && !defined(DBUG_OFF)
-class Dbug_violation_helper
-{
-public:
- inline Dbug_violation_helper() :
- _entered(TRUE)
- { }
-
- inline ~Dbug_violation_helper()
- {
- assert(!_entered);
- }
-
- inline void leave()
- {
- _entered= FALSE;
- }
-
-private:
- bool _entered;
-};
-#endif /* C++ */
-
-#ifdef __cplusplus
+#ifdef __cplusplus
extern "C" {
#endif
#if !defined(DBUG_OFF) && !defined(_lint)
-struct _db_code_state_;
-extern int _db_keyword_(struct _db_code_state_ *cs, const char *keyword);
-extern int _db_strict_keyword_(const char *keyword);
+
+struct _db_stack_frame_ {
+ const char *func; /* function name of the previous stack frame */
+ const char *file; /* filename of the function of previous frame */
+ uint level; /* this nesting level, highest bit enables tracing */
+ struct _db_stack_frame_ *prev; /* pointer to the previous frame */
+};
+
+struct _db_code_state_;
+extern my_bool _dbug_on_;
+extern my_bool _db_keyword_(struct _db_code_state_ *, const char *, int);
extern int _db_explain_(struct _db_code_state_ *cs, char *buf, size_t len);
extern int _db_explain_init_(char *buf, size_t len);
-extern void _db_setjmp_(void);
-extern void _db_longjmp_(void);
+extern int _db_is_pushed_(void);
+extern void _db_setjmp_(void);
+extern void _db_longjmp_(void);
extern void _db_process_(const char *name);
-extern void _db_push_(const char *control);
-extern void _db_pop_(void);
-extern void _db_set_(struct _db_code_state_ *cs, const char *control);
+extern void _db_push_(const char *control);
+extern void _db_pop_(void);
+extern void _db_set_(const char *control);
extern void _db_set_init_(const char *control);
-extern void _db_enter_(const char *_func_,const char *_file_,uint _line_,
- const char **_sfunc_,const char **_sfile_,
- uint *_slevel_, char ***);
-extern void _db_return_(uint _line_,const char **_sfunc_,const char **_sfile_,
- uint *_slevel_);
-extern void _db_pargs_(uint _line_,const char *keyword);
-extern void _db_doprnt_ _VARARGS((const char *format,...))
+extern void _db_enter_(const char *_func_, const char *_file_, uint _line_,
+ struct _db_stack_frame_ *_stack_frame_);
+extern void _db_return_(uint _line_, struct _db_stack_frame_ *_stack_frame_);
+extern void _db_pargs_(uint _line_,const char *keyword);
+extern void _db_doprnt_(const char *format,...)
ATTRIBUTE_FORMAT(printf, 1, 2);
-extern void _db_dump_(uint _line_,const char *keyword,
+extern void _db_dump_(uint _line_,const char *keyword,
const unsigned char *memory, size_t length);
-extern void _db_end_(void);
-extern void _db_lock_file_(void);
-extern void _db_unlock_file_(void);
-extern FILE *_db_fp_(void);
+extern void _db_end_(void);
+extern void _db_lock_file_(void);
+extern void _db_unlock_file_(void);
+extern FILE *_db_fp_(void);
extern void _db_flush_();
+extern const char* _db_get_func_(void);
-#ifdef __cplusplus
-
-#define DBUG_ENTER(a) \
- const char *_db_func_, *_db_file_; \
- uint _db_level_; \
- char **_db_framep_; \
- Dbug_violation_helper dbug_violation_helper; \
- _db_enter_ (a, __FILE__, __LINE__, &_db_func_, &_db_file_, \
- &_db_level_, &_db_framep_)
-#define DBUG_VIOLATION_HELPER_LEAVE dbug_violation_helper.leave()
-
-#else /* C */
-
-#define DBUG_ENTER(a) \
- const char *_db_func_, *_db_file_; \
- uint _db_level_; \
- char **_db_framep_; \
- _db_enter_ (a, __FILE__, __LINE__, &_db_func_, &_db_file_, \
- &_db_level_, &_db_framep_)
-#define DBUG_VIOLATION_HELPER_LEAVE do { } while(0)
-
-#endif /* C++ */
-
-#define DBUG_LEAVE \
- DBUG_VIOLATION_HELPER_LEAVE; \
- _db_return_ (__LINE__, &_db_func_, &_db_file_, &_db_level_)
+#define DBUG_ENTER(a) struct _db_stack_frame_ _db_stack_frame_; \
+ _db_enter_ (a,__FILE__,__LINE__,&_db_stack_frame_)
+#define DBUG_LEAVE _db_return_ (__LINE__, &_db_stack_frame_)
#define DBUG_RETURN(a1) do {DBUG_LEAVE; return(a1);} while(0)
#define DBUG_VOID_RETURN do {DBUG_LEAVE; return;} while(0)
#define DBUG_EXECUTE(keyword,a1) \
- do {if (_db_keyword_(0, (keyword))) { a1 }} while(0)
+ do {if (_db_keyword_(0, (keyword), 0)) { a1 }} while(0)
#define DBUG_EXECUTE_IF(keyword,a1) \
- do {if (_db_strict_keyword_ (keyword)) { a1 } } while(0)
+ do {if (_db_keyword_(0, (keyword), 1)) { a1 }} while(0)
#define DBUG_EVALUATE(keyword,a1,a2) \
- (_db_keyword_(0,(keyword)) ? (a1) : (a2))
+ (_db_keyword_(0,(keyword), 0) ? (a1) : (a2))
#define DBUG_EVALUATE_IF(keyword,a1,a2) \
- (_db_strict_keyword_((keyword)) ? (a1) : (a2))
+ (_db_keyword_(0,(keyword), 1) ? (a1) : (a2))
#define DBUG_PRINT(keyword,arglist) \
do {_db_pargs_(__LINE__,keyword); _db_doprnt_ arglist;} while(0)
#define DBUG_PUSH(a1) _db_push_ (a1)
#define DBUG_POP() _db_pop_ ()
-#define DBUG_SET(a1) _db_set_ (0, (a1))
+#define DBUG_SET(a1) _db_set_ (a1)
#define DBUG_SET_INITIAL(a1) _db_set_init_ (a1)
#define DBUG_PROCESS(a1) _db_process_(a1)
#define DBUG_FILE _db_fp_()
@@ -134,7 +96,8 @@ extern void _db_flush_();
#define DBUG_ASSERT(A) assert(A)
#define DBUG_EXPLAIN(buf,len) _db_explain_(0, (buf),(len))
#define DBUG_EXPLAIN_INITIAL(buf,len) _db_explain_init_((buf),(len))
-#define IF_DBUG(A) A
+#define DEBUGGER_OFF do { _dbug_on_= 0; } while(0)
+#define DEBUGGER_ON do { _dbug_on_= 1; } while(0)
#ifndef __WIN__
#define DBUG_ABORT() (_db_flush_(), abort())
#else
@@ -148,6 +111,15 @@ extern void _db_flush_();
(void)_CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR),\
_exit(3))
#endif
+#define DBUG_CHECK_CRASH(func, op) \
+ do { char _dbuf_[255]; strxnmov(_dbuf_, sizeof(_dbuf_)-1, (func), (op)); \
+ DBUG_EXECUTE_IF(_dbuf_, DBUG_ABORT()); } while(0)
+#define DBUG_CRASH_ENTER(func) \
+ DBUG_ENTER(func); DBUG_CHECK_CRASH(func, "_crash_enter")
+#define DBUG_CRASH_RETURN(val) \
+ DBUG_CHECK_CRASH(_db_get_func_(), "_crash_return")
+#define DBUG_CRASH_VOID_RETURN \
+ DBUG_CHECK_CRASH (_db_get_func_(), "_crash_return")
/*
Make the program fail, without creating a core file.
@@ -163,38 +135,57 @@ extern void _db_flush_();
#define DBUG_SUICIDE() (_db_flush_(), kill(getpid(), SIGKILL), pause())
#endif
-#else /* No debugger */
+#else /* No debugger */
#define DBUG_ENTER(a1)
#define DBUG_LEAVE
-#define DBUG_VIOLATION_HELPER_LEAVE
-#define DBUG_RETURN(a1) do { return(a1); } while(0)
-#define DBUG_VOID_RETURN do { return; } while(0)
-#define DBUG_EXECUTE(keyword,a1) do { } while(0)
-#define DBUG_EXECUTE_IF(keyword,a1) do { } while(0)
+#define DBUG_RETURN(a1) do { return(a1); } while(0)
+#define DBUG_VOID_RETURN do { return; } while(0)
+#define DBUG_EXECUTE(keyword,a1) do { } while(0)
+#define DBUG_EXECUTE_IF(keyword,a1) do { } while(0)
#define DBUG_EVALUATE(keyword,a1,a2) (a2)
#define DBUG_EVALUATE_IF(keyword,a1,a2) (a2)
-#define DBUG_PRINT(keyword,arglist) do { } while(0)
-#define DBUG_PUSH(a1)
-#define DBUG_SET(a1) do { } while(0)
-#define DBUG_SET_INITIAL(a1) do { } while(0)
-#define DBUG_POP()
-#define DBUG_PROCESS(a1)
+#define DBUG_PRINT(keyword,arglist) do { } while(0)
+#define DBUG_PUSH(a1) do { } while(0)
+#define DBUG_SET(a1) do { } while(0)
+#define DBUG_SET_INITIAL(a1) do { } while(0)
+#define DBUG_POP() do { } while(0)
+#define DBUG_PROCESS(a1) do { } while(0)
#define DBUG_SETJMP(a1) setjmp(a1)
#define DBUG_LONGJMP(a1) longjmp(a1)
-#define DBUG_DUMP(keyword,a1,a2) do { } while(0)
-#define DBUG_END()
-#define DBUG_ASSERT(A) do { } while(0)
-#define DBUG_LOCK_FILE
+#define DBUG_DUMP(keyword,a1,a2) do { } while(0)
+#define DBUG_END() do { } while(0)
+#define DBUG_ASSERT(A) do { } while(0)
+#define DBUG_LOCK_FILE do { } while(0)
#define DBUG_FILE (stderr)
-#define DBUG_UNLOCK_FILE
+#define DBUG_UNLOCK_FILE do { } while(0)
#define DBUG_EXPLAIN(buf,len)
#define DBUG_EXPLAIN_INITIAL(buf,len)
-#define IF_DBUG(A)
+#define DEBUGGER_OFF do { } while(0)
+#define DEBUGGER_ON do { } while(0)
#define DBUG_ABORT() do { } while(0)
+#define DBUG_CRASH_ENTER(func)
+#define DBUG_CRASH_RETURN(val) do { return(val); } while(0)
+#define DBUG_CRASH_VOID_RETURN do { return; } while(0)
#define DBUG_SUICIDE() do { } while(0)
#endif
+
+#ifdef EXTRA_DEBUG
+/**
+ Sync points allow us to force the server to reach a certain line of code
+ and block there until the client tells the server it is ok to go on.
+ The client tells the server to block with SELECT GET_LOCK()
+ and unblocks it with SELECT RELEASE_LOCK(). Used for debugging difficult
+ concurrency problems
+*/
+#define DBUG_SYNC_POINT(lock_name,lock_timeout) \
+ debug_sync_point(lock_name,lock_timeout)
+void debug_sync_point(const char* lock_name, uint lock_timeout);
+#else
+#define DBUG_SYNC_POINT(lock_name,lock_timeout)
+#endif /* EXTRA_DEBUG */
+
#ifdef __cplusplus
}
#endif
diff --git a/include/my_dir.h b/include/my_dir.h
index 06509a3af19..de21bee7385 100644
--- a/include/my_dir.h
+++ b/include/my_dir.h
@@ -13,17 +13,17 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
-#ifndef _my_dir_h
-#define _my_dir_h
-#ifdef __cplusplus
-extern "C" {
-#endif
-
#ifndef MY_DIR_H
#define MY_DIR_H
+#include "my_global.h"
+
#include <sys/stat.h>
+#ifdef __cplusplus
+extern "C" {
+#endif
+
/* Defines for my_dir and my_stat */
#define MY_S_IFMT S_IFMT /* type of file */
@@ -69,7 +69,11 @@ typedef struct my_stat
#else
+#if(_MSC_VER)
+#define MY_STAT struct _stati64 /* 64 bit file size */
+#else
#define MY_STAT struct stat /* Orginal struct have what we need */
+#endif
#endif /* USE_MY_STAT_STRUCT */
@@ -97,9 +101,9 @@ extern void my_dirend(MY_DIR *buffer);
extern MY_STAT *my_stat(const char *path, MY_STAT *stat_area, myf my_flags);
extern int my_fstat(int filenr, MY_STAT *stat_area, myf MyFlags);
-#endif /* MY_DIR_H */
-
#ifdef __cplusplus
}
#endif
-#endif
+
+#endif /* MY_DIR_H */
+
diff --git a/include/my_getopt.h b/include/my_getopt.h
index d7c996302fd..47feb21d85e 100644
--- a/include/my_getopt.h
+++ b/include/my_getopt.h
@@ -16,6 +16,8 @@
#ifndef _my_getopt_h
#define _my_getopt_h
+#include "my_sys.h" /* loglevel */
+
C_MODE_START
#define GET_NO_ARG 1
@@ -32,32 +34,57 @@ C_MODE_START
#define GET_ENUM 12
#define GET_SET 13
#define GET_DOUBLE 14
+#define GET_FLAGSET 15
#define GET_ASK_ADDR 128
#define GET_TYPE_MASK 127
+/**
+ Enumeration of the my_option::arg_type attributes.
+ It should be noted that for historical reasons variables with the combination
+ arg_type=NO_ARG, my_option::var_type=GET_BOOL still accepts
+ arguments. This is someone counter intuitive and care should be taken
+ if the code is refactored.
+*/
enum get_opt_arg_type { NO_ARG, OPT_ARG, REQUIRED_ARG };
struct st_typelib;
struct my_option
{
- const char *name; /* Name of the option */
- int id; /* unique id or short option */
- const char *comment; /* option comment, for autom. --help */
- void *value; /* The variable value */
- void *u_max_value; /* The user def. max variable value */
- struct st_typelib *typelib; /* Pointer to possible values */
- ulong var_type; /* Must match the variable type */
- enum get_opt_arg_type arg_type;
- longlong def_value; /* Default value */
- longlong min_value; /* Min allowed value */
- longlong max_value; /* Max allowed value */
- longlong sub_size; /* Subtract this from given value */
- long block_size; /* Value should be a mult. of this */
- void *app_type; /* To be used by an application */
+ const char *name; /**< Name of the option. name=NULL
+ marks the end of the my_option[]
+ array.
+ */
+ int id; /**< For 0<id<255 it's means one
+ character for a short option
+ (like -A), if >255 no short option
+ is created, but a long option still
+ can be identified uniquely in the
+ my_get_one_option() callback.
+ If an opton needs neither special
+ treatment in the my_get_one_option()
+ nor one-letter short equivalent
+ use id=0
+ */
+ const char *comment; /**< option comment, for autom. --help.
+ if it's NULL the option is not
+ visible in --help.
+ */
+ void *value; /**< A pointer to the variable value */
+ void *u_max_value; /**< The user def. max variable value */
+ struct st_typelib *typelib; /**< Pointer to possible values */
+ ulong var_type; /**< GET_BOOL, GET_ULL, etc */
+ enum get_opt_arg_type arg_type; /**< e.g. REQUIRED_ARG or OPT_ARG */
+ longlong def_value; /**< Default value */
+ longlong min_value; /**< Min allowed value (for numbers) */
+ longlong max_value; /**< Max allowed value (for numbers) */
+ longlong sub_size; /**< Unused */
+ long block_size; /**< Value should be a mult. of this (for numbers) */
+ void *app_type; /**< To be used by an application */
};
+
typedef my_bool (*my_get_one_option)(int, const struct my_option *, char *);
typedef void (*my_error_reporter)(enum loglevel level, const char *format, ...);
/**
@@ -69,6 +96,7 @@ typedef void (*my_error_reporter)(enum loglevel level, const char *format, ...);
typedef void *(*my_getopt_value)(const char *, uint, const struct my_option *,
int *);
+
extern char *disabled_my_option;
extern my_bool my_getopt_print_errors;
extern my_bool my_getopt_skip_unknown;
@@ -85,6 +113,8 @@ ulonglong getopt_ull_limit_value(ulonglong num, const struct my_option *optp,
my_bool *fix);
longlong getopt_ll_limit_value(longlong, const struct my_option *,
my_bool *fix);
+double getopt_double_limit_value(double num, const struct my_option *optp,
+ my_bool *fix);
my_bool getopt_compare_strings(const char *s, const char *t, uint length);
C_MODE_END
diff --git a/include/my_global.h b/include/my_global.h
index ec22a57329b..8540c3f100e 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
@@ -18,6 +18,11 @@
#ifndef _global_h
#define _global_h
+/* Client library users on Windows need this macro defined here. */
+#if !defined(__WIN__) && defined(_WIN32)
+#define __WIN__
+#endif
+
/*
InnoDB depends on some MySQL internals which other plugins should not
need. This is because of InnoDB's foreign key support, "safe" binlog
@@ -41,15 +46,6 @@
#define HAVE_ERRNO_AS_DEFINE
#endif /* __CYGWIN__ */
-#if defined(__QNXNTO__) && !defined(FD_SETSIZE)
-#define FD_SETSIZE 1024 /* Max number of file descriptor bits in
- fd_set, used when calling 'select'
- Must be defined before including
- "sys/select.h" and "sys/time.h"
- */
-#endif
-
-
/* to make command line shorter we'll define USE_PRAGMA_INTERFACE here */
#ifdef USE_PRAGMA_IMPLEMENTATION
#define USE_PRAGMA_INTERFACE
@@ -72,26 +68,28 @@
#define C_MODE_END
#endif
-#if defined(_WIN32) || defined(_WIN64) || defined(__WIN32__) || defined(WIN32)
-#include <config-win.h>
-#elif defined(__NETWARE__)
-#include <my_config.h>
-#include <config-netware.h>
-#if defined(__cplusplus) && defined(inline)
-#undef inline /* fix configure problem */
+#ifdef __cplusplus
+#define CPP_UNNAMED_NS_START namespace {
+#define CPP_UNNAMED_NS_END }
#endif
-#else
+
#include <my_config.h>
-#if defined(__cplusplus) && defined(inline)
-#undef inline /* fix configure problem */
-#endif
-#endif /* _WIN32... */
-/* Make it easier to add conditionl code for windows */
+#ifdef WITH_PERFSCHEMA_STORAGE_ENGINE
+#define HAVE_PSI_INTERFACE
+#endif /* WITH_PERFSCHEMA_STORAGE_ENGINE */
+
+/* Make it easier to add conditional code in _expressions_ */
#ifdef __WIN__
-#define IF_WIN(A,B) (A)
+#define IF_WIN(A,B) A
#else
-#define IF_WIN(A,B) (B)
+#define IF_WIN(A,B) B
+#endif
+
+#ifdef HAVE_purify
+#define IF_PURIFY(A,B) A
+#else
+#define IF_PURIFY(A,B) B
#endif
#ifndef EMBEDDED_LIBRARY
@@ -105,12 +103,49 @@
#define HAVE_EXTERNAL_CLIENT
#endif
-/* Some defines to avoid ifdefs in the code */
-#ifndef NETWARE_YIELD
-#define NETWARE_YIELD
-#define NETWARE_SET_SCREEN_MODE(A)
+#if defined (_WIN32)
+/*
+ off_t is 32 bit long. We do not use C runtime functions
+ with off_t but native Win32 file IO APIs, that work with
+ 64 bit offsets.
+*/
+#undef SIZEOF_OFF_T
+#define SIZEOF_OFF_T 8
+
+/*
+ Prevent inclusion of Windows GDI headers - they define symbol
+ ERROR that conflicts with mysql headers.
+*/
+#ifndef NOGDI
+#define NOGDI
#endif
+/* Include common headers.*/
+#include <winsock2.h>
+#include <ws2tcpip.h> /* SOCKET */
+#include <io.h> /* access(), chmod() */
+#include <process.h> /* getpid() */
+
+#define sleep(a) Sleep((a)*1000)
+
+/* Define missing access() modes. */
+#define F_OK 0
+#define W_OK 2
+
+/* Define missing file locking constants. */
+#define F_RDLCK 1
+#define F_WRLCK 2
+#define F_UNLCK 3
+#define F_TO_EOF 0x3FFFFFFF
+
+/* Shared memory and named pipe connections are supported. */
+#define HAVE_SMEM 1
+#define HAVE_NAMED_PIPE 1
+#define shared_memory_buffer_length 16000
+#define default_shared_memory_base_name "MYSQL"
+#endif /* _WIN32*/
+
+
/* Workaround for _LARGE_FILES and _LARGE_FILE_API incompatibility on AIX */
#if defined(_AIX) && defined(_LARGE_FILE_API)
#undef _LARGE_FILE_API
@@ -163,108 +198,6 @@
#define likely(x) __builtin_expect((x),1)
#define unlikely(x) __builtin_expect((x),0)
-
-/*
- The macros below are useful in optimising places where it has been
- discovered that cache misses stall the process and where a prefetch
- of the cache line can improve matters. This is available in GCC 3.1.1
- and later versions.
- PREFETCH_READ says that addr is going to be used for reading and that
- it is to be kept in caches if possible for a while
- PREFETCH_WRITE also says that the item to be cached is likely to be
- updated.
- The *LOCALITY scripts are also available for experimentation purposes
- mostly and should only be used if they are verified to improve matters.
- For more input see GCC manual (available in GCC 3.1.1 and later)
-*/
-
-#if (__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR > 10)
-#define PREFETCH_READ(addr) __builtin_prefetch(addr, 0, 3)
-#define PREFETCH_WRITE(addr) \
- __builtin_prefetch(addr, 1, 3)
-#define PREFETCH_READ_LOCALITY(addr, locality) \
- __builtin_prefetch(addr, 0, locality)
-#define PREFETCH_WRITE_LOCALITY(addr, locality) \
- __builtin_prefetch(addr, 1, locality)
-#else
-#define PREFETCH_READ(addr)
-#define PREFETCH_READ_LOCALITY(addr, locality)
-#define PREFETCH_WRITE(addr)
-#define PREFETCH_WRITE_LOCALITY(addr, locality)
-#endif
-
-/*
- The following macro is used to ensure that code often used in most
- SQL statements and definitely for parts of the SQL processing are
- kept in a code segment by itself. This has the advantage that the
- risk of common code being overlapping in caches of the CPU is less.
- This can be a cause of big performance problems.
- Routines should be put in this category with care and when they are
- put there one should also strive to make as much of the error handling
- as possible (or uncommon code of the routine) to execute in a
- separate method to avoid moving to much code to this code segment.
-
- It is very easy to use, simply add HOT_METHOD at the end of the
- function declaration.
- For more input see GCC manual (available in GCC 2.95 and later)
-*/
-
-#if (__GNUC__ > 2) || (__GNUC__ == 2 && __GNUC_MINOR > 94)
-#define HOT_METHOD \
- __attribute__ ((section ("hot_code_section")))
-#else
-#define HOT_METHOD
-#endif
-
-/*
- The following macro is used to ensure that popular global variables
- are located next to each other to avoid that they contend for the
- same cache lines.
-
- It is very easy to use, simply add HOT_DATA at the end of the declaration
- of the variable, the variable must be initialised because of the way
- that linker works so a declaration using HOT_DATA should look like:
- uint global_hot_data HOT_DATA = 0;
- For more input see GCC manual (available in GCC 2.95 and later)
-*/
-
-#if (__GNUC__ > 2) || (__GNUC__ == 2 && __GNUC_MINOR > 94)
-#define HOT_DATA \
- __attribute__ ((section ("hot_data_section")))
-#else
-#define HOT_DATA
-#endif
-
-/*
- now let's figure out if inline functions are supported
- autoconf defines 'inline' to be empty, if not
-*/
-#define inline_test_1(X) X ## 1
-#define inline_test_2(X) inline_test_1(X)
-#if inline_test_2(inline) != 1
-#define HAVE_INLINE
-#endif
-#undef inline_test_2
-#undef inline_test_1
-/* helper macro for "instantiating" inline functions */
-#define STATIC_INLINE static inline
-
-/*
- The following macros are used to control inlining a bit more than
- usual. These macros are used to ensure that inlining always or
- never occurs (independent of compilation mode).
- For more input see GCC manual (available in GCC 3.1.1 and later)
-*/
-
-#if (__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR > 10)
-#define ALWAYS_INLINE __attribute__ ((always_inline))
-#define NEVER_INLINE __attribute__ ((noinline))
-#else
-#define ALWAYS_INLINE
-#define NEVER_INLINE
-#endif
-
-
/* Fix problem with S_ISLNK() on Linux */
#if defined(TARGET_OS_LINUX) || defined(__GLIBC__)
#undef _GNU_SOURCE
@@ -374,10 +307,6 @@ C_MODE_END
#undef HAVE_PREAD
#undef HAVE_PWRITE
#endif
-#if defined(HAVE_BROKEN_INLINE) && !defined(__cplusplus)
-#undef inline
-#define inline
-#endif
#ifdef UNDEF_HAVE_GETHOSTBYNAME_R /* For OSF4.x */
#undef HAVE_GETHOSTBYNAME_R
@@ -392,18 +321,6 @@ C_MODE_END
#error "Please add -fno-exceptions to CXXFLAGS and reconfigure/recompile"
#endif
-
-/* Fix a bug in gcc 2.8.0 on IRIX 6.2 */
-#if SIZEOF_LONG == 4 && defined(__LONG_MAX__) && (__GNUC__ == 2 && __GNUC_MINOR__ == 8)
-#undef __LONG_MAX__ /* Is a longlong value in gcc 2.8.0 ??? */
-#define __LONG_MAX__ 2147483647
-#endif
-
-/* egcs 1.1.2 has a problem with memcpy on Alpha */
-#if defined(__GNUC__) && defined(__alpha__) && ! (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95))
-#define BAD_MEMCPY
-#endif
-
#if defined(_lint) && !defined(lint)
#define lint
#endif
@@ -414,6 +331,7 @@ C_MODE_END
#ifndef stdin
#include <stdio.h>
#endif
+#include <stdarg.h>
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
@@ -482,15 +400,17 @@ C_MODE_END
#define compile_time_assert(X) \
do \
{ \
- char compile_time_assert[(X) ? 1 : -1] \
- __attribute__ ((unused)); \
+ typedef char compile_time_assert[(X) ? 1 : -1]; \
} while(0)
#endif
/* Go around some bugs in different OS and compilers */
#if defined (HPUX11) && defined(_LARGEFILE_SOURCE)
+#ifndef _LARGEFILE64_SOURCE
#define _LARGEFILE64_SOURCE
#endif
+#endif
+
#if defined(_HPUX_SOURCE) && defined(HAVE_SYS_STREAM_H)
#include <sys/stream.h> /* HPUX 10.20 defines ulong here. UGLY !!! */
#define HAVE_ULONG
@@ -505,32 +425,6 @@ C_MODE_END
extern "C" int madvise(void *addr, size_t len, int behav);
#endif
-#ifdef __QNXNTO__
-/* This has to be after include limits.h */
-#define HAVE_ERRNO_AS_DEFINE
-#define HAVE_FCNTL_LOCK
-#undef HAVE_FINITE
-#undef LONGLONG_MIN /* These get wrongly defined in QNX 6.2 */
-#undef LONGLONG_MAX /* standard system library 'limits.h' */
-#ifdef __cplusplus
-#ifndef HAVE_RINT
-#define HAVE_RINT
-#endif /* rint() and isnan() functions are not */
-#define rint(a) std::rint(a) /* visible in C++ scope due to an error */
-#define isnan(a) std::isnan(a) /* in the usr/include/math.h on QNX */
-#endif
-#endif
-
-/* We can not live without the following defines */
-
-#define USE_MYFUNC 1 /* Must use syscall indirection */
-#define MASTER 1 /* Compile without unireg */
-#define ENGLISH 1 /* Messages in English */
-#define POSIX_MISTAKE 1 /* regexp: Fix stupid spec error */
-#define USE_REGEX 1 /* We want the use the regex library */
-/* Do not define for ultra sparcs */
-#define USE_BMOVE512 1 /* Use this unless system bmove is faster */
-
#define QUOTE_ARG(x) #x /* Quote argument (before cpp) */
#define STRINGIFY_ARG(x) QUOTE_ARG(x) /* Quote argument, after cpp */
@@ -545,17 +439,6 @@ extern "C" int madvise(void *addr, size_t len, int behav);
#define SIGNAL_HANDLER_RESET_ON_DELIVERY
#endif
-/* Define void to stop lint from generating "null effekt" comments */
-#ifndef DONT_DEFINE_VOID
-#ifdef _lint
-int __void__;
-#define VOID(X) (__void__ = (int) (X))
-#else
-#undef VOID
-#define VOID(X) (X)
-#endif
-#endif /* DONT_DEFINE_VOID */
-
/*
Deprecated workaround for false-positive uninitialized variables
warnings. Those should be silenced using tool-specific heuristics.
@@ -569,6 +452,16 @@ int __void__;
#define LINT_INIT(var)
#endif
+#ifndef SO_EXT
+#ifdef _WIN32
+#define SO_EXT ".dll"
+#elif defined(__APPLE__)
+#define SO_EXT ".dylib"
+#else
+#define SO_EXT ".so"
+#endif
+#endif
+
/*
Suppress uninitialized variable warning without generating code.
@@ -583,12 +476,6 @@ int __void__;
#define UNINIT_VAR(x) x= x
#endif
-/* Define some useful general macros */
-#if !defined(max)
-#define max(a, b) ((a) > (b) ? (a) : (b))
-#define min(a, b) ((a) < (b) ? (a) : (b))
-#endif
-
#if !defined(HAVE_UINT)
#undef HAVE_UINT
#define HAVE_UINT
@@ -596,8 +483,6 @@ typedef unsigned int uint;
typedef unsigned short ushort;
#endif
-#define CMP_NUM(a,b) (((a) < (b)) ? -1 : ((a) == (b)) ? 0 : 1)
-#define sgn(a) (((a) < 0) ? -1 : ((a) > 0) ? 1 : 0)
#define swap_variables(t, a, b) { t dummy; dummy= a; a= b; b= dummy; }
#define test(a) ((a) ? 1 : 0)
#define set_if_bigger(a,b) do { if ((a) < (b)) (a)=(b); } while(0)
@@ -611,18 +496,6 @@ typedef unsigned short ushort;
#define FALSE (0) /* Logical false */
#endif
-#if defined(__GNUC__)
-#define function_volatile volatile
-#define my_reinterpret_cast(A) reinterpret_cast<A>
-#define my_const_cast(A) const_cast<A>
-# ifndef GCC_VERSION
-# define GCC_VERSION (__GNUC__ * 1000 + __GNUC_MINOR__)
-# endif
-#elif !defined(my_reinterpret_cast)
-#define my_reinterpret_cast(A) (A)
-#define my_const_cast(A) (A)
-#endif
-
#include <my_compiler.h>
/*
@@ -636,16 +509,6 @@ int __cxa_pure_virtual () __attribute__ ((weak));
C_MODE_END
#endif
-/* From old s-system.h */
-
-/*
- Support macros for non ansi & other old compilers. Since such
- things are no longer supported we do nothing. We keep then since
- some of our code may still be needed to upgrade old customers.
-*/
-#define _VARARGS(X) X
-#define _STATIC_VARARGS(X) X
-
/* The DBUG_ON flag always takes precedence over default DBUG_OFF */
#if defined(DBUG_ON) && defined(DBUG_OFF)
#undef DBUG_OFF
@@ -659,16 +522,12 @@ C_MODE_END
# endif
#endif
-#include <my_dbug.h>
-
-#define MIN_ARRAY_SIZE 0 /* Zero or One. Gcc allows zero*/
-#define ASCII_BITS_USED 8 /* Bit char used */
-#define NEAR_F /* No near function handling */
-
/* Some types that is different between systems */
typedef int File; /* File descriptor */
-#ifndef Socket_defined
+#ifdef _WIN32
+typedef SOCKET my_socket;
+#else
typedef int my_socket; /* File descriptor for sockets */
#define INVALID_SOCKET -1
#endif
@@ -739,14 +598,7 @@ typedef SOCKET_SIZE_TYPE size_socket;
#endif /* __WIN__ */
-/* #define USE_RECORD_LOCK */
-
- /* Unsigned types supported by the compiler */
-#define UNSINT8 /* unsigned int8 (char) */
-#define UNSINT16 /* unsigned int16 */
-#define UNSINT32 /* unsigned int32 */
-
- /* General constants */
+/* General constants */
#define FN_LEN 256 /* Max file name len */
#define FN_HEADLEN 253 /* Max length of filepart of file name */
#define FN_EXTLEN 20 /* Max length of extension (part of FN_LEN) */
@@ -756,19 +608,57 @@ typedef SOCKET_SIZE_TYPE size_socket;
#define FN_CURLIB '.' /* ./ is used as abbrev for current dir */
#define FN_PARENTDIR ".." /* Parent directory; Must be a string */
-#ifndef FN_LIBCHAR
+#ifdef _WIN32
+#define FN_LIBCHAR '\\'
+#define FN_LIBCHAR2 '/'
+#define FN_ROOTDIR "\\"
+#define FN_DEVCHAR ':'
+#define FN_NETWORK_DRIVES /* Uses \\ to indicate network drives */
+#define FN_NO_CASE_SENCE /* Files are not case-sensitive */
+#else
#define FN_LIBCHAR '/'
+#define FN_LIBCHAR2 '/'
#define FN_ROOTDIR "/"
#endif
-#define MY_NFILE 64 /* This is only used to save filenames */
+
+/*
+ MY_FILE_MIN is Windows speciality and is used to quickly detect
+ the mismatch of CRT and mysys file IO usage on Windows at runtime.
+ CRT file descriptors can be in the range 0-2047, whereas descriptors returned
+ by my_open() will start with 2048. If a file descriptor with value less then
+ MY_FILE_MIN is passed to mysys IO function, chances are it stemms from
+ open()/fileno() and not my_open()/my_fileno.
+
+ For Posix, mysys functions are light wrappers around libc, and MY_FILE_MIN
+ is logically 0.
+*/
+
+#ifdef _WIN32
+#define MY_FILE_MIN 2048
+#else
+#define MY_FILE_MIN 0
+#endif
+
+/*
+ MY_NFILE is the default size of my_file_info array.
+
+ It is larger on Windows, because it all file handles are stored in my_file_info
+ Default size is 16384 and this should be enough for most cases.If it is not
+ enough, --max-open-files with larger value can be used.
+
+ For Posix , my_file_info array is only used to store filenames for
+ error reporting and its size is not a limitation for number of open files.
+*/
+#ifdef _WIN32
+#define MY_NFILE (16384 + MY_FILE_MIN)
+#else
+#define MY_NFILE 64
+#endif
+
#ifndef OS_FILE_LIMIT
#define OS_FILE_LIMIT UINT_MAX
#endif
-/* #define EXT_IN_LIBNAME */
-/* #define FN_NO_CASE_SENCE */
-/* #define FN_UPPER_CASE TRUE */
-
/*
Io buffer size; Must be a power of 2 and a multiple of 512. May be
smaller what the disk page size. This influences the speed of the
@@ -779,27 +669,22 @@ typedef SOCKET_SIZE_TYPE size_socket;
How much overhead does malloc have. The code often allocates
something like 1024-MALLOC_OVERHEAD bytes
*/
-#ifdef SAFEMALLOC
-#define MALLOC_OVERHEAD (8+24+4)
-#else
#define MALLOC_OVERHEAD 8
-#endif
+
/* get memory in huncs */
#define ONCE_ALLOC_INIT (uint) (4096-MALLOC_OVERHEAD)
/* Typical record cash */
#define RECORD_CACHE_SIZE (uint) (64*1024-MALLOC_OVERHEAD)
/* Typical key cash */
-#define KEY_CACHE_SIZE (uint) (8*1024*1024-MALLOC_OVERHEAD)
+#define KEY_CACHE_SIZE (uint) (8*1024*1024)
/* Default size of a key cache block */
#define KEY_CACHE_BLOCK_SIZE (uint) 1024
/* Some things that this system doesn't have */
-#define NO_HASH /* Not needed anymore */
-#ifdef __WIN__
-#define NO_DIR_LIBRARY /* Not standar dir-library */
-#define USE_MY_STAT_STRUCT /* For my_lib */
+#ifdef _WIN32
+#define NO_DIR_LIBRARY /* Not standard dir-library */
#endif
/* Some defines of functions for portability */
@@ -807,6 +692,31 @@ typedef SOCKET_SIZE_TYPE size_socket;
#undef remove /* Crashes MySQL on SCO 5.0.0 */
#ifndef __WIN__
#define closesocket(A) close(A)
+#endif
+
+#if (_MSC_VER)
+#if !defined(_WIN64)
+inline double my_ulonglong2double(unsigned long long value)
+{
+ long long nr=(long long) value;
+ if (nr >= 0)
+ return (double) nr;
+ return (18446744073709551616.0 + (double) nr);
+}
+#define ulonglong2double my_ulonglong2double
+#define my_off_t2double my_ulonglong2double
+#endif /* _WIN64 */
+inline unsigned long long my_double2ulonglong(double d)
+{
+ double t= d - (double) 0x8000000000000000ULL;
+
+ if (t >= 0)
+ return ((unsigned long long) t) + 0x8000000000000000ULL;
+ return (unsigned long long) d;
+}
+#define double2ulonglong my_double2ulonglong
+#endif
+
#ifndef ulonglong2double
#define ulonglong2double(A) ((double) (ulonglong) (A))
#define my_off_t2double(A) ((double) (my_off_t) (A))
@@ -814,13 +724,11 @@ typedef SOCKET_SIZE_TYPE size_socket;
#ifndef double2ulonglong
#define double2ulonglong(A) ((ulonglong) (double) (A))
#endif
-#endif
#ifndef offsetof
#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
#endif
#define ulong_to_double(X) ((double) (ulong) (X))
-#define SET_STACK_SIZE(X) /* Not needed on real machines */
#ifndef STACK_DIRECTION
#error "please add -DSTACK_DIRECTION=1 or -1 to your CPPFLAGS"
@@ -839,7 +747,6 @@ typedef SOCKET_SIZE_TYPE size_socket;
/*
Some pre-ANSI-C99 systems like AIX 5.1 and Linux/GCC 2.95 define
ULONGLONG_MAX, LONGLONG_MIN, LONGLONG_MAX; we use them if they're defined.
- Also on Windows we define these constants by hand in config-win.h.
*/
#if defined(HAVE_LONG_LONG) && !defined(LONGLONG_MIN)
@@ -856,6 +763,8 @@ typedef SOCKET_SIZE_TYPE size_socket;
#endif
#endif /* defined (HAVE_LONG_LONG) && !defined(ULONGLONG_MAX)*/
+#define INT_MIN64 (~0x7FFFFFFFFFFFFFFFLL)
+#define INT_MAX64 0x7FFFFFFFFFFFFFFFLL
#define INT_MIN32 (~0x7FFFFFFFL)
#define INT_MAX32 0x7FFFFFFFL
#define UINT_MAX32 0xFFFFFFFFL
@@ -935,9 +844,6 @@ typedef long long my_ptrdiff_t;
#define MY_ALIGN(A,L) (((A) + (L) - 1) & ~((L) - 1))
#define ALIGN_SIZE(A) MY_ALIGN((A),sizeof(double))
/* Size to make adressable obj. */
-#define ALIGN_PTR(A, t) ((t*) MY_ALIGN((A),sizeof(t)))
- /* Offset of field f in structure t */
-#define OFFSET(t, f) ((size_t)(char *)&((t *)0)->f)
#define ADD_TO_PTR(ptr,size,type) (type) ((uchar*) (ptr)+size)
#define PTR_BYTE_DIFF(A,B) (my_ptrdiff_t) ((uchar*) (A) - (uchar*) (B))
@@ -957,18 +863,14 @@ typedef long long my_ptrdiff_t;
((size_t)((char *)&(((TYPE *)0x10)->MEMBER) - (char*)0x10))
#define NullS (char *) 0
-/* Nowdays we do not support MessyDos */
-#ifndef NEAR
-#define NEAR /* Who needs segments ? */
-#define FAR /* On a good machine */
-#ifndef HUGE_PTR
-#define HUGE_PTR
-#endif
+
+#ifdef STDCALL
+#undef STDCALL
#endif
-#if defined(__IBMC__) || defined(__IBMCPP__)
-/* This was _System _Export but caused a lot of warnings on _AIX43 */
-#define STDCALL
-#elif !defined( STDCALL)
+
+#ifdef _WIN32
+#define STDCALL __stdcall
+#else
#define STDCALL
#endif
@@ -1052,31 +954,24 @@ typedef long long intptr;
#define MY_ERRPTR ((void*)(intptr)1)
-#ifdef USE_RAID
-/*
- The following is done with a if to not get problems with pre-processors
- with late define evaluation
-*/
-#if SIZEOF_OFF_T == 4
-#define SYSTEM_SIZEOF_OFF_T 4
+#if defined(_WIN32)
+typedef unsigned long long my_off_t;
+typedef unsigned long long os_off_t;
#else
-#define SYSTEM_SIZEOF_OFF_T 8
-#endif
-#undef SIZEOF_OFF_T
-#define SIZEOF_OFF_T 8
-#else
-#define SYSTEM_SIZEOF_OFF_T SIZEOF_OFF_T
-#endif /* USE_RAID */
-
+typedef off_t os_off_t;
#if SIZEOF_OFF_T > 4
typedef ulonglong my_off_t;
#else
typedef unsigned long my_off_t;
#endif
+#endif /*_WIN32*/
#define MY_FILEPOS_ERROR (~(my_off_t) 0)
-#if !defined(__WIN__)
-typedef off_t os_off_t;
-#endif
+
+/*
+ TODO Convert these to use Bitmap class.
+ */
+typedef ulonglong table_map; /* Used for table bits in join */
+typedef ulong nesting_map; /* Used for flags of nesting constructs */
#if defined(__WIN__)
#define socket_errno WSAGetLastError()
@@ -1099,17 +994,10 @@ typedef off_t os_off_t;
#define SOCKET_EMFILE EMFILE
#endif
-typedef uint8 int7; /* Most effective integer 0 <= x <= 127 */
-typedef short int15; /* Most effective integer 0 <= x <= 32767 */
typedef int myf; /* Type of MyFlags in my_funcs */
typedef char my_bool; /* Small bool */
-#if !defined(bool) && (!defined(HAVE_BOOL) || !defined(__cplusplus))
-typedef char bool; /* Ordinary boolean values 0 1 */
-#endif
- /* Macros for converting *constants* to the right type */
-#define INT8(v) (int8) (v)
-#define INT16(v) (int16) (v)
-#define INT32(v) (int32) (v)
+
+/* Macros for converting *constants* to the right type */
#define MYF(v) (myf) (v)
#ifndef LL
@@ -1151,23 +1039,11 @@ typedef char bool; /* Ordinary boolean values 0 1 */
#define reg16 register
#endif
-/*
- Sometimes we want to make sure that the variable is not put into
- a register in debugging mode so we can see its value in the core
-*/
-
-#ifndef DBUG_OFF
-#define dbug_volatile volatile
-#else
-#define dbug_volatile
-#endif
+#include <my_dbug.h>
/* Some helper macros */
#define YESNO(X) ((X) ? "yes" : "no")
-/* Defines for time function */
-#define SCALE_SEC 100
-#define SCALE_USEC 10000
#define MY_HOW_OFTEN_TO_ALARM 2 /* How often we want info on screen */
#define MY_HOW_OFTEN_TO_WRITE 1000 /* How often we want info on screen */
@@ -1365,8 +1241,8 @@ do { doubleget_union _tmp; \
((uchar*) &def_temp)[7]=(M)[0];\
(V) = def_temp; } while(0)
#else
-#define float4get(V,M) memcpy_fixed((uchar*) &V,(uchar*) (M),sizeof(float))
-#define float4store(V,M) memcpy_fixed((uchar*) V,(uchar*) (&M),sizeof(float))
+#define float4get(V,M) memcpy(&V, (M), sizeof(float))
+#define float4store(V,M) memcpy(V, (&M), sizeof(float))
#if defined(__FLOAT_WORD_ORDER) && (__FLOAT_WORD_ORDER == __BIG_ENDIAN)
#define doublestore(T,V) do { *(((char*)T)+0)=(char) ((uchar *) &V)[4];\
@@ -1436,12 +1312,12 @@ do { doubleget_union _tmp; \
*(((char*)T)+1)=(((A) >> 16));\
*(((char*)T)+0)=(((A) >> 24)); } while(0)
-#define floatget(V,M) memcpy_fixed((uchar*) &V,(uchar*) (M),sizeof(float))
-#define floatstore(T,V) memcpy_fixed((uchar*) (T),(uchar*)(&V),sizeof(float))
-#define doubleget(V,M) memcpy_fixed((uchar*) &V,(uchar*) (M),sizeof(double))
-#define doublestore(T,V) memcpy_fixed((uchar*) (T),(uchar*) &V,sizeof(double))
-#define longlongget(V,M) memcpy_fixed((uchar*) &V,(uchar*) (M),sizeof(ulonglong))
-#define longlongstore(T,V) memcpy_fixed((uchar*) (T),(uchar*) &V,sizeof(ulonglong))
+#define floatget(V,M) memcpy(&V, (M), sizeof(float))
+#define floatstore(T,V) memcpy((T), (void*) (&V), sizeof(float))
+#define doubleget(V,M) memcpy(&V, (M), sizeof(double))
+#define doublestore(T,V) memcpy((T), (void *) &V, sizeof(double))
+#define longlongget(V,M) memcpy(&V, (M), sizeof(ulonglong))
+#define longlongstore(T,V) memcpy((T), &V, sizeof(ulonglong))
#else
@@ -1452,15 +1328,15 @@ do { doubleget_union _tmp; \
#define shortstore(T,V) int2store(T,V)
#define longstore(T,V) int4store(T,V)
#ifndef floatstore
-#define floatstore(T,V) memcpy_fixed((uchar*) (T),(uchar*) (&V),sizeof(float))
-#define floatget(V,M) memcpy_fixed((uchar*) &V, (uchar*) (M), sizeof(float))
+#define floatstore(T,V) memcpy((T), (void *) (&V), sizeof(float))
+#define floatget(V,M) memcpy(&V, (M), sizeof(float))
#endif
#ifndef doubleget
-#define doubleget(V,M) memcpy_fixed((uchar*) &V,(uchar*) (M),sizeof(double))
-#define doublestore(T,V) memcpy_fixed((uchar*) (T),(uchar*) &V,sizeof(double))
+#define doubleget(V,M) memcpy(&V, (M), sizeof(double))
+#define doublestore(T,V) memcpy((T), (void *) &V, sizeof(double))
#endif /* doubleget */
-#define longlongget(V,M) memcpy_fixed((uchar*) &V,(uchar*) (M),sizeof(ulonglong))
-#define longlongstore(T,V) memcpy_fixed((uchar*) (T),(uchar*) &V,sizeof(ulonglong))
+#define longlongget(V,M) memcpy(&V, (M), sizeof(ulonglong))
+#define longlongstore(T,V) memcpy((T), &V, sizeof(ulonglong))
#endif /* WORDS_BIGENDIAN */
@@ -1485,45 +1361,36 @@ do { doubleget_union _tmp; \
#define NO_EMBEDDED_ACCESS_CHECKS
#endif
-#ifdef HAVE_DLOPEN
-#if defined(__WIN__)
-#define dlsym(lib, name) GetProcAddress((HMODULE)lib, name)
+#if defined(_WIN32)
+#define dlsym(lib, name) (void*)GetProcAddress((HMODULE)lib, name)
#define dlopen(libname, unused) LoadLibraryEx(libname, NULL, 0)
#define dlclose(lib) FreeLibrary((HMODULE)lib)
-#elif defined(HAVE_DLFCN_H)
-#include <dlfcn.h>
+#ifndef HAVE_DLOPEN
+#define HAVE_DLOPEN
#endif
#endif
-/* FreeBSD 2.2.2 does not define RTLD_NOW) */
-#ifndef RTLD_NOW
-#define RTLD_NOW 1
+#ifdef HAVE_DLOPEN
+#if defined(HAVE_DLFCN_H)
+#include <dlfcn.h>
+#endif
#endif
#ifndef HAVE_DLERROR
+#ifdef _WIN32
#define dlerror() ""
+#else
+#define dlerror() "No support for dynamic loading (static build?)"
+#endif
#endif
-#ifndef __NETWARE__
/*
* Include standard definitions of operator new and delete.
*/
#ifdef __cplusplus
#include <new>
#endif
-#else
-/*
- * Define placement versions of operator new and operator delete since
- * we don't have <new> when building for Netware.
- */
-#ifdef __cplusplus
-inline void *operator new(size_t, void *ptr) { return ptr; }
-inline void *operator new[](size_t, void *ptr) { return ptr; }
-inline void operator delete(void*, void*) { /* Do nothing */ }
-inline void operator delete[](void*, void*) { /* Do nothing */ }
-#endif
-#endif
/* Length of decimal number represented by INT32. */
#define MY_INT32_NUM_DECIMAL_DIGITS 11
@@ -1536,6 +1403,7 @@ inline void operator delete[](void*, void*) { /* Do nothing */ }
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#endif
+
/*
Only Linux is known to need an explicit sync of the directory to make sure a
file creation/deletion/renaming in(from,to) this directory durable.
@@ -1548,6 +1416,25 @@ inline void operator delete[](void*, void*) { /* Do nothing */ }
#define bool In_C_you_should_use_my_bool_instead()
#endif
+/* Provide __func__ macro definition for platforms that miss it. */
+#if __STDC_VERSION__ < 199901L
+# if __GNUC__ >= 2
+# define __func__ __FUNCTION__
+# else
+# define __func__ "<unknown>"
+# endif
+#elif defined(_MSC_VER)
+# if _MSC_VER < 1300
+# define __func__ "<unknown>"
+# else
+# define __func__ __FUNCTION__
+# endif
+#elif defined(__BORLANDC__)
+# define __func__ __FUNC__
+#else
+# define __func__ "<unknown>"
+#endif
+
#ifndef HAVE_RINT
/**
All integers up to this number can be represented exactly as double precision
@@ -1596,4 +1483,17 @@ static inline double rint(double x)
#endif
#endif
+/* Defines that are unique to the embedded version of MySQL */
+
+#ifdef EMBEDDED_LIBRARY
+
+/* Things we don't need in the embedded version of MySQL */
+/* TODO HF add #undef HAVE_VIO if we don't want client in embedded library */
+
+#undef HAVE_OPENSSL
+#undef HAVE_SMEM /* No shared memory */
+#undef HAVE_NDBCLUSTER_DB /* No NDB cluster */
+
+#endif /* EMBEDDED_LIBRARY */
+
#endif /* my_global_h */
diff --git a/include/my_handler.h b/include/my_handler.h
index a3376cb74a2..977c0042938 100644
--- a/include/my_handler.h
+++ b/include/my_handler.h
@@ -23,6 +23,8 @@
extern "C" {
#endif
+#include "m_ctype.h" /* CHARSET_INFO */
+
/*
There is a hard limit for the maximum number of keys as there are only
8 bits in the index file header for the number of keys in a table.
@@ -53,8 +55,8 @@ typedef struct st_HA_KEYSEG /* Key-portion */
uint16 bit_pos; /* Position to bit part */
uint16 flag;
uint16 length; /* Keylength */
+ uint16 language;
uint8 type; /* Type of key (for sort) */
- uint8 language;
uint8 null_bit; /* bitmask to test for NULL */
uint8 bit_start,bit_end; /* if bit field */
uint8 bit_length; /* Length of bit part */
diff --git a/include/my_libwrap.h b/include/my_libwrap.h
index 9a8579475fb..8235c00d8f3 100644
--- a/include/my_libwrap.h
+++ b/include/my_libwrap.h
@@ -1,3 +1,6 @@
+#ifndef MY_LIBWRAP_INCLUDED
+#define MY_LIBWRAP_INCLUDED
+
/* Copyright (C) 2000 MySQL AB
This program is free software; you can redistribute it and/or modify
@@ -25,3 +28,4 @@ extern int my_hosts_access(struct request_info *req);
extern char *my_eval_client(struct request_info *req);
#endif /* HAVE_LIBWRAP */
+#endif /* MY_LIBWRAP_INCLUDED */
diff --git a/include/my_list.h b/include/my_list.h
index 775b56587b8..ff086e1725b 100644
--- a/include/my_list.h
+++ b/include/my_list.h
@@ -37,7 +37,7 @@ extern int list_walk(LIST *,list_walk_action action,unsigned char * argument);
#define list_rest(a) ((a)->next)
#define list_push(a,b) (a)=list_cons((b),(a))
-#define list_pop(A) {LIST *old=(A); (A)=list_delete(old,old) ; my_free((unsigned char *) old,MYF(MY_FAE)); }
+#define list_pop(A) {LIST *old=(A); (A)=list_delete(old,old); my_free(old); }
#ifdef __cplusplus
}
diff --git a/include/my_md5.h b/include/my_md5.h
index 6458f27c5cc..782bef8a27a 100644
--- a/include/my_md5.h
+++ b/include/my_md5.h
@@ -1,3 +1,6 @@
+#ifndef MY_MD5_INCLUDED
+#define MY_MD5_INCLUDED
+
/* Copyright (C) 2000 MySQL AB
This program is free software; you can redistribute it and/or modify
@@ -52,3 +55,5 @@ do { \
my_MD5Update (&ctx, buf, len); \
my_MD5Final (digest, &ctx); \
} while (0)
+
+#endif /* MY_MD__INCLUDED */
diff --git a/include/my_net.h b/include/my_net.h
index 3af79ea3db5..5762f5da06e 100644
--- a/include/my_net.h
+++ b/include/my_net.h
@@ -14,9 +14,6 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
/*
- thread safe version of some common functions:
- my_inet_ntoa
-
This file is also used to make handling of sockets and ioctl()
portable accross systems.
@@ -24,6 +21,9 @@
#ifndef _my_net_h
#define _my_net_h
+
+#include "my_global.h" /* C_MODE_START, C_MODE_END */
+
C_MODE_START
#include <errno.h>
@@ -43,7 +43,7 @@ C_MODE_START
#include <sys/ioctl.h>
#endif
-#if !defined(__WIN__) && !defined(HAVE_BROKEN_NETINET_INCLUDES) && !defined(__BEOS__) && !defined(__NETWARE__)
+#if !defined(__WIN__) && !defined(HAVE_BROKEN_NETINET_INCLUDES)
#include <netinet/in_systm.h>
#include <netinet/in.h>
#include <netinet/ip.h>
@@ -73,22 +73,10 @@ C_MODE_START
#define in_addr_t uint32
#endif
-/* On some operating systems (e.g. Solaris) INADDR_NONE is not defined */
-#ifndef INADDR_NONE
-#define INADDR_NONE -1 /* Error value from inet_addr */
-#endif
-
-/* Thread safe or portable version of some functions */
-
-void my_inet_ntoa(struct in_addr in, char *buf);
-
/*
Handling of gethostbyname_r()
*/
-#if !defined(HPUX10)
-struct hostent;
-#endif /* HPUX */
#if !defined(HAVE_GETHOSTBYNAME_R)
struct hostent *my_gethostbyname_r(const char *name,
struct hostent *result, char *buffer,
@@ -118,11 +106,5 @@ struct hostent *my_gethostbyname_r(const char *name,
#define GETHOSTBYNAME_BUFF_SIZE 2048
#endif
-/* On SCO you get a link error when refering to h_errno */
-#ifdef SCO
-#undef h_errno
-#define h_errno errno
-#endif
-
C_MODE_END
#endif
diff --git a/include/my_no_pthread.h b/include/my_no_pthread.h
index 511fac407d5..633a5b94a6c 100644
--- a/include/my_no_pthread.h
+++ b/include/my_no_pthread.h
@@ -1,4 +1,7 @@
-/* Copyright (C) 2000 MySQL AB
+#ifndef MY_NO_PTHREAD_INCLUDED
+#define MY_NO_PTHREAD_INCLUDED
+
+/* 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
@@ -14,9 +17,7 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
-#if !defined(_my_no_pthread_h) && !defined(THREAD)
-#define _my_no_pthread_h
-
+#ifndef THREAD
/*
This block is to access some thread-related type definitions
@@ -46,6 +47,18 @@
#define rw_wrlock(A)
#define rw_unlock(A)
#define rwlock_destroy(A)
+#define safe_mutex_assert_owner(mp)
+
+#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)
typedef int my_pthread_once_t;
#define MY_PTHREAD_ONCE_INIT 0
@@ -56,3 +69,4 @@ typedef int my_pthread_once_t;
} while(0)
#endif
+#endif /* MY_NO_PTHREAD_INCLUDED */
diff --git a/include/my_nosys.h b/include/my_nosys.h
index df5639b81e2..96ba6d4c464 100644
--- a/include/my_nosys.h
+++ b/include/my_nosys.h
@@ -30,7 +30,7 @@ extern "C" {
#include <malloc.h>
#endif
-#undef my_read /* Can be predefined in raid.h */
+#undef my_read
#undef my_write
#undef my_seek
#define my_read(a,b,c,d) my_quick_read(a,b,c,d)
@@ -39,7 +39,7 @@ extern size_t my_quick_read(File Filedes,uchar *Buffer,size_t Count,
myf myFlags);
extern size_t my_quick_write(File Filedes,const uchar *Buffer,size_t Count);
-#if !defined(SAFEMALLOC) && defined(USE_HALLOC)
+#if defined(USE_HALLOC)
#define my_malloc(a,b) halloc(a,1)
#define my_no_flags_free(a) hfree(a)
#endif
diff --git a/include/my_pthread.h b/include/my_pthread.h
index a7e4ea25064..bec88a716fe 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
@@ -18,6 +18,8 @@
#ifndef _my_pthread_h
#define _my_pthread_h
+#include "my_global.h" /* myf */
+
#ifndef ETIME
#define ETIME ETIMEDOUT /* For FreeBSD */
#endif
@@ -31,11 +33,10 @@ extern "C" {
#if defined(__WIN__)
typedef CRITICAL_SECTION pthread_mutex_t;
-typedef HANDLE pthread_t;
+typedef DWORD pthread_t;
typedef struct thread_attr {
DWORD dwStackSize ;
DWORD dwCreatingFlag ;
- int priority ;
} pthread_attr_t ;
typedef struct { int dummy; } pthread_condattr_t;
@@ -47,25 +48,35 @@ typedef struct st_pthread_link {
struct st_pthread_link *next;
} pthread_link;
-typedef struct {
- uint32 waiting;
- CRITICAL_SECTION lock_waiting;
-
- enum {
- SIGNAL= 0,
- BROADCAST= 1,
- MAX_EVENTS= 2
- } EVENTS;
-
- HANDLE events[MAX_EVENTS];
- HANDLE broadcast_block_event;
-
+/**
+ Implementation of Windows condition variables.
+ We use native conditions on Vista and later, and fallback to own
+ implementation on earlier OS version.
+*/
+typedef union
+{
+ /* Native condition (used on Vista and later) */
+ CONDITION_VARIABLE native_cond;
+
+ /* Own implementation (used on XP) */
+ struct
+ {
+ uint32 waiting;
+ CRITICAL_SECTION lock_waiting;
+ enum
+ {
+ SIGNAL= 0,
+ BROADCAST= 1,
+ MAX_EVENTS= 2
+ } EVENTS;
+ HANDLE events[MAX_EVENTS];
+ HANDLE broadcast_block_event;
+ };
} pthread_cond_t;
typedef int pthread_mutexattr_t;
-#define win_pthread_self my_thread_var->pthread_self
-#define pthread_self() win_pthread_self
+#define pthread_self() GetCurrentThreadId()
#define pthread_handler_t EXTERNC void * __cdecl
typedef void * (__cdecl *pthread_handler)(void *);
@@ -104,10 +115,22 @@ struct timespec {
(ABSTIME).max_timeout_msec= (long)((NSEC)/1000000); \
}
-void win_pthread_init(void);
-int win_pthread_setspecific(void *A,void *B,uint length);
+/**
+ Compare two timespec structs.
+
+ @retval 1 If TS1 ends after TS2.
+
+ @retval 0 If TS1 is equal to TS2.
+
+ @retval -1 If TS1 ends before TS2.
+*/
+#define cmp_timespec(TS1, TS2) \
+ ((TS1.tv.i64 > TS2.tv.i64) ? 1 : \
+ ((TS1.tv.i64 < TS2.tv.i64) ? -1 : 0))
+
+
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,
@@ -117,69 +140,50 @@ int pthread_cond_broadcast(pthread_cond_t *cond);
int pthread_cond_destroy(pthread_cond_t *cond);
int pthread_attr_init(pthread_attr_t *connect_att);
int pthread_attr_setstacksize(pthread_attr_t *connect_att,DWORD stack);
-int pthread_attr_setprio(pthread_attr_t *connect_att,int priority);
int pthread_attr_destroy(pthread_attr_t *connect_att);
int my_pthread_once(my_pthread_once_t *once_control,void (*init_routine)(void));
struct tm *localtime_r(const time_t *timep,struct tm *tmp);
struct tm *gmtime_r(const time_t *timep,struct tm *tmp);
+void pthread_exit(void *a);
+int pthread_join(pthread_t thread, void **value_ptr);
+int pthread_cancel(pthread_t thread);
-void pthread_exit(void *a); /* was #define pthread_exit(A) ExitThread(A)*/
-
+#ifndef ETIMEDOUT
#define ETIMEDOUT 145 /* Win32 doesn't have this */
-#define getpid() GetCurrentThreadId()
+#endif
#define HAVE_LOCALTIME_R 1
#define _REENTRANT 1
#define HAVE_PTHREAD_ATTR_SETSTACKSIZE 1
-/*
- Windows has two ways to use thread local storage. The most efficient
- is using __declspec(thread), but that does not work properly when
- used in a .dll that is loaded at runtime, after program load. So for
- libmysql.dll and libmysqld.dll we define USE_TLS in order to use the
- TlsXxx() API instead, which works in all cases.
-*/
-#ifdef USE_TLS /* For LIBMYSQL.DLL */
+
#undef SAFE_MUTEX /* This will cause conflicts */
#define pthread_key(T,V) DWORD V
#define pthread_key_create(A,B) ((*A=TlsAlloc())==0xFFFFFFFF)
#define pthread_key_delete(A) TlsFree(A)
+#define my_pthread_setspecific_ptr(T,V) (!TlsSetValue((T),(V)))
+#define pthread_setspecific(A,B) (!TlsSetValue((A),(B)))
#define pthread_getspecific(A) (TlsGetValue(A))
#define my_pthread_getspecific(T,A) ((T) TlsGetValue(A))
#define my_pthread_getspecific_ptr(T,V) ((T) TlsGetValue(V))
-#define my_pthread_setspecific_ptr(T,V) (!TlsSetValue((T),(V)))
-#define pthread_setspecific(A,B) (!TlsSetValue((A),(B)))
-#else
-#define pthread_key(T,V) __declspec(thread) T V
-#define pthread_key_create(A,B) pthread_dummy(0)
-#define pthread_key_delete(A) pthread_dummy(0)
-#define pthread_getspecific(A) (&(A))
-#define my_pthread_getspecific(T,A) (&(A))
-#define my_pthread_getspecific_ptr(T,V) (V)
-#define my_pthread_setspecific_ptr(T,V) ((T)=(V),0)
-#define pthread_setspecific(A,B) win_pthread_setspecific(&(A),(B),sizeof(A))
-#endif /* USE_TLS */
#define pthread_equal(A,B) ((A) == (B))
#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 my_pthread_setprio(A,B) SetThreadPriority(GetCurrentThread(), (B))
+#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)
-#define pthread_join(A,B) (WaitForSingleObject((A), INFINITE) != WAIT_OBJECT_0)
/* Dummy defines for easier code */
#define pthread_attr_setdetachstate(A,B) pthread_dummy(0)
-#define my_pthread_attr_setprio(A,B) pthread_attr_setprio(A,B)
#define pthread_attr_setscope(A,B)
#define pthread_detach_this_thread()
#define pthread_condattr_init(A)
#define pthread_condattr_destroy(A)
-
-#define my_pthread_getprio(thread_id) pthread_dummy(0)
+#define pthread_yield() SwitchToThread()
+#define my_sigset(A,B) signal(A,B)
#else /* Normal threads */
@@ -202,13 +206,6 @@ void pthread_exit(void *a); /* was #define pthread_exit(A) ExitThread(A)*/
#include <synch.h>
#endif
-#ifdef __NETWARE__
-void my_pthread_exit(void *status);
-#define pthread_exit(A) my_pthread_exit(A)
-#endif
-
-extern int my_pthread_getprio(pthread_t thread_id);
-
#define pthread_key(T,V) pthread_key_t V
#define my_pthread_getspecific_ptr(T,V) my_pthread_getspecific(T,(V))
#define my_pthread_setspecific_ptr(T,V) pthread_setspecific(T,(void*) (V))
@@ -270,14 +267,12 @@ int sigwait(sigset_t *setp, int *sigp); /* Use our implemention */
*/
#if defined(HAVE_SIGACTION) && !defined(my_sigset)
#define my_sigset(A,B) do { struct sigaction l_s; sigset_t l_set; \
- IF_DBUG(int l_rc); \
DBUG_ASSERT((A) != 0); \
sigemptyset(&l_set); \
l_s.sa_handler = (B); \
l_s.sa_mask = l_set; \
l_s.sa_flags = 0; \
- IF_DBUG(l_rc=) sigaction((A), &l_s, NULL); \
- DBUG_ASSERT(l_rc == 0); \
+ sigaction((A), &l_s, NULL); \
} while (0)
#elif defined(HAVE_SIGSET) && !defined(my_sigset)
#define my_sigset(A,B) sigset((A),(B))
@@ -285,26 +280,6 @@ int sigwait(sigset_t *setp, int *sigp); /* Use our implemention */
#define my_sigset(A,B) signal((A),(B))
#endif
-#ifndef my_pthread_setprio
-#if defined(HAVE_PTHREAD_SETPRIO_NP) /* FSU threads */
-#define my_pthread_setprio(A,B) pthread_setprio_np((A),(B))
-#elif defined(HAVE_PTHREAD_SETPRIO)
-#define my_pthread_setprio(A,B) pthread_setprio((A),(B))
-#elif defined(HAVE_PTHREAD_SETSCHEDPRIO)
-#define my_pthread_setprio(A,B) pthread_setschedprio((A),(B))
-#else
-extern void my_pthread_setprio(pthread_t thread_id,int prior);
-#endif
-#endif
-
-#ifndef my_pthread_attr_setprio
-#ifdef HAVE_PTHREAD_ATTR_SETPRIO
-#define my_pthread_attr_setprio(A,B) pthread_attr_setprio((A),(B))
-#else
-extern void my_pthread_attr_setprio(pthread_attr_t *attr, int priority);
-#endif
-#endif
-
#if !defined(HAVE_PTHREAD_ATTR_SETSCOPE) || defined(HAVE_DEC_3_2_THREADS)
#define pthread_attr_setscope(A,B)
#undef HAVE_GETHOSTBYADDR_R /* No definition */
@@ -386,7 +361,7 @@ struct tm *gmtime_r(const time_t *clock, struct tm *res);
#define pthread_kill(A,B) pthread_dummy((A) ? 0 : ESRCH)
#undef pthread_detach_this_thread
#define pthread_detach_this_thread() { pthread_t tmp=pthread_self() ; pthread_detach(&tmp); }
-#elif !defined(__NETWARE__) /* HAVE_PTHREAD_ATTR_CREATE && !HAVE_SIGWAIT */
+#else /* HAVE_PTHREAD_ATTR_CREATE && !HAVE_SIGWAIT */
#define HAVE_PTHREAD_KILL
#endif
@@ -410,6 +385,17 @@ void my_pthread_attr_getstacksize(pthread_attr_t *attrib, size_t *size);
int my_pthread_mutex_trylock(pthread_mutex_t *mutex);
#endif
+#if !defined(HAVE_PTHREAD_YIELD_ONE_ARG) && !defined(HAVE_PTHREAD_YIELD_ZERO_ARG)
+/* no pthread_yield() available */
+#ifdef HAVE_SCHED_YIELD
+#define pthread_yield() sched_yield()
+#elif defined(HAVE_PTHREAD_YIELD_NP) /* can be Mac OS X */
+#define pthread_yield() pthread_yield_np()
+#elif defined(HAVE_THR_YIELD)
+#define pthread_yield() thr_yield()
+#endif
+#endif
+
/*
The defines set_timespec and set_timespec_nsec should be used
for calculating an absolute time at which
@@ -451,11 +437,34 @@ int my_pthread_mutex_trylock(pthread_mutex_t *mutex);
#endif /* !set_timespec_nsec */
#endif /* HAVE_TIMESPEC_TS_SEC */
- /* safe_mutex adds checking to mutex for easier debugging */
+/**
+ Compare two timespec structs.
-#if defined(__NETWARE__) && !defined(SAFE_MUTEX_DETECT_DESTROY)
-#define SAFE_MUTEX_DETECT_DESTROY
-#endif
+ @retval 1 If TS1 ends after TS2.
+
+ @retval 0 If TS1 is equal to TS2.
+
+ @retval -1 If TS1 ends before TS2.
+*/
+#ifdef HAVE_TIMESPEC_TS_SEC
+#ifndef cmp_timespec
+#define cmp_timespec(TS1, TS2) \
+ ((TS1.ts_sec > TS2.ts_sec || \
+ (TS1.ts_sec == TS2.ts_sec && TS1.ts_nsec > TS2.ts_nsec)) ? 1 : \
+ ((TS1.ts_sec < TS2.ts_sec || \
+ (TS1.ts_sec == TS2.ts_sec && TS1.ts_nsec < TS2.ts_nsec)) ? -1 : 0))
+#endif /* !cmp_timespec */
+#else
+#ifndef cmp_timespec
+#define cmp_timespec(TS1, TS2) \
+ ((TS1.tv_sec > TS2.tv_sec || \
+ (TS1.tv_sec == TS2.tv_sec && TS1.tv_nsec > TS2.tv_nsec)) ? 1 : \
+ ((TS1.tv_sec < TS2.tv_sec || \
+ (TS1.tv_sec == TS2.tv_sec && TS1.tv_nsec < TS2.tv_nsec)) ? -1 : 0))
+#endif /* !cmp_timespec */
+#endif /* HAVE_TIMESPEC_TS_SEC */
+
+ /* safe_mutex adds checking to mutex for easier debugging */
typedef struct st_safe_mutex_t
{
@@ -595,30 +604,171 @@ int my_pthread_fastmutex_lock(my_pthread_fastmutex_t *mp);
#define my_rwlock_init(A,B) rwlock_init((A),USYNC_THREAD,0)
#else
/* Use our own version of read/write locks */
-typedef struct _my_rw_lock_t {
- pthread_mutex_t lock; /* lock for structure */
- pthread_cond_t readers; /* waiting readers */
- pthread_cond_t writers; /* waiting writers */
- int state; /* -1:writer,0:free,>0:readers */
- int waiters; /* number of waiting writers */
-} my_rw_lock_t;
-
+#define NEED_MY_RW_LOCK 1
#define rw_lock_t my_rw_lock_t
+#define my_rwlock_init(A,B) my_rw_init((A))
#define rw_rdlock(A) my_rw_rdlock((A))
#define rw_wrlock(A) my_rw_wrlock((A))
#define rw_tryrdlock(A) my_rw_tryrdlock((A))
#define rw_trywrlock(A) my_rw_trywrlock((A))
#define rw_unlock(A) my_rw_unlock((A))
-#define rwlock_destroy(A) my_rwlock_destroy((A))
+#define rwlock_destroy(A) my_rw_destroy((A))
+#define rw_lock_assert_write_owner(A) my_rw_lock_assert_write_owner((A))
+#define rw_lock_assert_not_write_owner(A) my_rw_lock_assert_not_write_owner((A))
+#endif /* USE_MUTEX_INSTEAD_OF_RW_LOCKS */
+
+
+/**
+ Portable implementation of special type of read-write locks.
+
+ These locks have two properties which are unusual for rwlocks:
+ 1) They "prefer readers" in the sense that they do not allow
+ situations in which rwlock is rd-locked and there is a
+ pending rd-lock which is blocked (e.g. due to pending
+ request for wr-lock).
+ This is a stronger guarantee than one which is provided for
+ PTHREAD_RWLOCK_PREFER_READER_NP rwlocks in Linux.
+ MDL subsystem deadlock detector relies on this property for
+ its correctness.
+ 2) They are optimized for uncontended wr-lock/unlock case.
+ This is scenario in which they are most oftenly used
+ within MDL subsystem. Optimizing for it gives significant
+ performance improvements in some of tests involving many
+ connections.
+
+ Another important requirement imposed on this type of rwlock
+ by the MDL subsystem is that it should be OK to destroy rwlock
+ object which is in unlocked state even though some threads might
+ have not yet fully left unlock operation for it (of course there
+ is an external guarantee that no thread will try to lock rwlock
+ which is destroyed).
+ Putting it another way the unlock operation should not access
+ rwlock data after changing its state to unlocked.
+
+ TODO/FIXME: We should consider alleviating this requirement as
+ it blocks us from doing certain performance optimizations.
+*/
+
+typedef struct st_rw_pr_lock_t {
+ /**
+ Lock which protects the structure.
+ Also held for the duration of wr-lock.
+ */
+ pthread_mutex_t lock;
+ /**
+ Condition variable which is used to wake-up
+ writers waiting for readers to go away.
+ */
+ pthread_cond_t no_active_readers;
+ /** Number of active readers. */
+ uint active_readers;
+ /** Number of writers waiting for readers to go away. */
+ uint writers_waiting_readers;
+ /** Indicates whether there is an active writer. */
+ my_bool active_writer;
+#ifdef SAFE_MUTEX
+ /** Thread holding wr-lock (for debug purposes only). */
+ pthread_t writer_thread;
+#endif
+} rw_pr_lock_t;
+
+extern int rw_pr_init(rw_pr_lock_t *);
+extern int rw_pr_rdlock(rw_pr_lock_t *);
+extern int rw_pr_wrlock(rw_pr_lock_t *);
+extern int rw_pr_unlock(rw_pr_lock_t *);
+extern int rw_pr_destroy(rw_pr_lock_t *);
+#ifdef SAFE_MUTEX
+#define rw_pr_lock_assert_write_owner(A) \
+ DBUG_ASSERT((A)->active_writer && pthread_equal(pthread_self(), \
+ (A)->writer_thread))
+#define rw_pr_lock_assert_not_write_owner(A) \
+ DBUG_ASSERT(! (A)->active_writer || ! pthread_equal(pthread_self(), \
+ (A)->writer_thread))
+#else
+#define rw_pr_lock_assert_write_owner(A)
+#define rw_pr_lock_assert_not_write_owner(A)
+#endif /* SAFE_MUTEX */
+
+
+#ifdef NEED_MY_RW_LOCK
+
+#ifdef _WIN32
+
+/**
+ Implementation of Windows rwlock.
+
+ We use native (slim) rwlocks on Win7 and later, and fallback to portable
+ implementation on earlier Windows.
+
+ slim rwlock are also available on Vista/WS2008, but we do not use it
+ ("trylock" APIs are missing on Vista)
+*/
+typedef union
+{
+ /* Native rwlock (is_srwlock == TRUE) */
+ struct
+ {
+ SRWLOCK srwlock; /* native reader writer lock */
+ BOOL have_exclusive_srwlock; /* used for unlock */
+ };
+
+ /*
+ Portable implementation (is_srwlock == FALSE)
+ Fields are identical with Unix my_rw_lock_t fields.
+ */
+ struct
+ {
+ pthread_mutex_t lock; /* lock for structure */
+ pthread_cond_t readers; /* waiting readers */
+ pthread_cond_t writers; /* waiting writers */
+ int state; /* -1:writer,0:free,>0:readers */
+ int waiters; /* number of waiting writers */
+#ifdef SAFE_MUTEX
+ pthread_t write_thread;
+#endif
+ };
+} my_rw_lock_t;
+
-extern int my_rwlock_init(my_rw_lock_t *, void *);
-extern int my_rwlock_destroy(my_rw_lock_t *);
+#else /* _WIN32 */
+
+/*
+ On systems which don't support native read/write locks we have
+ to use own implementation.
+*/
+typedef struct st_my_rw_lock_t {
+ pthread_mutex_t lock; /* lock for structure */
+ pthread_cond_t readers; /* waiting readers */
+ pthread_cond_t writers; /* waiting writers */
+ int state; /* -1:writer,0:free,>0:readers */
+ int waiters; /* number of waiting writers */
+#ifdef SAFE_MUTEX
+ pthread_t write_thread;
+#endif
+} my_rw_lock_t;
+
+#endif /*! _WIN32 */
+
+extern int my_rw_init(my_rw_lock_t *);
+extern int my_rw_destroy(my_rw_lock_t *);
extern int my_rw_rdlock(my_rw_lock_t *);
extern int my_rw_wrlock(my_rw_lock_t *);
extern int my_rw_unlock(my_rw_lock_t *);
extern int my_rw_tryrdlock(my_rw_lock_t *);
extern int my_rw_trywrlock(my_rw_lock_t *);
-#endif /* USE_MUTEX_INSTEAD_OF_RW_LOCKS */
+#ifdef SAFE_MUTEX
+#define my_rw_lock_assert_write_owner(A) \
+ DBUG_ASSERT((A)->state == -1 && pthread_equal(pthread_self(), \
+ (A)->write_thread))
+#define my_rw_lock_assert_not_write_owner(A) \
+ DBUG_ASSERT((A)->state >= 0 || ! pthread_equal(pthread_self(), \
+ (A)->write_thread))
+#else
+#define my_rw_lock_assert_write_owner(A)
+#define my_rw_lock_assert_not_write_owner(A)
+#endif
+#endif /* NEED_MY_RW_LOCK */
+
#define GETHOSTBYADDR_BUFF_SIZE 2048
@@ -652,12 +802,13 @@ extern pthread_mutexattr_t my_errorcheck_mutexattr;
typedef ulong my_thread_id;
extern my_bool my_thread_global_init(void);
+extern my_bool my_thread_basic_global_init(void);
+extern void my_thread_basic_global_reinit(void);
extern void my_thread_global_end(void);
extern my_bool my_thread_init(void);
extern void my_thread_end(void);
extern const char *my_thread_name(void);
extern my_thread_id my_thread_dbug_id(void);
-extern int pthread_no_free(void *);
extern int pthread_dummy(int);
/* All thread specific variables are in the following struct */
@@ -675,13 +826,17 @@ 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;
- pthread_cond_t suspend;
- pthread_mutex_t mutex;
- pthread_mutex_t * volatile current_mutex;
- pthread_cond_t * volatile current_cond;
+ mysql_cond_t suspend;
+ mysql_mutex_t mutex;
+ mysql_mutex_t * volatile current_mutex;
+ mysql_cond_t * volatile current_cond;
pthread_t pthread_self;
my_thread_id id;
int cmp_length;
@@ -689,6 +844,7 @@ struct st_my_thread_var
my_bool init;
struct st_my_thread_var *next,**prev;
void *opt_info;
+ void *stack_ends_here;
#ifndef DBUG_OFF
void *dbug;
char name[THREAD_NAME_SIZE+1];
@@ -696,6 +852,7 @@ struct st_my_thread_var
};
extern struct st_my_thread_var *_my_thread_var(void) __attribute__ ((const));
+extern void **my_thread_var_dbug();
extern uint my_thread_end_wait_time;
#define my_thread_var (_my_thread_var())
#define my_errno my_thread_var->thr_errno
@@ -717,30 +874,37 @@ extern uint thd_lib_detected;
The implementation is guaranteed to be thread safe, on all platforms.
Note that the calling code should *not* assume the counter is protected
by the mutex given, as the implementation of these helpers may change
- to use atomic operations instead.
+ to use my_atomic operations instead.
*/
/*
Warning:
When compiling without threads, this file is not included.
See the *other* declarations of thread_safe_xxx in include/my_global.h
-
- Second warning:
- See include/config-win.h, for yet another implementation.
*/
#ifdef THREAD
#ifndef thread_safe_increment
+#ifdef _WIN32
+#define thread_safe_increment(V,L) InterlockedIncrement((long*) &(V))
+#define thread_safe_decrement(V,L) InterlockedDecrement((long*) &(V))
+#else
#define thread_safe_increment(V,L) \
- (pthread_mutex_lock((L)), (V)++, pthread_mutex_unlock((L)))
+ (mysql_mutex_lock((L)), (V)++, mysql_mutex_unlock((L)))
#define thread_safe_decrement(V,L) \
- (pthread_mutex_lock((L)), (V)--, pthread_mutex_unlock((L)))
+ (mysql_mutex_lock((L)), (V)--, mysql_mutex_unlock((L)))
+#endif
#endif
#ifndef thread_safe_add
+#ifdef _WIN32
+#define thread_safe_add(V,C,L) InterlockedExchangeAdd((long*) &(V),(C))
+#define thread_safe_sub(V,C,L) InterlockedExchangeAdd((long*) &(V),-(long) (C))
+#else
#define thread_safe_add(V,C,L) \
- (pthread_mutex_lock((L)), (V)+=(C), pthread_mutex_unlock((L)))
+ (mysql_mutex_lock((L)), (V)+=(C), mysql_mutex_unlock((L)))
#define thread_safe_sub(V,C,L) \
- (pthread_mutex_lock((L)), (V)-=(C), pthread_mutex_unlock((L)))
+ (mysql_mutex_lock((L)), (V)-=(C), mysql_mutex_unlock((L)))
+#endif
#endif
#endif
diff --git a/include/my_rdtsc.h b/include/my_rdtsc.h
new file mode 100644
index 00000000000..81bc1aafb58
--- /dev/null
+++ b/include/my_rdtsc.h
@@ -0,0 +1,129 @@
+/* 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 */
+
+/*
+ rdtsc3 -- multi-platform timer code
+ pgulutzan@mysql.com, 2005-08-29
+ modified 2008-11-02
+*/
+
+#ifndef MY_RDTSC_H
+#define MY_RDTSC_H
+
+/**
+ Characteristics of a timer.
+*/
+struct my_timer_unit_info
+{
+ /** Routine used for the timer. */
+ ulonglong routine;
+ /** Overhead of the timer. */
+ ulonglong overhead;
+ /** Frequency of the timer. */
+ ulonglong frequency;
+ /** Resolution of the timer. */
+ ulonglong resolution;
+};
+
+/**
+ Characteristics of all the supported timers.
+ @sa my_timer_init().
+*/
+struct my_timer_info
+{
+ /** Characteristics of the cycle timer. */
+ struct my_timer_unit_info cycles;
+ /** Characteristics of the nanosecond timer. */
+ struct my_timer_unit_info nanoseconds;
+ /** Characteristics of the microsecond timer. */
+ struct my_timer_unit_info microseconds;
+ /** Characteristics of the millisecond timer. */
+ struct my_timer_unit_info milliseconds;
+ /** Characteristics of the tick timer. */
+ struct my_timer_unit_info ticks;
+};
+
+typedef struct my_timer_info MY_TIMER_INFO;
+
+C_MODE_START
+
+/**
+ A cycle timer.
+ @return the current timer value, in cycles.
+*/
+ulonglong my_timer_cycles(void);
+
+/**
+ A namoseconds timer.
+ @return the current timer value, in nanoseconds.
+*/
+ulonglong my_timer_nanoseconds(void);
+
+/**
+ A microseconds timer.
+ @return the current timer value, in microseconds.
+*/
+ulonglong my_timer_microseconds(void);
+
+/**
+ A millisecond timer.
+ @return the current timer value, in milliseconds.
+*/
+ulonglong my_timer_milliseconds(void);
+
+/**
+ A ticks timer.
+ @return the current timer value, in ticks.
+*/
+ulonglong my_timer_ticks(void);
+
+/**
+ Timer initialization function.
+ @param [out] mti the timer characteristics.
+*/
+void my_timer_init(MY_TIMER_INFO *mti);
+
+C_MODE_END
+
+#define MY_TIMER_ROUTINE_ASM_X86 1
+#define MY_TIMER_ROUTINE_ASM_X86_64 2
+#define MY_TIMER_ROUTINE_RDTSCLL 3
+#define MY_TIMER_ROUTINE_ASM_X86_WIN 4
+#define MY_TIMER_ROUTINE_RDTSC 5
+#define MY_TIMER_ROUTINE_ASM_IA64 6
+#define MY_TIMER_ROUTINE_ASM_PPC 7
+#define MY_TIMER_ROUTINE_SGI_CYCLE 8
+#define MY_TIMER_ROUTINE_GETHRTIME 9
+#define MY_TIMER_ROUTINE_READ_REAL_TIME 10
+#define MY_TIMER_ROUTINE_CLOCK_GETTIME 11
+#define MY_TIMER_ROUTINE_NXGETTIME 12
+#define MY_TIMER_ROUTINE_GETTIMEOFDAY 13
+#define MY_TIMER_ROUTINE_QUERYPERFORMANCECOUNTER 14
+#define MY_TIMER_ROUTINE_GETTICKCOUNT 15
+#define MY_TIMER_ROUTINE_TIME 16
+#define MY_TIMER_ROUTINE_TIMES 17
+#define MY_TIMER_ROUTINE_FTIME 18
+#define MY_TIMER_ROUTINE_ASM_PPC64 19
+#define MY_TIMER_ROUTINE_ASM_SUNPRO_SPARC64 20
+#define MY_TIMER_ROUTINE_ASM_SUNPRO_SPARC32 21
+#define MY_TIMER_ROUTINE_ASM_SUNPRO_I386 22
+#define MY_TIMER_ROUTINE_ASM_GCC_SPARC64 23
+#define MY_TIMER_ROUTINE_ASM_GCC_SPARC32 24
+#define MY_TIMER_ROUTINE_MACH_ABSOLUTE_TIME 25
+#define MY_TIMER_ROUTINE_GETSYSTEMTIMEASFILETIME 26
+#define MY_TIMER_ROUTINE_ASM_SUNPRO_X86_64 27
+
+#endif
+
diff --git a/include/my_stacktrace.h b/include/my_stacktrace.h
index b64d5d798a5..8c2c97c68e5 100644
--- a/include/my_stacktrace.h
+++ b/include/my_stacktrace.h
@@ -32,9 +32,7 @@
#define HAVE_STACKTRACE 1
#endif
-#if !defined(__NETWARE__)
#define HAVE_WRITE_CORE
-#endif
#if HAVE_BACKTRACE && HAVE_BACKTRACE_SYMBOLS && \
HAVE_CXXABI_H && HAVE_ABI_CXA_DEMANGLE && \
diff --git a/include/my_sys.h b/include/my_sys.h
index 3a240cfc118..7b437e2a745 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
@@ -15,6 +15,9 @@
#ifndef _my_sys_h
#define _my_sys_h
+
+#include "my_global.h" /* C_MODE_START, C_MODE_END */
+
C_MODE_START
#ifdef HAVE_AIOWAIT
@@ -39,7 +42,7 @@ typedef struct my_aio_result {
#endif /* HAVE_VALGRIND */
#ifndef THREAD
-extern int NEAR my_errno; /* Last error in mysys */
+extern int my_errno; /* Last error in mysys */
#else
#include <my_pthread.h>
#endif
@@ -47,11 +50,23 @@ extern int NEAR my_errno; /* Last error in mysys */
#include <m_ctype.h> /* for CHARSET_INFO */
#include <stdarg.h>
#include <typelib.h>
+#ifdef _WIN32
+#include <malloc.h> /*for alloca*/
+#endif
-#define MYSYS_PROGRAM_USES_CURSES() { error_handler_hook = my_message_curses; mysys_uses_curses=1; }
-#define MYSYS_PROGRAM_DONT_USE_CURSES() { error_handler_hook = my_message_no_curses; mysys_uses_curses=0;}
#define MY_INIT(name) { my_progname= name; my_init(); }
+/**
+ Max length of an error message generated by mysys utilities.
+ Some mysys functions produce error messages. These mostly go
+ to stderr.
+ This constant defines the size of the buffer used to format
+ the message. It should be kept in sync with MYSQL_ERRMSG_SIZE,
+ since sometimes mysys errors are stored in the server diagnostics
+ area, and we would like to avoid unexpected truncation.
+*/
+#define MYSYS_ERRMSG_SIZE (512)
+
#define MY_FILE_ERROR ((size_t) -1)
/* General bitmaps for my_func's */
@@ -62,8 +77,8 @@ extern int NEAR my_errno; /* Last error in mysys */
#define MY_WME 16 /* Write message on error */
#define MY_WAIT_IF_FULL 32 /* Wait and try again if disk full error */
#define MY_IGNORE_BADFD 32 /* my_sync: ignore 'bad descriptor' errors */
-#define MY_SYNC_DIR 1024 /* my_create/delete/rename: sync directory */
-#define MY_RAID 64 /* Support for RAID */
+#define MY_SYNC_DIR 8192 /* my_create/delete/rename: sync directory */
+#define MY_UNUSED 64 /* Unused (was support for RAID) */
#define MY_FULL_IO 512 /* For my_read - loop intil I/O is complete */
#define MY_DONT_CHECK_FILESIZE 128 /* Option to init_io_cache() */
#define MY_LINK_WARNING 32 /* my_redel() gives warning if links */
@@ -86,10 +101,6 @@ extern int NEAR my_errno; /* Last error in mysys */
#define MY_GIVE_INFO 2 /* Give time info about process*/
#define MY_DONT_FREE_DBUG 4 /* Do not call DBUG_END() in my_end() */
-#define MY_REMOVE_NONE 0 /* Params for modify_defaults_file */
-#define MY_REMOVE_OPTION 1
-#define MY_REMOVE_SECTION 2
-
#define ME_HIGHBYTE 8 /* Shift for colours */
#define ME_NOCUR 1 /* Don't use curses message */
#define ME_OLDWIN 2 /* Use old window */
@@ -103,8 +114,6 @@ extern int NEAR my_errno; /* Last error in mysys */
#define ME_COLOUR2 ((2 << ME_HIGHBYTE))
#define ME_COLOUR3 ((3 << ME_HIGHBYTE))
#define ME_FATALERROR 1024 /* Fatal statement error */
-#define ME_NO_WARNING_FOR_ERROR 2048 /* Don't push a warning for error */
-#define ME_NO_SP_HANDLER 4096 /* Don't call stored routine error handlers */
/* Bits in last argument to fn_format */
#define MY_REPLACE_DIR 1 /* replace dir in name with 'dir' */
@@ -145,46 +154,15 @@ extern int NEAR my_errno; /* Last error in mysys */
#define GETDATE_FIXEDLENGTH 16
/* defines when allocating data */
-#ifdef SAFEMALLOC
-#define my_malloc(SZ,FLAG) _mymalloc((SZ), __FILE__, __LINE__, FLAG )
-#define my_malloc_ci(SZ,FLAG) _mymalloc((SZ), sFile, uLine, FLAG )
-#define my_realloc(PTR,SZ,FLAG) _myrealloc((PTR), (SZ), __FILE__, __LINE__, FLAG )
-#define my_checkmalloc() _sanity( __FILE__, __LINE__ )
-#define my_free(PTR,FLAG) _myfree((PTR), __FILE__, __LINE__,FLAG)
-#define my_memdup(A,B,C) _my_memdup((A),(B), __FILE__,__LINE__,C)
-#define my_strdup(A,C) _my_strdup((A), __FILE__,__LINE__,C)
-#define my_strndup(A,B,C) _my_strndup((A),(B),__FILE__,__LINE__,C)
-#define TRASH(A,B) do { bfill(A, B, 0x8F); MEM_UNDEFINED(A, B); } while (0)
-#define QUICK_SAFEMALLOC sf_malloc_quick=1
-#define NORMAL_SAFEMALLOC sf_malloc_quick=0
-extern uint sf_malloc_prehunc,sf_malloc_endhunc,sf_malloc_quick;
-extern ulonglong sf_malloc_mem_limit;
-
-#define CALLER_INFO_PROTO , const char *sFile, uint uLine
-#define CALLER_INFO , __FILE__, __LINE__
-#define ORIG_CALLER_INFO , sFile, uLine
-#else
-#define my_checkmalloc()
-#undef TERMINATE
-#define TERMINATE(A,B) {}
-#define QUICK_SAFEMALLOC
-#define NORMAL_SAFEMALLOC
extern void *my_malloc(size_t Size,myf MyFlags);
-#define my_malloc_ci(SZ,FLAG) my_malloc( SZ, FLAG )
+extern void *my_multi_malloc(myf MyFlags, ...);
extern void *my_realloc(void *oldpoint, size_t Size, myf MyFlags);
-extern void my_no_flags_free(void *ptr);
+extern void my_free(void *ptr);
extern void *my_memdup(const void *from,size_t length,myf MyFlags);
extern char *my_strdup(const char *from,myf MyFlags);
extern char *my_strndup(const char *from, size_t length,
myf MyFlags);
-/* we do use FG (as a no-op) in below so that a typo on FG is caught */
-#define my_free(PTR,FG) ((void)FG,my_no_flags_free(PTR))
-#define CALLER_INFO_PROTO /* nothing */
-#define CALLER_INFO /* nothing */
-#define ORIG_CALLER_INFO /* nothing */
#define TRASH(A,B) do{MEM_CHECK_ADDRESSABLE(A,B);MEM_UNDEFINED(A,B);} while (0)
-#endif
-
#if defined(ENABLED_DEBUG_SYNC)
extern void (*debug_sync_C_callback_ptr)(const char *, size_t);
#define DEBUG_SYNC_C(_sync_point_name_) do { \
@@ -198,11 +176,11 @@ extern void (*debug_sync_C_callback_ptr)(const char *, size_t);
#ifdef HAVE_LARGE_PAGES
extern uint my_get_large_page_size(void);
extern uchar * my_large_malloc(size_t size, myf my_flags);
-extern void my_large_free(uchar * ptr, myf my_flags);
+extern void my_large_free(uchar *ptr);
#else
#define my_get_large_page_size() (0)
#define my_large_malloc(A,B) my_malloc_lock((A),(B))
-#define my_large_free(A,B) my_free_lock((A),(B))
+#define my_large_free(A) my_free_lock((A))
#endif /* HAVE_LARGE_PAGES */
#ifdef HAVE_ALLOCA
@@ -219,8 +197,8 @@ extern void my_large_free(uchar * ptr, myf my_flags);
#define my_alloca(SZ) alloca((size_t) (SZ))
#define my_afree(PTR) {}
#else
-#define my_alloca(SZ) my_malloc(SZ,MYF(0))
-#define my_afree(PTR) my_free(PTR,MYF(MY_WME))
+#define my_alloca(SZ) my_malloc(SZ,MYF(MY_FAE))
+#define my_afree(PTR) my_free(PTR)
#endif /* HAVE_ALLOCA */
#ifndef errno /* did we already get it? */
@@ -232,21 +210,25 @@ extern int errno; /* declare errno */
#endif /* #ifndef errno */
extern char *home_dir; /* Home directory for user */
extern const char *my_progname; /* program-name (printed in errors) */
-extern char NEAR curr_dir[]; /* Current directory for user */
-extern int (*error_handler_hook)(uint my_err, const char *str,myf MyFlags);
-extern int (*fatal_error_handler_hook)(uint my_err, const char *str,
+extern char curr_dir[]; /* Current directory for user */
+extern void (*error_handler_hook)(uint my_err, const char *str,myf MyFlags);
+extern void (*fatal_error_handler_hook)(uint my_err, const char *str,
myf MyFlags);
extern uint my_file_limit;
extern ulong my_thread_stack_size;
+extern const char *(*proc_info_hook)(void *, const char *, const char *,
+ const char *, const unsigned int);
+
#ifdef HAVE_LARGE_PAGES
extern my_bool my_use_large_pages;
extern uint my_large_page_size;
#endif
/* charsets */
+#define MY_ALL_CHARSETS_SIZE 2048
extern MYSQL_PLUGIN_IMPORT CHARSET_INFO *default_charset_info;
-extern MYSQL_PLUGIN_IMPORT CHARSET_INFO *all_charsets[256];
+extern MYSQL_PLUGIN_IMPORT CHARSET_INFO *all_charsets[MY_ALL_CHARSETS_SIZE];
extern CHARSET_INFO compiled_charsets[];
/* statistics */
@@ -261,33 +243,25 @@ extern void (*my_sigtstp_cleanup)(void),
(*my_sigtstp_restart)(void),
(*my_abort_hook)(int);
/* Executed when comming from shell */
-extern MYSQL_PLUGIN_IMPORT int NEAR my_umask; /* Default creation mask */
-extern int NEAR my_umask_dir,
- NEAR my_recived_signals, /* Signals we have got */
- NEAR my_safe_to_handle_signal, /* Set when allowed to SIGTSTP */
- NEAR my_dont_interrupt; /* call remember_intr when set */
-extern my_bool NEAR mysys_uses_curses, my_use_symdir;
-extern size_t sf_malloc_cur_memory, sf_malloc_max_memory;
+extern MYSQL_PLUGIN_IMPORT int my_umask; /* Default creation mask */
+extern int my_umask_dir,
+ my_recived_signals, /* Signals we have got */
+ my_safe_to_handle_signal, /* Set when allowed to SIGTSTP */
+ my_dont_interrupt; /* call remember_intr when set */
+extern my_bool my_use_symdir;
extern ulong my_default_record_cache_size;
-extern my_bool NEAR my_disable_locking,NEAR my_disable_async_io,
- NEAR my_disable_flush_key_blocks, NEAR my_disable_symlinks;
+extern my_bool my_disable_locking, my_disable_async_io,
+ my_disable_flush_key_blocks, my_disable_symlinks;
extern char wild_many,wild_one,wild_prefix;
extern const char *charsets_dir;
/* from default.c */
-extern char *my_defaults_extra_file;
+extern const char *my_defaults_extra_file;
extern const char *my_defaults_group_suffix;
extern const char *my_defaults_file;
extern my_bool timed_mutexes;
-typedef struct wild_file_pack /* Struct to hold info when selecting files */
-{
- uint wilds; /* How many wildcards */
- uint not_pos; /* Start of not-theese-files */
- char * *wild; /* Pointer to wildcards */
-} WF_PACK;
-
enum loglevel {
ERROR_LEVEL,
WARNING_LEVEL,
@@ -334,10 +308,14 @@ enum file_type
struct st_my_file_info
{
- char * name;
- enum file_type type;
-#if defined(THREAD) && !defined(HAVE_PREAD)
- pthread_mutex_t mutex;
+ char *name;
+#ifdef _WIN32
+ HANDLE fhandle; /* win32 file handle */
+ int oflag; /* open flags, e.g O_APPEND */
+#endif
+ enum file_type type;
+#if defined(THREAD) && !defined(HAVE_PREAD) && !defined(_WIN32)
+ mysql_mutex_t mutex;
#endif
};
@@ -357,7 +335,7 @@ typedef struct st_my_tmpdir
char **list;
uint cur, max;
#ifdef THREAD
- pthread_mutex_t mutex;
+ mysql_mutex_t mutex;
#endif
} MY_TMPDIR;
@@ -373,9 +351,9 @@ typedef int (*IO_CACHE_CALLBACK)(struct st_io_cache*);
#ifdef THREAD
typedef struct st_io_cache_share
{
- pthread_mutex_t mutex; /* To sync on reads into buffer. */
- pthread_cond_t cond; /* To wait for signals. */
- pthread_cond_t cond_writer; /* For a synchronized writer. */
+ mysql_mutex_t mutex; /* To sync on reads into buffer. */
+ mysql_cond_t cond; /* To wait for signals. */
+ mysql_cond_t cond_writer; /* For a synchronized writer. */
/* Offset in file corresponding to the first byte of buffer. */
my_off_t pos_in_file;
/* If a synchronized write cache is the source of the data. */
@@ -436,7 +414,7 @@ typedef struct st_io_cache /* Used when cacheing files */
The lock is for append buffer used in SEQ_READ_APPEND cache
need mutex copying from append buffer to read buffer.
*/
- pthread_mutex_t append_buffer_lock;
+ mysql_mutex_t append_buffer_lock;
/*
The following is used when several threads are reading the
same file in parallel. They are synchronized on disk
@@ -579,7 +557,6 @@ typedef int (*Process_option_func)(void *ctx, const char *group_name,
/* Prototypes for mysys and my_func functions */
extern int my_copy(const char *from,const char *to,myf MyFlags);
-extern int my_append(const char *from,const char *to,myf MyFlags);
extern int my_delete(const char *name,myf MyFlags);
extern int my_getwd(char * buf,size_t size,myf MyFlags);
extern int my_setwd(const char *dir,myf MyFlags);
@@ -595,7 +572,6 @@ extern File my_register_filename(File fd, const char *FileName,
extern File my_create(const char *FileName,int CreateFlags,
int AccessFlags, myf MyFlags);
extern int my_close(File Filedes,myf MyFlags);
-extern File my_dup(File file, myf MyFlags);
extern int my_mkdir(const char *dir, int Flags, myf MyFlags);
extern int my_readlink(char *to, const char *filename, myf MyFlags);
extern int my_is_symlink(const char *filename);
@@ -621,63 +597,57 @@ extern size_t my_fwrite(FILE *stream,const uchar *Buffer,size_t Count,
myf MyFlags);
extern my_off_t my_fseek(FILE *stream,my_off_t pos,int whence,myf MyFlags);
extern my_off_t my_ftell(FILE *stream,myf MyFlags);
-extern void *_mymalloc(size_t uSize,const char *sFile,
- uint uLine, myf MyFlag);
-extern void *_myrealloc(void *pPtr,size_t uSize,const char *sFile,
- uint uLine, myf MyFlag);
-extern void * my_multi_malloc _VARARGS((myf MyFlags, ...));
-extern void _myfree(void *pPtr,const char *sFile,uint uLine, myf MyFlag);
-extern int _sanity(const char *sFile, uint uLine);
-extern void *_my_memdup(const void *from, size_t length,
- const char *sFile, uint uLine,myf MyFlag);
-extern char * _my_strdup(const char *from, const char *sFile, uint uLine,
- myf MyFlag);
-extern char *_my_strndup(const char *from, size_t length,
- const char *sFile, uint uLine,
- myf MyFlag);
/* implemented in my_memmem.c */
extern void *my_memmem(const void *haystack, size_t haystacklen,
const void *needle, size_t needlelen);
-#ifdef __WIN__
-extern int my_access(const char *path, int amode);
-extern File my_sopen(const char *path, int oflag, int shflag, int pmode);
+#ifdef _WIN32
+extern int my_access(const char *path, int amode);
#else
#define my_access access
#endif
+
extern int check_if_legal_filename(const char *path);
extern int check_if_legal_tablename(const char *path);
-#if defined(__WIN__) && defined(__NT__)
+#ifdef _WIN32
extern int nt_share_delete(const char *name,myf MyFlags);
#define my_delete_allow_opened(fname,flags) nt_share_delete((fname),(flags))
#else
#define my_delete_allow_opened(fname,flags) my_delete((fname),(flags))
#endif
-#ifndef TERMINATE
-extern void TERMINATE(FILE *file, uint flag);
+#ifdef _WIN32
+/* Windows-only functions (CRT equivalents)*/
+extern HANDLE my_get_osfhandle(File fd);
+extern void my_osmaperr(unsigned long last_error);
#endif
+
extern void init_glob_errs(void);
+extern const char** get_global_errmsgs();
extern void wait_for_free_space(const char *filename, int errors);
extern FILE *my_fopen(const char *FileName,int Flags,myf MyFlags);
extern FILE *my_fdopen(File Filedes,const char *name, int Flags,myf MyFlags);
extern int my_fclose(FILE *fd,myf MyFlags);
+extern File my_fileno(FILE *fd);
extern int my_chsize(File fd,my_off_t newlength, int filler, myf MyFlags);
extern int my_sync(File fd, myf my_flags);
extern int my_sync_dir(const char *dir_name, myf my_flags);
extern int my_sync_dir_by_file(const char *file_name, myf my_flags);
-extern int my_error _VARARGS((int nr,myf MyFlags, ...));
-extern int my_printf_error _VARARGS((uint my_err, const char *format,
- myf MyFlags, ...))
- ATTRIBUTE_FORMAT(printf, 2, 4);
-extern int my_error_register(const char **errmsgs, int first, int last);
+extern void my_error(int nr,myf MyFlags, ...);
+extern void my_printf_error(uint my_err, const char *format,
+ myf MyFlags, ...)
+ ATTRIBUTE_FORMAT(printf, 2, 4);
+extern void my_printv_error(uint error, const char *format, myf MyFlags,
+ va_list ap);
+extern int my_error_register(const char** (*get_errmsgs) (),
+ int first, int last);
extern const char **my_error_unregister(int first, int last);
-extern int my_message(uint my_err, const char *str,myf MyFlags);
-extern int my_message_no_curses(uint my_err, const char *str,myf MyFlags);
-extern int my_message_curses(uint my_err, const char *str,myf MyFlags);
+extern void my_message(uint my_err, const char *str,myf MyFlags);
+extern void my_message_stderr(uint my_err, const char *str, myf MyFlags);
+extern my_bool my_basic_init(void);
extern my_bool my_init(void);
extern void my_end(int infoflag);
extern int my_redel(const char *from, const char *to, int MyFlags);
@@ -730,9 +700,6 @@ extern char * my_load_path(char * to, const char *path,
const char *own_path_prefix);
extern int wild_compare(const char *str,const char *wildstr,
pbool str_is_pattern);
-extern WF_PACK *wf_comp(char * str);
-extern int wf_test(struct wild_file_pack *wf_pack,const char *name);
-extern void wf_end(struct wild_file_pack *buffer);
extern my_bool array_append_string_unique(const char *str,
const char **array, size_t size);
extern void get_date(char * to,int timeflag,time_t use_time);
@@ -746,8 +713,6 @@ extern int end_record_cache(RECORD_CACHE *info);
extern int write_cache_record(RECORD_CACHE *info,my_off_t filepos,
const uchar *record,size_t length);
extern int flush_write_cache(RECORD_CACHE *info);
-extern long my_clock(void);
-extern sig_handler sigtstp_handler(int signal_number);
extern void handle_recived_signals(void);
extern sig_handler my_set_alarm_variable(int signo);
@@ -803,18 +768,16 @@ extern my_bool real_open_cached_file(IO_CACHE *cache);
extern void close_cached_file(IO_CACHE *cache);
File create_temp_file(char *to, const char *dir, const char *pfx,
int mode, myf MyFlags);
-#define my_init_dynamic_array(A,B,C,D) init_dynamic_array2(A,B,NULL,C,D CALLER_INFO)
-#define my_init_dynamic_array_ci(A,B,C,D) init_dynamic_array2(A,B,NULL,C,D ORIG_CALLER_INFO)
-#define my_init_dynamic_array2(A,B,C,D,E) init_dynamic_array2(A,B,C,D,E CALLER_INFO)
-#define my_init_dynamic_array2_ci(A,B,C,D,E) init_dynamic_array2(A,B,C,D,E ORIG_CALLER_INFO)
-extern my_bool init_dynamic_array2(DYNAMIC_ARRAY *array,uint element_size,
- void *init_buffer, uint init_alloc,
- uint alloc_increment
- CALLER_INFO_PROTO);
+#define my_init_dynamic_array(A,B,C,D) init_dynamic_array2(A,B,NULL,C,D)
+#define my_init_dynamic_array_ci(A,B,C,D) init_dynamic_array2(A,B,NULL,C,D)
+#define my_init_dynamic_array2(A,B,C,D,E) init_dynamic_array2(A,B,C,D,E)
+#define my_init_dynamic_array2_ci(A,B,C,D,E) init_dynamic_array2(A,B,C,D,E)
+extern my_bool init_dynamic_array2(DYNAMIC_ARRAY *array, uint element_size,
+ void *init_buffer, uint init_alloc,
+ uint alloc_increment);
/* init_dynamic_array() function is deprecated */
-extern my_bool init_dynamic_array(DYNAMIC_ARRAY *array,uint element_size,
- uint init_alloc,uint alloc_increment
- CALLER_INFO_PROTO);
+extern my_bool init_dynamic_array(DYNAMIC_ARRAY *array, uint element_size,
+ uint init_alloc, uint alloc_increment);
extern my_bool insert_dynamic(DYNAMIC_ARRAY *array,uchar * element);
extern uchar *alloc_dynamic(DYNAMIC_ARRAY *array);
extern uchar *pop_dynamic(DYNAMIC_ARRAY*);
@@ -844,10 +807,10 @@ extern my_bool dynstr_trunc(DYNAMIC_STRING *str, size_t n);
extern void dynstr_free(DYNAMIC_STRING *str);
#ifdef HAVE_MLOCK
extern void *my_malloc_lock(size_t length,myf flags);
-extern void my_free_lock(void *ptr,myf flags);
+extern void my_free_lock(void *ptr);
#else
#define my_malloc_lock(A,B) my_malloc((A),(B))
-#define my_free_lock(A,B) my_free((A),(B))
+#define my_free_lock(A) my_free((A))
#endif
#define alloc_root_inited(A) ((A)->min_malloc != 0)
#define ALLOC_ROOT_MIN_BLOCK_SIZE (MALLOC_OVERHEAD + sizeof(USED_MEM) + 8)
@@ -861,18 +824,20 @@ extern void set_prealloc_root(MEM_ROOT *root, char *ptr);
extern void reset_root_defaults(MEM_ROOT *mem_root, size_t block_size,
size_t prealloc_size);
extern char *strdup_root(MEM_ROOT *root,const char *str);
+static inline char *safe_strdup_root(MEM_ROOT *root, const char *str)
+{
+ return str ? strdup_root(root, str) : 0;
+}
extern char *strmake_root(MEM_ROOT *root,const char *str,size_t len);
extern void *memdup_root(MEM_ROOT *root,const void *str, size_t len);
extern int get_defaults_options(int argc, char **argv,
char **defaults, char **extra_defaults,
char **group_suffix);
+extern const char *args_separator;
extern int my_load_defaults(const char *conf_file, const char **groups,
int *argc, char ***argv, const char ***);
extern int load_defaults(const char *conf_file, const char **groups,
int *argc, char ***argv);
-extern int modify_defaults_file(const char *file_location, const char *option,
- const char *option_value,
- const char *section_name, int remove_option);
extern int my_search_option_files(const char *conf_file, int *argc,
char ***argv, uint *args_used,
Process_option_func func, void *func_ctx,
@@ -930,10 +895,7 @@ extern int my_getncpus();
#define MAP_FAILED ((void *)-1)
#define MS_SYNC 0x0000
-#ifndef __NETWARE__
#define HAVE_MMAP
-#endif
-
void *my_mmap(void *, size_t, int, int, int, my_off_t);
int my_munmap(void *, size_t);
#endif
@@ -998,10 +960,16 @@ void my_security_attr_free(SECURITY_ATTRIBUTES *sa);
char* my_cgets(char *string, size_t clen, size_t* plen);
#endif
-#ifdef __NETWARE__
-void netware_reg_user(const char *ip, const char *user,
- const char *application);
+
+#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/my_time.h b/include/my_time.h
index 58995f1bf62..fdfe130c45f 100644
--- a/include/my_time.h
+++ b/include/my_time.h
@@ -35,8 +35,6 @@ extern uchar days_in_month[];
Using the system built in time_t is not an option as
we rely on the above requirements in the time functions
-
- For example QNX has an unsigned time_t type
*/
typedef long my_time_t;
@@ -74,12 +72,12 @@ typedef long my_time_t;
TIME_MAX_MINUTE * 60L + TIME_MAX_SECOND)
my_bool check_date(const MYSQL_TIME *ltime, my_bool not_zero_date,
- ulong flags, int *was_cut);
+ ulonglong flags, int *was_cut);
enum enum_mysql_timestamp_type
str_to_datetime(const char *str, uint length, MYSQL_TIME *l_time,
- uint flags, int *was_cut);
+ ulonglong flags, int *was_cut);
longlong number_to_datetime(longlong nr, MYSQL_TIME *time_res,
- uint flags, int *was_cut);
+ ulonglong flags, int *was_cut);
ulonglong TIME_to_ulonglong_datetime(const MYSQL_TIME *);
ulonglong TIME_to_ulonglong_date(const MYSQL_TIME *);
ulonglong TIME_to_ulonglong_time(const MYSQL_TIME *);
diff --git a/include/my_tree.h b/include/my_tree.h
index 24bbdd54019..0958a37fb4c 100644
--- a/include/my_tree.h
+++ b/include/my_tree.h
@@ -20,6 +20,7 @@ extern "C" {
#endif
#include "my_base.h" /* get 'enum ha_rkey_function' */
+#include "my_alloc.h" /* MEM_ROOT */
/* Worst case tree is half full. This gives use 2^(MAX_TREE_HEIGHT/2) leafs */
#define MAX_TREE_HEIGHT 64
diff --git a/include/my_trie.h b/include/my_trie.h
deleted file mode 100644
index 72dd485af04..00000000000
--- a/include/my_trie.h
+++ /dev/null
@@ -1,141 +0,0 @@
-/* Copyright (C) 2005 MySQL AB
-
- 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 _trie_h
-#define _trie_h
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef struct st_trie_node
-{
- uint16 leaf; /* Depth from root node if match, 0 else */
- uchar c; /* Label on this edge */
- struct st_trie_node *next; /* Next label */
- struct st_trie_node *links; /* Array of edges leaving this node */
- struct st_trie_node *fail; /* AC failure function */
-} TRIE_NODE;
-
-typedef struct st_trie
-{
- TRIE_NODE root;
- MEM_ROOT mem_root;
- CHARSET_INFO *charset;
- uint32 nnodes;
- uint32 nwords;
-} TRIE;
-
-typedef struct st_ac_trie_state
-{
- TRIE *trie;
- TRIE_NODE *node;
-} AC_TRIE_STATE;
-
-extern TRIE *trie_init (TRIE *trie, CHARSET_INFO *charset);
-extern void trie_free (TRIE *trie);
-extern my_bool trie_insert (TRIE *trie, const uchar *key, uint keylen);
-extern my_bool ac_trie_prepare (TRIE *trie);
-extern void ac_trie_init (TRIE *trie, AC_TRIE_STATE *state);
-
-
-/* `trie_goto' is internal function and shouldn't be used. */
-
-static inline TRIE_NODE *trie_goto (TRIE_NODE *root, TRIE_NODE *node, uchar c)
-{
- TRIE_NODE *next;
- DBUG_ENTER("trie_goto");
- for (next= node->links; next; next= next->next)
- if (next->c == c)
- DBUG_RETURN(next);
- if (root == node)
- DBUG_RETURN(root);
- DBUG_RETURN(NULL);
-}
-
-
-/*
- SYNOPSIS
- int ac_trie_next (AC_TRIE_STATE *state, uchar *c);
- state - valid pointer to `AC_TRIE_STATE'
- c - character to lookup
-
- DESCRIPTION
- Implementation of search using Aho-Corasick automaton.
- Performs char-by-char search.
-
- RETURN VALUE
- `ac_trie_next' returns length of matched word or 0.
-*/
-
-static inline int ac_trie_next (AC_TRIE_STATE *state, uchar *c)
-{
- TRIE_NODE *root, *node;
- DBUG_ENTER("ac_trie_next");
- DBUG_ASSERT(state && c);
- root= &state->trie->root;
- node= state->node;
- while (! (state->node= trie_goto(root, node, *c)))
- node= node->fail;
- DBUG_RETURN(state->node->leaf);
-}
-
-
-/*
- SYNOPSIS
- my_bool trie_search (TRIE *trie, const uchar *key, uint keylen);
- trie - valid pointer to `TRIE'
- key - valid pointer to key to insert
- keylen - non-0 key length
-
- DESCRIPTION
- Performs key lookup in trie.
-
- RETURN VALUE
- `trie_search' returns `true' if key is in `trie'. Otherwise,
- `false' is returned.
-
- NOTES
- Consecutive search here is "best by test". arrays are very short, so
- binary search or hashing would add too much complexity that would
- overweight speed gain. Especially because compiler can optimize simple
- consecutive loop better (tested)
-*/
-
-static inline my_bool trie_search (TRIE *trie, const uchar *key, uint keylen)
-{
- TRIE_NODE *node;
- uint k;
- DBUG_ENTER("trie_search");
- DBUG_ASSERT(trie && key && keylen);
- node= &trie->root;
-
- for (k= 0; k < keylen; k++)
- {
- uchar p;
- if (! (node= node->links))
- DBUG_RETURN(FALSE);
- p= key[k];
- while (p != node->c)
- if (! (node= node->next))
- DBUG_RETURN(FALSE);
- }
-
- DBUG_RETURN(node->leaf > 0);
-}
-
-#ifdef __cplusplus
-}
-#endif
-#endif
diff --git a/include/my_uctype.h b/include/my_uctype.h
index 9aaf478810c..580eb646e11 100644
--- a/include/my_uctype.h
+++ b/include/my_uctype.h
@@ -1,3 +1,6 @@
+#ifndef MY_UCTYPE_INCLUDED
+#define MY_UCTYPE_INCLUDED
+
/* Copyright (C) 2006 MySQL AB
This program is free software; you can redistribute it and/or modify
@@ -1477,3 +1480,4 @@ MY_UNI_CTYPE my_uni_ctype[256]={
};
+#endif /* MY_UCTYPE_INCLUDED */
diff --git a/include/my_vle.h b/include/my_vle.h
deleted file mode 100644
index c09f82229c4..00000000000
--- a/include/my_vle.h
+++ /dev/null
@@ -1,38 +0,0 @@
-/* Copyright (C) 2005 MySQL AB
-
- 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 VLE_H
-#define VLE_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include "my_global.h"
-
-/*
- The size (in bytes) required to store the object ITEM, which can be
- either an expression or a type (since sizeof() is used on the item).
-*/
-#define my_vle_sizeof(ITEM) (((sizeof(ITEM) * CHAR_BIT) + 6) / 7)
-
-uchar *my_vle_encode(uchar *vle, size_t max, ulong value);
-uchar const *my_vle_decode(ulong *value_ptr, uchar const *vle);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/include/myisam.h b/include/myisam.h
index e502daa2f17..c4076ead403 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
@@ -160,7 +160,7 @@ typedef struct st_mi_create_info
ulonglong data_file_length;
ulonglong key_file_length;
uint old_options;
- uint8 language;
+ uint16 language;
my_bool with_auto_increment;
} MI_CREATE_INFO;
@@ -252,13 +252,13 @@ extern ulong myisam_block_size;
extern ulong myisam_concurrent_insert;
extern my_bool myisam_flush,myisam_delay_key_write,myisam_single_user;
extern my_off_t myisam_max_temp_length;
-extern ulong myisam_bulk_insert_tree_size, myisam_data_pointer_size;
+extern ulong myisam_data_pointer_size;
/* usually used to check if a symlink points into the mysql data home */
/* which is normally forbidden */
extern int (*myisam_test_invalid_symlink)(const char *filename);
extern ulonglong myisam_mmap_size, myisam_mmap_used;
-extern pthread_mutex_t THR_LOCK_myisam_mmap;
+extern mysql_mutex_t THR_LOCK_myisam_mmap;
/* Prototypes for myisam-functions */
@@ -411,7 +411,7 @@ typedef struct st_mi_check_param
uint out_flag,warning_printed,error_printed,verbose;
uint opt_sort_key,total_files,max_level;
uint testflag, key_cache_block_size;
- uint8 language;
+ uint16 language;
my_bool using_global_keycache, opt_lock_memory, opt_follow_links;
my_bool retry_repair, force_sort;
char temp_filename[FN_REFLEN],*isam_file_name;
@@ -434,7 +434,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;
@@ -461,8 +461,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;
@@ -481,8 +481,7 @@ int mi_repair_by_sort(MI_CHECK *param, register MI_INFO *info,
int mi_repair_parallel(MI_CHECK *param, register MI_INFO *info,
const char * name, int rep_quick);
int change_to_newfile(const char * filename, const char * old_ext,
- const char * new_ext, uint raid_chunks,
- myf myflags);
+ const char * new_ext, myf myflags);
int lock_file(MI_CHECK *param, File file, my_off_t start, int lock_type,
const char *filetype, const char *filename);
void lock_memory(MI_CHECK *param);
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/myisampack.h b/include/myisampack.h
index 7d4871bd1cb..ecf35520a88 100644
--- a/include/myisampack.h
+++ b/include/myisampack.h
@@ -1,3 +1,6 @@
+#ifndef MYISAMPACK_INCLUDED
+#define MYISAMPACK_INCLUDED
+
/* Copyright (C) 2000 MySQL AB
This program is free software; you can redistribute it and/or modify
@@ -236,3 +239,4 @@
mi_int4store(((T) + 4), A); }}
#define mi_sizekorr(T) mi_uint4korr((uchar*) (T) + 4)
#endif
+#endif /* MYISAMPACK_INCLUDED */
diff --git a/include/mysql.h b/include/mysql.h
index 699bd1f1b7f..d3b24f0198a 100644
--- a/include/mysql.h
+++ b/include/mysql.h
@@ -17,11 +17,10 @@
This file defines the client API to MySQL and also the ABI of the
dynamically linked libmysqlclient.
- The ABI should never be changed in a released product of MySQL
+ The ABI should never be changed in a released product of MySQL,
thus you need to take great care when changing the file. In case
- the file is changed so the ABI is broken, you must also
- update the SHAREDLIB_MAJOR_VERSION in configure.in .
-
+ the file is changed so the ABI is broken, you must also update
+ the SHARED_LIB_MAJOR_VERSION in cmake/mysql_version.cmake
*/
#ifndef _mysql_h
@@ -81,16 +80,14 @@ extern char *mysql_unix_port;
#define CLIENT_NET_READ_TIMEOUT 365*24*3600 /* Timeout on read */
#define CLIENT_NET_WRITE_TIMEOUT 365*24*3600 /* Timeout on write */
-#ifdef __NETWARE__
-#pragma pack(push, 8) /* 8 byte alignment */
-#endif
-
#define IS_PRI_KEY(n) ((n) & PRI_KEY_FLAG)
#define IS_NOT_NULL(n) ((n) & NOT_NULL_FLAG)
#define IS_BLOB(n) ((n) & BLOB_FLAG)
-#define IS_NUM(t) ((t) <= MYSQL_TYPE_INT24 || (t) == MYSQL_TYPE_YEAR || (t) == MYSQL_TYPE_NEWDECIMAL)
-#define IS_NUM_FIELD(f) ((f)->flags & NUM_FLAG)
-#define INTERNAL_NUM_FIELD(f) (((f)->type <= MYSQL_TYPE_INT24 && ((f)->type != MYSQL_TYPE_TIMESTAMP || (f)->length == 14 || (f)->length == 8)) || (f)->type == MYSQL_TYPE_YEAR)
+/**
+ Returns true if the value is a number which does not need quotes for
+ the sql_lex.cc parser to parse correctly.
+*/
+#define IS_NUM(t) (((t) <= MYSQL_TYPE_INT24 && (t) != MYSQL_TYPE_TIMESTAMP) || (t) == MYSQL_TYPE_YEAR || (t) == MYSQL_TYPE_NEWDECIMAL)
#define IS_LONGDATA(t) ((t) >= MYSQL_TYPE_TINY_BLOB && (t) <= MYSQL_TYPE_STRING)
@@ -169,9 +166,15 @@ enum mysql_option
MYSQL_OPT_USE_REMOTE_CONNECTION, MYSQL_OPT_USE_EMBEDDED_CONNECTION,
MYSQL_OPT_GUESS_CONNECTION, MYSQL_SET_CLIENT_IP, MYSQL_SECURE_AUTH,
MYSQL_REPORT_DATA_TRUNCATION, MYSQL_OPT_RECONNECT,
- MYSQL_OPT_SSL_VERIFY_SERVER_CERT
+ MYSQL_OPT_SSL_VERIFY_SERVER_CERT, MYSQL_PLUGIN_DIR, MYSQL_DEFAULT_AUTH
};
+/**
+ @todo remove the "extension", move st_mysql_options completely
+ out of mysql.h
+*/
+struct st_mysql_options_extention;
+
struct st_mysql_options {
unsigned int connect_timeout, read_timeout, write_timeout;
unsigned int port, protocol;
@@ -188,24 +191,10 @@ struct st_mysql_options {
unsigned long max_allowed_packet;
my_bool use_ssl; /* if to use SSL or not */
my_bool compress,named_pipe;
- /*
- On connect, find out the replication role of the server, and
- establish connections to all the peers
- */
- my_bool rpl_probe;
- /*
- Each call to mysql_real_query() will parse it to tell if it is a read
- or a write, and direct it to the slave or the master
- */
- my_bool rpl_parse;
- /*
- If set, never read from a master, only from slave, when doing
- a read that is replication-aware
- */
- my_bool no_master_reads;
-#if !defined(CHECK_EMBEDDED_DIFFERENCES) || defined(EMBEDDED_LIBRARY)
- my_bool separate_thread;
-#endif
+ my_bool unused1;
+ my_bool unused2;
+ my_bool unused3;
+ my_bool unused4;
enum mysql_option methods_to_use;
char *client_ip;
/* Refuse client connecting to server if it uses old (pre-4.1.1) protocol */
@@ -219,7 +208,7 @@ struct st_mysql_options {
void (*local_infile_end)(void *);
int (*local_infile_error)(void *, char *, unsigned int);
void *local_infile_userdata;
- void *extension;
+ struct st_mysql_options_extention *extension;
};
enum mysql_status
@@ -233,15 +222,6 @@ enum mysql_protocol_type
MYSQL_PROTOCOL_DEFAULT, MYSQL_PROTOCOL_TCP, MYSQL_PROTOCOL_SOCKET,
MYSQL_PROTOCOL_PIPE, MYSQL_PROTOCOL_MEMORY
};
-/*
- There are three types of queries - the ones that have to go to
- the master, the ones that go to a slave, and the adminstrative
- type which must happen on the pivot connectioin
-*/
-enum mysql_rpl_type
-{
- MYSQL_RPL_MASTER, MYSQL_RPL_SLAVE, MYSQL_RPL_ADMIN
-};
typedef struct character_set
{
@@ -286,21 +266,8 @@ typedef struct st_mysql
/* session-wide random string */
char scramble[SCRAMBLE_LENGTH+1];
-
- /*
- Set if this is the original connection, not a master or a slave we have
- added though mysql_rpl_probe() or mysql_set_master()/ mysql_add_slave()
- */
- my_bool rpl_pivot;
- /*
- Pointers to the master, and the next slave connections, points to
- itself if lone connection.
- */
- struct st_mysql* master, *next_slave;
-
- struct st_mysql* last_used_slave; /* needed for round-robin slave pick */
- /* needed for send/read/store/use result to work correctly with replication */
- struct st_mysql* last_used_con;
+ my_bool unused1;
+ void *unused2, *unused3, *unused4, *unused5;
LIST *stmts; /* list of all statements */
const struct st_mysql_methods *methods;
@@ -334,35 +301,12 @@ typedef struct st_mysql_res {
void *extension;
} MYSQL_RES;
-#define MAX_MYSQL_MANAGER_ERR 256
-#define MAX_MYSQL_MANAGER_MSG 256
-
-#define MANAGER_OK 200
-#define MANAGER_INFO 250
-#define MANAGER_ACCESS 401
-#define MANAGER_CLIENT_ERR 450
-#define MANAGER_INTERNAL_ERR 500
#if !defined(MYSQL_SERVER) && !defined(MYSQL_CLIENT)
#define MYSQL_CLIENT
#endif
-typedef struct st_mysql_manager
-{
- NET net;
- char *host, *user, *passwd;
- char *net_buf, *net_buf_pos, *net_data_end;
- unsigned int port;
- int cmd_status;
- int last_errno;
- int net_buf_size;
- my_bool free_me;
- my_bool eof;
- char last_error[MAX_MYSQL_MANAGER_ERR];
- void *extension;
-} MYSQL_MANAGER;
-
typedef struct st_mysql_parameters
{
unsigned long *p_max_allowed_packet;
@@ -455,16 +399,6 @@ int STDCALL mysql_real_query(MYSQL *mysql, const char *q,
MYSQL_RES * STDCALL mysql_store_result(MYSQL *mysql);
MYSQL_RES * STDCALL mysql_use_result(MYSQL *mysql);
-/* perform query on master */
-my_bool STDCALL mysql_master_query(MYSQL *mysql, const char *q,
- unsigned long length);
-my_bool STDCALL mysql_master_send_query(MYSQL *mysql, const char *q,
- unsigned long length);
-/* perform query on slave */
-my_bool STDCALL mysql_slave_query(MYSQL *mysql, const char *q,
- unsigned long length);
-my_bool STDCALL mysql_slave_send_query(MYSQL *mysql, const char *q,
- unsigned long length);
void STDCALL mysql_get_character_set_info(MYSQL *mysql,
MY_CHARSET_INFO *charset);
@@ -486,37 +420,6 @@ mysql_set_local_infile_handler(MYSQL *mysql,
void
mysql_set_local_infile_default(MYSQL *mysql);
-
-/*
- enable/disable parsing of all queries to decide if they go on master or
- slave
-*/
-void STDCALL mysql_enable_rpl_parse(MYSQL* mysql);
-void STDCALL mysql_disable_rpl_parse(MYSQL* mysql);
-/* get the value of the parse flag */
-int STDCALL mysql_rpl_parse_enabled(MYSQL* mysql);
-
-/* enable/disable reads from master */
-void STDCALL mysql_enable_reads_from_master(MYSQL* mysql);
-void STDCALL mysql_disable_reads_from_master(MYSQL* mysql);
-/* get the value of the master read flag */
-my_bool STDCALL mysql_reads_from_master_enabled(MYSQL* mysql);
-
-enum mysql_rpl_type STDCALL mysql_rpl_query_type(const char* q, int len);
-
-/* discover the master and its slaves */
-my_bool STDCALL mysql_rpl_probe(MYSQL* mysql);
-
-/* set the master, close/free the old one, if it is not a pivot */
-int STDCALL mysql_set_master(MYSQL* mysql, const char* host,
- unsigned int port,
- const char* user,
- const char* passwd);
-int STDCALL mysql_add_slave(MYSQL* mysql, const char* host,
- unsigned int port,
- const char* user,
- const char* passwd);
-
int STDCALL mysql_shutdown(MYSQL *mysql,
enum mysql_enum_shutdown_level
shutdown_level);
@@ -563,18 +466,6 @@ void STDCALL mysql_debug(const char *debug);
void STDCALL myodbc_remove_escape(MYSQL *mysql,char *name);
unsigned int STDCALL mysql_thread_safe(void);
my_bool STDCALL mysql_embedded(void);
-MYSQL_MANAGER* STDCALL mysql_manager_init(MYSQL_MANAGER* con);
-MYSQL_MANAGER* STDCALL mysql_manager_connect(MYSQL_MANAGER* con,
- const char* host,
- const char* user,
- const char* passwd,
- unsigned int port);
-void STDCALL mysql_manager_close(MYSQL_MANAGER* con);
-int STDCALL mysql_manager_command(MYSQL_MANAGER* con,
- const char* cmd, int cmd_len);
-int STDCALL mysql_manager_fetch_line(MYSQL_MANAGER* con,
- char* res_buf,
- int res_buf_size);
my_bool STDCALL mysql_read_query_result(MYSQL *mysql);
@@ -753,38 +644,6 @@ enum enum_stmt_attr_type
};
-typedef struct st_mysql_methods
-{
- my_bool (*read_query_result)(MYSQL *mysql);
- my_bool (*advanced_command)(MYSQL *mysql,
- enum enum_server_command command,
- const unsigned char *header,
- unsigned long header_length,
- const unsigned char *arg,
- unsigned long arg_length,
- my_bool skip_check,
- MYSQL_STMT *stmt);
- MYSQL_DATA *(*read_rows)(MYSQL *mysql,MYSQL_FIELD *mysql_fields,
- unsigned int fields);
- MYSQL_RES * (*use_result)(MYSQL *mysql);
- void (*fetch_lengths)(unsigned long *to,
- MYSQL_ROW column, unsigned int field_count);
- void (*flush_use_result)(MYSQL *mysql);
-#if !defined(MYSQL_SERVER) || defined(EMBEDDED_LIBRARY)
- MYSQL_FIELD * (*list_fields)(MYSQL *mysql);
- my_bool (*read_prepare_result)(MYSQL *mysql, MYSQL_STMT *stmt);
- int (*stmt_execute)(MYSQL_STMT *stmt);
- int (*read_binary_rows)(MYSQL_STMT *stmt);
- int (*unbuffered_fetch)(MYSQL *mysql, char **row);
- void (*free_embedded_thd)(MYSQL *mysql);
- const char *(*read_statistics)(MYSQL *mysql);
- my_bool (*next_result)(MYSQL *mysql);
- int (*read_change_user_result)(MYSQL *mysql, char *buff, const char *passwd);
- int (*read_rows_from_cursor)(MYSQL_STMT *stmt);
-#endif
-} MYSQL_METHODS;
-
-
MYSQL_STMT * STDCALL mysql_stmt_init(MYSQL *mysql);
int STDCALL mysql_stmt_prepare(MYSQL_STMT *stmt, const char *query,
unsigned long length);
@@ -829,6 +688,7 @@ my_bool STDCALL mysql_rollback(MYSQL * mysql);
my_bool STDCALL mysql_autocommit(MYSQL * mysql, my_bool auto_mode);
my_bool STDCALL mysql_more_results(MYSQL *mysql);
int STDCALL mysql_next_result(MYSQL *mysql);
+int STDCALL mysql_stmt_next_result(MYSQL_STMT *stmt);
void STDCALL mysql_close(MYSQL *sock);
@@ -843,26 +703,9 @@ MYSQL * STDCALL mysql_connect(MYSQL *mysql, const char *host,
const char *user, const char *passwd);
int STDCALL mysql_create_db(MYSQL *mysql, const char *DB);
int STDCALL mysql_drop_db(MYSQL *mysql, const char *DB);
-#define mysql_reload(mysql) mysql_refresh((mysql),REFRESH_GRANT)
#endif
#define HAVE_MYSQL_REAL_CONNECT
-/*
- The following functions are mainly exported because of mysqlbinlog;
- They are not for general usage
-*/
-
-#define simple_command(mysql, command, arg, length, skip_check) \
- (*(mysql)->methods->advanced_command)(mysql, command, 0, \
- 0, arg, length, skip_check, NULL)
-#define stmt_command(mysql, command, arg, length, stmt) \
- (*(mysql)->methods->advanced_command)(mysql, command, 0, \
- 0, arg, length, 1, stmt)
-
-#ifdef __NETWARE__
-#pragma pack(pop) /* restore alignment */
-#endif
-
#ifdef __cplusplus
}
#endif
diff --git a/include/mysql.h.pp b/include/mysql.h.pp
index ceb4b2d591c..0a5c3d83148 100644
--- a/include/mysql.h.pp
+++ b/include/mysql.h.pp
@@ -27,15 +27,15 @@ typedef struct st_net {
unsigned int *return_status;
unsigned char reading_or_writing;
char save_char;
- my_bool unused0;
- my_bool unused;
- my_bool compress;
my_bool unused1;
- unsigned char *query_cache_query;
+ my_bool unused2;
+ my_bool compress;
+ my_bool unused3;
+ unsigned char *unused;
unsigned int last_errno;
unsigned char error;
- my_bool unused2;
- my_bool return_errno;
+ my_bool unused4;
+ my_bool unused5;
char last_error[512];
char sqlstate[5 +1];
void *extension;
@@ -130,13 +130,13 @@ void create_random_string(char *to, unsigned int length, struct rand_struct *ran
void hash_password(unsigned long *to, const char *password, unsigned int password_len);
void make_scrambled_password_323(char *to, const char *password);
void scramble_323(char *to, const char *message, const char *password);
-my_bool check_scramble_323(const char *, const char *message,
+my_bool check_scramble_323(const unsigned char *reply, const char *message,
unsigned long *salt);
void get_salt_from_password_323(unsigned long *res, const char *password);
void make_password_from_salt_323(char *to, const unsigned long *salt);
void make_scrambled_password(char *to, const char *password);
void scramble(char *to, const char *message, const char *password);
-my_bool check_scramble(const char *reply, const char *message,
+my_bool check_scramble(const unsigned char *reply, const char *message,
const unsigned char *hash_stage2);
void get_salt_from_password(unsigned char *res, const char *password);
void make_password_from_salt(char *to, const unsigned char *hash_stage2);
@@ -232,6 +232,10 @@ extern void make_type(char *to,unsigned int nr,TYPELIB *typelib);
extern const char *get_type(TYPELIB *typelib,unsigned int nr);
extern TYPELIB *copy_typelib(MEM_ROOT *root, TYPELIB *from);
extern TYPELIB sql_protocol_typelib;
+my_ulonglong find_set_from_flags(const TYPELIB *lib, unsigned int default_name,
+ my_ulonglong cur_set, my_ulonglong default_set,
+ const char *str, unsigned int length,
+ char **err_pos, unsigned int *err_len);
typedef struct st_mysql_rows {
struct st_mysql_rows *next;
MYSQL_ROW data;
@@ -258,8 +262,9 @@ enum mysql_option
MYSQL_OPT_USE_REMOTE_CONNECTION, MYSQL_OPT_USE_EMBEDDED_CONNECTION,
MYSQL_OPT_GUESS_CONNECTION, MYSQL_SET_CLIENT_IP, MYSQL_SECURE_AUTH,
MYSQL_REPORT_DATA_TRUNCATION, MYSQL_OPT_RECONNECT,
- MYSQL_OPT_SSL_VERIFY_SERVER_CERT
+ MYSQL_OPT_SSL_VERIFY_SERVER_CERT, MYSQL_PLUGIN_DIR, MYSQL_DEFAULT_AUTH
};
+struct st_mysql_options_extention;
struct st_mysql_options {
unsigned int connect_timeout, read_timeout, write_timeout;
unsigned int port, protocol;
@@ -276,10 +281,10 @@ struct st_mysql_options {
unsigned long max_allowed_packet;
my_bool use_ssl;
my_bool compress,named_pipe;
- my_bool rpl_probe;
- my_bool rpl_parse;
- my_bool no_master_reads;
- my_bool separate_thread;
+ my_bool unused1;
+ my_bool unused2;
+ my_bool unused3;
+ my_bool unused4;
enum mysql_option methods_to_use;
char *client_ip;
my_bool secure_auth;
@@ -289,7 +294,7 @@ struct st_mysql_options {
void (*local_infile_end)(void *);
int (*local_infile_error)(void *, char *, unsigned int);
void *local_infile_userdata;
- void *extension;
+ struct st_mysql_options_extention *extension;
};
enum mysql_status
{
@@ -301,10 +306,6 @@ enum mysql_protocol_type
MYSQL_PROTOCOL_DEFAULT, MYSQL_PROTOCOL_TCP, MYSQL_PROTOCOL_SOCKET,
MYSQL_PROTOCOL_PIPE, MYSQL_PROTOCOL_MEMORY
};
-enum mysql_rpl_type
-{
- MYSQL_RPL_MASTER, MYSQL_RPL_SLAVE, MYSQL_RPL_ADMIN
-};
typedef struct character_set
{
unsigned int number;
@@ -344,10 +345,8 @@ typedef struct st_mysql
my_bool free_me;
my_bool reconnect;
char scramble[20 +1];
- my_bool rpl_pivot;
- struct st_mysql* master, *next_slave;
- struct st_mysql* last_used_slave;
- struct st_mysql* last_used_con;
+ my_bool unused1;
+ void *unused2, *unused3, *unused4, *unused5;
LIST *stmts;
const struct st_mysql_methods *methods;
void *thd;
@@ -371,20 +370,6 @@ typedef struct st_mysql_res {
my_bool unbuffered_fetch_cancelled;
void *extension;
} MYSQL_RES;
-typedef struct st_mysql_manager
-{
- NET net;
- char *host, *user, *passwd;
- char *net_buf, *net_buf_pos, *net_data_end;
- unsigned int port;
- int cmd_status;
- int last_errno;
- int net_buf_size;
- my_bool free_me;
- my_bool eof;
- char last_error[256];
- void *extension;
-} MYSQL_MANAGER;
typedef struct st_mysql_parameters
{
unsigned long *p_max_allowed_packet;
@@ -437,14 +422,6 @@ int mysql_real_query(MYSQL *mysql, const char *q,
unsigned long length);
MYSQL_RES * mysql_store_result(MYSQL *mysql);
MYSQL_RES * mysql_use_result(MYSQL *mysql);
-my_bool mysql_master_query(MYSQL *mysql, const char *q,
- unsigned long length);
-my_bool mysql_master_send_query(MYSQL *mysql, const char *q,
- unsigned long length);
-my_bool mysql_slave_query(MYSQL *mysql, const char *q,
- unsigned long length);
-my_bool mysql_slave_send_query(MYSQL *mysql, const char *q,
- unsigned long length);
void mysql_get_character_set_info(MYSQL *mysql,
MY_CHARSET_INFO *charset);
void
@@ -459,22 +436,6 @@ mysql_set_local_infile_handler(MYSQL *mysql,
void *);
void
mysql_set_local_infile_default(MYSQL *mysql);
-void mysql_enable_rpl_parse(MYSQL* mysql);
-void mysql_disable_rpl_parse(MYSQL* mysql);
-int mysql_rpl_parse_enabled(MYSQL* mysql);
-void mysql_enable_reads_from_master(MYSQL* mysql);
-void mysql_disable_reads_from_master(MYSQL* mysql);
-my_bool mysql_reads_from_master_enabled(MYSQL* mysql);
-enum mysql_rpl_type mysql_rpl_query_type(const char* q, int len);
-my_bool mysql_rpl_probe(MYSQL* mysql);
-int mysql_set_master(MYSQL* mysql, const char* host,
- unsigned int port,
- const char* user,
- const char* passwd);
-int mysql_add_slave(MYSQL* mysql, const char* host,
- unsigned int port,
- const char* user,
- const char* passwd);
int mysql_shutdown(MYSQL *mysql,
enum mysql_enum_shutdown_level
shutdown_level);
@@ -521,18 +482,6 @@ void mysql_debug(const char *debug);
void myodbc_remove_escape(MYSQL *mysql,char *name);
unsigned int mysql_thread_safe(void);
my_bool mysql_embedded(void);
-MYSQL_MANAGER* mysql_manager_init(MYSQL_MANAGER* con);
-MYSQL_MANAGER* mysql_manager_connect(MYSQL_MANAGER* con,
- const char* host,
- const char* user,
- const char* passwd,
- unsigned int port);
-void mysql_manager_close(MYSQL_MANAGER* con);
-int mysql_manager_command(MYSQL_MANAGER* con,
- const char* cmd, int cmd_len);
-int mysql_manager_fetch_line(MYSQL_MANAGER* con,
- char* res_buf,
- int res_buf_size);
my_bool mysql_read_query_result(MYSQL *mysql);
enum enum_mysql_stmt_state
{
@@ -600,34 +549,6 @@ enum enum_stmt_attr_type
STMT_ATTR_CURSOR_TYPE,
STMT_ATTR_PREFETCH_ROWS
};
-typedef struct st_mysql_methods
-{
- my_bool (*read_query_result)(MYSQL *mysql);
- my_bool (*advanced_command)(MYSQL *mysql,
- enum enum_server_command command,
- const unsigned char *header,
- unsigned long header_length,
- const unsigned char *arg,
- unsigned long arg_length,
- my_bool skip_check,
- MYSQL_STMT *stmt);
- MYSQL_DATA *(*read_rows)(MYSQL *mysql,MYSQL_FIELD *mysql_fields,
- unsigned int fields);
- MYSQL_RES * (*use_result)(MYSQL *mysql);
- void (*fetch_lengths)(unsigned long *to,
- MYSQL_ROW column, unsigned int field_count);
- void (*flush_use_result)(MYSQL *mysql);
- MYSQL_FIELD * (*list_fields)(MYSQL *mysql);
- my_bool (*read_prepare_result)(MYSQL *mysql, MYSQL_STMT *stmt);
- int (*stmt_execute)(MYSQL_STMT *stmt);
- int (*read_binary_rows)(MYSQL_STMT *stmt);
- int (*unbuffered_fetch)(MYSQL *mysql, char **row);
- void (*free_embedded_thd)(MYSQL *mysql);
- const char *(*read_statistics)(MYSQL *mysql);
- my_bool (*next_result)(MYSQL *mysql);
- int (*read_change_user_result)(MYSQL *mysql, char *buff, const char *passwd);
- int (*read_rows_from_cursor)(MYSQL_STMT *stmt);
-} MYSQL_METHODS;
MYSQL_STMT * mysql_stmt_init(MYSQL *mysql);
int mysql_stmt_prepare(MYSQL_STMT *stmt, const char *query,
unsigned long length);
@@ -671,4 +592,5 @@ my_bool mysql_rollback(MYSQL * mysql);
my_bool mysql_autocommit(MYSQL * mysql, my_bool auto_mode);
my_bool mysql_more_results(MYSQL *mysql);
int mysql_next_result(MYSQL *mysql);
+int mysql_stmt_next_result(MYSQL_STMT *stmt);
void mysql_close(MYSQL *sock);
diff --git a/include/mysql/client_plugin.h b/include/mysql/client_plugin.h
new file mode 100644
index 00000000000..cc3f468040f
--- /dev/null
+++ b/include/mysql/client_plugin.h
@@ -0,0 +1,163 @@
+#ifndef MYSQL_CLIENT_PLUGIN_INCLUDED
+/* Copyright (C) 2010 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 Client Plugin API
+
+ This file defines the API for plugins that work on the client side
+*/
+#define MYSQL_CLIENT_PLUGIN_INCLUDED
+
+#ifndef MYSQL_ABI_CHECK
+#include <stdarg.h>
+#include <stdlib.h>
+#endif
+
+/* known plugin types */
+#define MYSQL_CLIENT_reserved1 0
+#define MYSQL_CLIENT_reserved2 1
+#define MYSQL_CLIENT_AUTHENTICATION_PLUGIN 2
+
+#define MYSQL_CLIENT_AUTHENTICATION_PLUGIN_INTERFACE_VERSION 0x0100
+
+#define MYSQL_CLIENT_MAX_PLUGINS 3
+
+#define mysql_declare_client_plugin(X) \
+ MYSQL_PLUGIN_EXPORT struct st_mysql_client_plugin_ ## X \
+ _mysql_client_plugin_declaration_ = { \
+ MYSQL_CLIENT_ ## X ## _PLUGIN, \
+ MYSQL_CLIENT_ ## X ## _PLUGIN_INTERFACE_VERSION,
+#define mysql_end_client_plugin }
+
+/* generic plugin header structure */
+#define MYSQL_CLIENT_PLUGIN_HEADER \
+ int type; \
+ unsigned int interface_version; \
+ const char *name; \
+ const char *author; \
+ const char *desc; \
+ unsigned int version[3]; \
+ const char *license; \
+ void *mysql_api; \
+ int (*init)(char *, size_t, int, va_list); \
+ int (*deinit)(); \
+ int (*options)(const char *option, const void *);
+
+struct st_mysql_client_plugin
+{
+ MYSQL_CLIENT_PLUGIN_HEADER
+};
+
+struct st_mysql;
+
+/******** authentication plugin specific declarations *********/
+#include <mysql/plugin_auth_common.h>
+
+struct st_mysql_client_plugin_AUTHENTICATION
+{
+ MYSQL_CLIENT_PLUGIN_HEADER
+ int (*authenticate_user)(MYSQL_PLUGIN_VIO *vio, struct st_mysql *mysql);
+};
+
+/******** using plugins ************/
+
+/**
+ loads a plugin and initializes it
+
+ @param mysql MYSQL structure.
+ @param name a name of the plugin to load
+ @param type type of plugin that should be loaded, -1 to disable type check
+ @param argc number of arguments to pass to the plugin initialization
+ function
+ @param ... arguments for the plugin initialization function
+
+ @retval
+ a pointer to the loaded plugin, or NULL in case of a failure
+*/
+struct st_mysql_client_plugin *
+mysql_load_plugin(struct st_mysql *mysql, const char *name, int type,
+ int argc, ...);
+
+/**
+ loads a plugin and initializes it, taking va_list as an argument
+
+ This is the same as mysql_load_plugin, but take va_list instead of
+ a list of arguments.
+
+ @param mysql MYSQL structure.
+ @param name a name of the plugin to load
+ @param type type of plugin that should be loaded, -1 to disable type check
+ @param argc number of arguments to pass to the plugin initialization
+ function
+ @param args arguments for the plugin initialization function
+
+ @retval
+ a pointer to the loaded plugin, or NULL in case of a failure
+*/
+struct st_mysql_client_plugin *
+mysql_load_plugin_v(struct st_mysql *mysql, const char *name, int type,
+ int argc, va_list args);
+
+/**
+ finds an already loaded plugin by name, or loads it, if necessary
+
+ @param mysql MYSQL structure.
+ @param name a name of the plugin to load
+ @param type type of plugin that should be loaded
+
+ @retval
+ a pointer to the plugin, or NULL in case of a failure
+*/
+struct st_mysql_client_plugin *
+mysql_client_find_plugin(struct st_mysql *mysql, const char *name, int type);
+
+/**
+ adds a plugin structure to the list of loaded plugins
+
+ This is useful if an application has the necessary functionality
+ (for example, a special load data handler) statically linked into
+ the application binary. It can use this function to register the plugin
+ directly, avoiding the need to factor it out into a shared object.
+
+ @param mysql MYSQL structure. It is only used for error reporting
+ @param plugin an st_mysql_client_plugin structure to register
+
+ @retval
+ a pointer to the plugin, or NULL in case of a failure
+*/
+struct st_mysql_client_plugin *
+mysql_client_register_plugin(struct st_mysql *mysql,
+ struct st_mysql_client_plugin *plugin);
+
+/**
+ set plugin options
+
+ Can be used to set extra options and affect behavior for a plugin.
+ This function may be called multiple times to set several options
+
+ @param plugin an st_mysql_client_plugin structure
+ @param option a string which specifies the option to set
+ @param value value for the option.
+
+ @retval 0 on success, 1 in case of failure
+**/
+int STDCALL mysql_plugin_options(struct st_mysql_client_plugin *plugin,
+ const char *option,
+ const void *value);
+#endif
+
diff --git a/include/mysql/client_plugin.h.pp b/include/mysql/client_plugin.h.pp
new file mode 100644
index 00000000000..e508f821aad
--- /dev/null
+++ b/include/mysql/client_plugin.h.pp
@@ -0,0 +1,40 @@
+struct st_mysql_client_plugin
+{
+ int type; unsigned int interface_version; const char *name; const char *author; const char *desc; unsigned int version[3]; const char *license; void *mysql_api; int (*init)(char *, size_t, int, va_list); int (*deinit)(); int (*options)(const char *option, const void *);
+};
+struct st_mysql;
+#include <mysql/plugin_auth_common.h>
+typedef struct st_plugin_vio_info
+{
+ enum { MYSQL_VIO_INVALID, MYSQL_VIO_TCP, MYSQL_VIO_SOCKET,
+ MYSQL_VIO_PIPE, MYSQL_VIO_MEMORY } protocol;
+ int socket;
+} MYSQL_PLUGIN_VIO_INFO;
+typedef struct st_plugin_vio
+{
+ int (*read_packet)(struct st_plugin_vio *vio,
+ unsigned char **buf);
+ int (*write_packet)(struct st_plugin_vio *vio,
+ const unsigned char *packet,
+ int packet_len);
+ void (*info)(struct st_plugin_vio *vio, struct st_plugin_vio_info *info);
+} MYSQL_PLUGIN_VIO;
+struct st_mysql_client_plugin_AUTHENTICATION
+{
+ int type; unsigned int interface_version; const char *name; const char *author; const char *desc; unsigned int version[3]; const char *license; void *mysql_api; int (*init)(char *, size_t, int, va_list); int (*deinit)(); int (*options)(const char *option, const void *);
+ int (*authenticate_user)(MYSQL_PLUGIN_VIO *vio, struct st_mysql *mysql);
+};
+struct st_mysql_client_plugin *
+mysql_load_plugin(struct st_mysql *mysql, const char *name, int type,
+ int argc, ...);
+struct st_mysql_client_plugin *
+mysql_load_plugin_v(struct st_mysql *mysql, const char *name, int type,
+ int argc, va_list args);
+struct st_mysql_client_plugin *
+mysql_client_find_plugin(struct st_mysql *mysql, const char *name, int type);
+struct st_mysql_client_plugin *
+mysql_client_register_plugin(struct st_mysql *mysql,
+ struct st_mysql_client_plugin *plugin);
+int STDCALL mysql_plugin_options(struct st_mysql_client_plugin *plugin,
+ const char *option,
+ const void *value);
diff --git a/include/mysql/innodb_priv.h b/include/mysql/innodb_priv.h
new file mode 100644
index 00000000000..993dad7cf99
--- /dev/null
+++ b/include/mysql/innodb_priv.h
@@ -0,0 +1,37 @@
+/* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ 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 INNODB_PRIV_INCLUDED
+#define INNODB_PRIV_INCLUDED
+
+/** @file Declaring server-internal functions that are used by InnoDB. */
+
+#include <sql_priv.h>
+
+class THD;
+
+uint filename_to_tablename(const char *from, char *to, uint to_length);
+int get_quote_char_for_identifier(THD *thd, const char *name, uint length);
+bool schema_table_store_record(THD *thd, TABLE *table);
+void localtime_to_TIME(MYSQL_TIME *to, struct tm *from);
+bool check_global_access(THD *thd, ulong want_access);
+uint strconvert(CHARSET_INFO *from_cs, const char *from,
+ CHARSET_INFO *to_cs, char *to, uint to_length,
+ uint *errors);
+void sql_print_error(const char *format, ...);
+
+
+
+#endif /* INNODB_PRIV_INCLUDED */
diff --git a/include/mysql/plugin.h b/include/mysql/plugin.h
index 55ef6070f85..7ec68ff5040 100644
--- a/include/mysql/plugin.h
+++ b/include/mysql/plugin.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 2005 MySQL AB
+/* Copyright (C) 2005 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
@@ -16,13 +16,27 @@
#ifndef _my_plugin_h
#define _my_plugin_h
-
/*
On Windows, exports from DLL need to be declared
-*/
-#if (defined(_WIN32) && defined(MYSQL_DYNAMIC_PLUGIN))
-#define MYSQL_PLUGIN_EXPORT extern "C" __declspec(dllexport)
-#else
+ Also, plugin needs to be declared as extern "C" because MSVC
+ unlike other compilers, uses C++ mangling for variables not only
+ for functions.
+*/
+#if defined(_MSC_VER)
+#if defined(MYSQL_DYNAMIC_PLUGIN)
+ #ifdef __cplusplus
+ #define MYSQL_PLUGIN_EXPORT extern "C" __declspec(dllexport)
+ #else
+ #define MYSQL_PLUGIN_EXPORT __declspec(dllexport)
+ #endif
+#else /* MYSQL_DYNAMIC_PLUGIN */
+ #ifdef __cplusplus
+ #define MYSQL_PLUGIN_EXPORT extern "C"
+ #else
+ #define MYSQL_PLUGIN_EXPORT
+ #endif
+#endif /*MYSQL_DYNAMIC_PLUGIN */
+#else /*_MSC_VER */
#define MYSQL_PLUGIN_EXPORT
#endif
@@ -34,15 +48,7 @@ class Item;
#define MYSQL_THD void*
#endif
-#ifndef _m_string_h
-/* This definition must match the one given in m_string.h */
-struct st_mysql_lex_string
-{
- char *str;
- unsigned int length;
-};
-#endif /* _m_string_h */
-typedef struct st_mysql_lex_string MYSQL_LEX_STRING;
+#include <mysql/services.h>
#define MYSQL_XIDDATASIZE 128
/**
@@ -65,7 +71,7 @@ typedef struct st_mysql_xid MYSQL_XID;
Plugin API. Common for all plugin types.
*/
-#define MYSQL_PLUGIN_INTERFACE_VERSION 0x0100
+#define MYSQL_PLUGIN_INTERFACE_VERSION 0x0102
/*
The allowable types of plugins
@@ -75,7 +81,10 @@ typedef struct st_mysql_xid MYSQL_XID;
#define MYSQL_FTPARSER_PLUGIN 2 /* Full-text parser plugin */
#define MYSQL_DAEMON_PLUGIN 3 /* The daemon/raw plugin type */
#define MYSQL_INFORMATION_SCHEMA_PLUGIN 4 /* The I_S plugin type */
-#define MYSQL_MAX_PLUGIN_TYPE_NUM 5 /* The number of plugin types */
+#define MYSQL_AUDIT_PLUGIN 5 /* The Audit plugin type */
+#define MYSQL_REPLICATION_PLUGIN 6 /* The replication plugin type */
+#define MYSQL_AUTHENTICATION_PLUGIN 7 /* The authentication plugin type */
+#define MYSQL_MAX_PLUGIN_TYPE_NUM 8 /* The number of plugin types */
/* We use the following strings to define licenses for plugins */
#define PLUGIN_LICENSE_PROPRIETARY 0
@@ -95,9 +104,9 @@ typedef struct st_mysql_xid MYSQL_XID;
#ifndef MYSQL_DYNAMIC_PLUGIN
#define __MYSQL_DECLARE_PLUGIN(NAME, VERSION, PSIZE, DECLS) \
-int VERSION= MYSQL_PLUGIN_INTERFACE_VERSION; \
-int PSIZE= sizeof(struct st_mysql_plugin); \
-struct st_mysql_plugin DECLS[]= {
+MYSQL_PLUGIN_EXPORT int VERSION= MYSQL_PLUGIN_INTERFACE_VERSION; \
+MYSQL_PLUGIN_EXPORT int PSIZE= sizeof(struct st_mysql_plugin); \
+MYSQL_PLUGIN_EXPORT struct st_mysql_plugin DECLS[]= {
#else
#define __MYSQL_DECLARE_PLUGIN(NAME, VERSION, PSIZE, DECLS) \
MYSQL_PLUGIN_EXPORT int _mysql_plugin_interface_version_= MYSQL_PLUGIN_INTERFACE_VERSION; \
@@ -120,7 +129,8 @@ enum enum_mysql_show_type
{
SHOW_UNDEF, SHOW_BOOL, SHOW_INT, SHOW_LONG,
SHOW_LONGLONG, SHOW_CHAR, SHOW_CHAR_PTR,
- SHOW_ARRAY, SHOW_FUNC, SHOW_DOUBLE
+ SHOW_ARRAY, SHOW_FUNC, SHOW_DOUBLE,
+ SHOW_always_last
};
struct st_mysql_show_var {
@@ -410,205 +420,43 @@ struct st_mysql_plugin
/*************************************************************************
API for Full-text parser plugin. (MYSQL_FTPARSER_PLUGIN)
*/
+#include "plugin_ftparser.h"
-#define MYSQL_FTPARSER_INTERFACE_VERSION 0x0100
-
-/* Parsing modes. Set in MYSQL_FTPARSER_PARAM::mode */
-enum enum_ftparser_mode
-{
-/*
- Fast and simple mode. This mode is used for indexing, and natural
- language queries.
-
- The parser is expected to return only those words that go into the
- index. Stopwords or too short/long words should not be returned. The
- 'boolean_info' argument of mysql_add_word() does not have to be set.
-*/
- MYSQL_FTPARSER_SIMPLE_MODE= 0,
-
-/*
- Parse with stopwords mode. This mode is used in boolean searches for
- "phrase matching."
-
- The parser is not allowed to ignore words in this mode. Every word
- should be returned, including stopwords and words that are too short
- or long. The 'boolean_info' argument of mysql_add_word() does not
- have to be set.
+/*************************************************************************
+ API for Storage Engine plugin. (MYSQL_DAEMON_PLUGIN)
*/
- MYSQL_FTPARSER_WITH_STOPWORDS= 1,
-/*
- Parse in boolean mode. This mode is used to parse a boolean query string.
-
- The parser should provide a valid MYSQL_FTPARSER_BOOLEAN_INFO
- structure in the 'boolean_info' argument to mysql_add_word().
- Usually that means that the parser should recognize boolean operators
- in the parsing stream and set appropriate fields in
- MYSQL_FTPARSER_BOOLEAN_INFO structure accordingly. As for
- MYSQL_FTPARSER_WITH_STOPWORDS mode, no word should be ignored.
- Instead, use FT_TOKEN_STOPWORD for the token type of such a word.
-*/
- MYSQL_FTPARSER_FULL_BOOLEAN_INFO= 2
-};
+/* handlertons of different MySQL releases are incompatible */
+#define MYSQL_DAEMON_INTERFACE_VERSION (MYSQL_VERSION_ID << 8)
/*
- Token types for boolean mode searching (used for the type member of
- MYSQL_FTPARSER_BOOLEAN_INFO struct)
-
- FT_TOKEN_EOF: End of data.
- FT_TOKEN_WORD: Regular word.
- FT_TOKEN_LEFT_PAREN: Left parenthesis (start of group/sub-expression).
- FT_TOKEN_RIGHT_PAREN: Right parenthesis (end of group/sub-expression).
- FT_TOKEN_STOPWORD: Stopword.
+ Here we define only the descriptor structure, that is referred from
+ st_mysql_plugin.
*/
-enum enum_ft_token_type
+struct st_mysql_daemon
{
- FT_TOKEN_EOF= 0,
- FT_TOKEN_WORD= 1,
- FT_TOKEN_LEFT_PAREN= 2,
- FT_TOKEN_RIGHT_PAREN= 3,
- FT_TOKEN_STOPWORD= 4
+ int interface_version;
};
-/*
- This structure is used in boolean search mode only. It conveys
- boolean-mode metadata to the MySQL search engine for every word in
- the search query. A valid instance of this structure must be filled
- in by the plugin parser and passed as an argument in the call to
- mysql_add_word (the callback function in the MYSQL_FTPARSER_PARAM
- structure) when a query is parsed in boolean mode.
-
- type: The token type. Should be one of the enum_ft_token_type values.
-
- yesno: Whether the word must be present for a match to occur:
- >0 Must be present
- <0 Must not be present
- 0 Neither; the word is optional but its presence increases the relevance
- With the default settings of the ft_boolean_syntax system variable,
- >0 corresponds to the '+' operator, <0 corrresponds to the '-' operator,
- and 0 means neither operator was used.
-
- weight_adjust: A weighting factor that determines how much a match
- for the word counts. Positive values increase, negative - decrease the
- relative word's importance in the query.
-
- wasign: The sign of the word's weight in the query. If it's non-negative
- the match for the word will increase document relevance, if it's
- negative - decrease (the word becomes a "noise word", the less of it the
- better).
-
- trunc: Corresponds to the '*' operator in the default setting of the
- ft_boolean_syntax system variable.
-*/
-typedef struct st_mysql_ftparser_boolean_info
-{
- enum enum_ft_token_type type;
- int yesno;
- int weight_adjust;
- char wasign;
- char trunc;
- /* These are parser state and must be removed. */
- char prev;
- char *quot;
-} MYSQL_FTPARSER_BOOLEAN_INFO;
-
-/*
- The following flag means that buffer with a string (document, word)
- may be overwritten by the caller before the end of the parsing (that is
- before st_mysql_ftparser::deinit() call). If one needs the string
- to survive between two successive calls of the parsing function, she
- needs to save a copy of it. The flag may be set by MySQL before calling
- st_mysql_ftparser::parse(), or it may be set by a plugin before calling
- st_mysql_ftparser_param::mysql_parse() or
- st_mysql_ftparser_param::mysql_add_word().
-*/
-#define MYSQL_FTFLAGS_NEED_COPY 1
-
-/*
- An argument of the full-text parser plugin. This structure is
- filled in by MySQL server and passed to the parsing function of the
- plugin as an in/out parameter.
-
- mysql_parse: A pointer to the built-in parser implementation of the
- server. It's set by the server and can be used by the parser plugin
- to invoke the MySQL default parser. If plugin's role is to extract
- textual data from .doc, .pdf or .xml content, it might extract
- plaintext from the content, and then pass the text to the default
- MySQL parser to be parsed.
-
- mysql_add_word: A server callback to add a new word. When parsing
- a document, the server sets this to point at a function that adds
- the word to MySQL full-text index. When parsing a search query,
- this function will add the new word to the list of words to search
- for. The boolean_info argument can be NULL for all cases except
- when mode is MYSQL_FTPARSER_FULL_BOOLEAN_INFO.
-
- ftparser_state: A generic pointer. The plugin can set it to point
- to information to be used internally for its own purposes.
-
- mysql_ftparam: This is set by the server. It is used by MySQL functions
- called via mysql_parse() and mysql_add_word() callback. The plugin
- should not modify it.
-
- cs: Information about the character set of the document or query string.
-
- doc: A pointer to the document or query string to be parsed.
-
- length: Length of the document or query string, in bytes.
-
- flags: See MYSQL_FTFLAGS_* constants above.
-
- mode: The parsing mode. With boolean operators, with stopwords, or
- nothing. See enum_ftparser_mode above.
+/*************************************************************************
+ API for I_S plugin. (MYSQL_INFORMATION_SCHEMA_PLUGIN)
*/
-typedef struct st_mysql_ftparser_param
-{
- int (*mysql_parse)(struct st_mysql_ftparser_param *,
- char *doc, int doc_len);
- int (*mysql_add_word)(struct st_mysql_ftparser_param *,
- char *word, int word_len,
- MYSQL_FTPARSER_BOOLEAN_INFO *boolean_info);
- void *ftparser_state;
- void *mysql_ftparam;
- struct charset_info_st *cs;
- char *doc;
- int length;
- int flags;
- enum enum_ftparser_mode mode;
-} MYSQL_FTPARSER_PARAM;
+/* handlertons of different MySQL releases are incompatible */
+#define MYSQL_INFORMATION_SCHEMA_INTERFACE_VERSION (MYSQL_VERSION_ID << 8)
/*
- Full-text parser descriptor.
-
- interface_version is, e.g., MYSQL_FTPARSER_INTERFACE_VERSION.
- The parsing, initialization, and deinitialization functions are
- invoked per SQL statement for which the parser is used.
+ Here we define only the descriptor structure, that is referred from
+ st_mysql_plugin.
*/
-struct st_mysql_ftparser
+struct st_mysql_information_schema
{
int interface_version;
- int (*parse)(MYSQL_FTPARSER_PARAM *param);
- int (*init)(MYSQL_FTPARSER_PARAM *param);
- int (*deinit)(MYSQL_FTPARSER_PARAM *param);
};
-/*************************************************************************
- API for Storage Engine plugin. (MYSQL_DAEMON_PLUGIN)
-*/
-
-/* handlertons of different MySQL releases are incompatible */
-#define MYSQL_DAEMON_INTERFACE_VERSION (MYSQL_VERSION_ID << 8)
-
-/*************************************************************************
- API for I_S plugin. (MYSQL_INFORMATION_SCHEMA_PLUGIN)
-*/
-
-/* handlertons of different MySQL releases are incompatible */
-#define MYSQL_INFORMATION_SCHEMA_INTERFACE_VERSION (MYSQL_VERSION_ID << 8)
/*************************************************************************
API for Storage Engine plugin. (MYSQL_STORAGE_ENGINE_PLUGIN)
@@ -630,28 +478,20 @@ struct st_mysql_storage_engine
struct handlerton;
-/*
- Here we define only the descriptor structure, that is referred from
- st_mysql_plugin.
-*/
-
-struct st_mysql_daemon
-{
- int interface_version;
-};
/*
- Here we define only the descriptor structure, that is referred from
- st_mysql_plugin.
+ API for Replication plugin. (MYSQL_REPLICATION_PLUGIN)
*/
+ #define MYSQL_REPLICATION_INTERFACE_VERSION 0x0100
+
+ /**
+ Replication plugin descriptor
+ */
+ struct Mysql_replication {
+ int interface_version;
+ };
-struct st_mysql_information_schema
-{
- int interface_version;
-};
-
-
-/*
+/*************************************************************************
st_mysql_value struct for reading values from mysqld.
Used by server variables framework to parse user-provided values.
Will be used for arguments when implementing UDFs.
@@ -671,6 +511,7 @@ struct st_mysql_value
const char *(*val_str)(struct st_mysql_value *, char *buffer, int *length);
int (*val_real)(struct st_mysql_value *, double *realbuf);
int (*val_int)(struct st_mysql_value *, long long *intbuf);
+ int (*is_unsigned)(struct st_mysql_value *);
};
@@ -688,6 +529,7 @@ long long thd_test_options(const MYSQL_THD thd, long long test_options);
int thd_sql_command(const MYSQL_THD thd);
const char *thd_proc_info(MYSQL_THD thd, const char *info);
void **thd_ha_data(const MYSQL_THD thd, const struct handlerton *hton);
+void thd_storage_lock_wait(MYSQL_THD thd, long long value);
int thd_tx_isolation(const MYSQL_THD thd);
char *thd_security_context(MYSQL_THD thd, char *buffer, unsigned int length,
unsigned int max_query_len);
@@ -733,54 +575,6 @@ int thd_killed(const MYSQL_THD thd);
*/
unsigned long thd_get_thread_id(const MYSQL_THD thd);
-
-/**
- Allocate memory in the connection's local memory pool
-
- @details
- When properly used in place of @c my_malloc(), this can significantly
- improve concurrency. Don't use this or related functions to allocate
- large chunks of memory. Use for temporary storage only. The memory
- will be freed automatically at the end of the statement; no explicit
- code is required to prevent memory leaks.
-
- @see alloc_root()
-*/
-void *thd_alloc(MYSQL_THD thd, unsigned int size);
-/**
- @see thd_alloc()
-*/
-void *thd_calloc(MYSQL_THD thd, unsigned int size);
-/**
- @see thd_alloc()
-*/
-char *thd_strdup(MYSQL_THD thd, const char *str);
-/**
- @see thd_alloc()
-*/
-char *thd_strmake(MYSQL_THD thd, const char *str, unsigned int size);
-/**
- @see thd_alloc()
-*/
-void *thd_memdup(MYSQL_THD thd, const void* str, unsigned int size);
-
-/**
- Create a LEX_STRING in this connection's local memory pool
-
- @param thd user thread connection handle
- @param lex_str pointer to LEX_STRING object to be initialized
- @param str initializer to be copied into lex_str
- @param size length of str, in bytes
- @param allocate_lex_string flag: if TRUE, allocate new LEX_STRING object,
- instead of using lex_str value
- @return NULL on failure, or pointer to the LEX_STRING object
-
- @see thd_alloc()
-*/
-MYSQL_LEX_STRING *thd_make_lex_string(MYSQL_THD thd, MYSQL_LEX_STRING *lex_str,
- const char *str, unsigned int size,
- int allocate_lex_string);
-
/**
Get the XID for this connection's transaction
diff --git a/include/mysql/plugin_audit.h b/include/mysql/plugin_audit.h
new file mode 100644
index 00000000000..41505da64af
--- /dev/null
+++ b/include/mysql/plugin_audit.h
@@ -0,0 +1,98 @@
+/* Copyright (C) 2007 MySQL AB
+
+ 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 _my_audit_h
+#define _my_audit_h
+
+/*************************************************************************
+ API for Audit plugin. (MYSQL_AUDIT_PLUGIN)
+*/
+
+#include "plugin.h"
+
+#define MYSQL_AUDIT_CLASS_MASK_SIZE 1
+
+#define MYSQL_AUDIT_INTERFACE_VERSION 0x0200
+
+/*
+ The first word in every event class struct indicates the specific
+ class of the event.
+*/
+struct mysql_event
+{
+ unsigned int event_class;
+};
+
+
+/*************************************************************************
+ AUDIT CLASS : GENERAL
+
+ LOG events occurs before emitting to the general query log.
+ ERROR events occur before transmitting errors to the user.
+ RESULT events occur after transmitting a resultset to the user.
+*/
+
+#define MYSQL_AUDIT_GENERAL_CLASS 0
+#define MYSQL_AUDIT_GENERAL_CLASSMASK (1 << MYSQL_AUDIT_GENERAL_CLASS)
+#define MYSQL_AUDIT_GENERAL_LOG 0
+#define MYSQL_AUDIT_GENERAL_ERROR 1
+#define MYSQL_AUDIT_GENERAL_RESULT 2
+
+struct mysql_event_general
+{
+ unsigned int event_class;
+ unsigned int event_subclass;
+ int general_error_code;
+ unsigned long general_thread_id;
+ const char *general_user;
+ unsigned int general_user_length;
+ const char *general_command;
+ unsigned int general_command_length;
+ const char *general_query;
+ unsigned int general_query_length;
+ struct charset_info_st *general_charset;
+ unsigned long long general_time;
+ unsigned long long general_rows;
+};
+
+
+/*************************************************************************
+ Here we define the descriptor structure, that is referred from
+ st_mysql_plugin.
+
+ release_thd() event occurs when the event class consumer is to be
+ disassociated from the specified THD. This would typically occur
+ before some operation which may require sleeping - such as when
+ waiting for the next query from the client.
+
+ event_notify() is invoked whenever an event occurs which is of any
+ class for which the plugin has interest. The first word of the
+ mysql_event argument indicates the specific event class and the
+ remainder of the structure is as required for that class.
+
+ class_mask is an array of bits used to indicate what event classes
+ that this plugin wants to receive.
+*/
+
+struct st_mysql_audit
+{
+ int interface_version;
+ void (*release_thd)(MYSQL_THD);
+ void (*event_notify)(MYSQL_THD, const struct mysql_event *);
+ unsigned long class_mask[MYSQL_AUDIT_CLASS_MASK_SIZE];
+};
+
+
+#endif
diff --git a/include/mysql/plugin_audit.h.pp b/include/mysql/plugin_audit.h.pp
new file mode 100644
index 00000000000..b48cbca2e87
--- /dev/null
+++ b/include/mysql/plugin_audit.h.pp
@@ -0,0 +1,217 @@
+#include "plugin.h"
+#include <mysql/services.h>
+#include <mysql/service_my_snprintf.h>
+extern struct my_snprintf_service_st {
+ size_t (*my_snprintf_type)(char*, size_t, const char*, ...);
+ size_t (*my_vsnprintf_type)(char *, size_t, const char*, va_list);
+} *my_snprintf_service;
+size_t my_snprintf(char* to, size_t n, const char* fmt, ...);
+size_t my_vsnprintf(char *to, size_t n, const char* fmt, va_list ap);
+#include <mysql/service_thd_alloc.h>
+struct st_mysql_lex_string
+{
+ char *str;
+ size_t length;
+};
+typedef struct st_mysql_lex_string MYSQL_LEX_STRING;
+extern struct thd_alloc_service_st {
+ void *(*thd_alloc_func)(void*, unsigned int);
+ void *(*thd_calloc_func)(void*, unsigned int);
+ char *(*thd_strdup_func)(void*, const char *);
+ char *(*thd_strmake_func)(void*, const char *, unsigned int);
+ void *(*thd_memdup_func)(void*, const void*, unsigned int);
+ MYSQL_LEX_STRING *(*thd_make_lex_string_func)(void*, MYSQL_LEX_STRING *,
+ const char *, unsigned int, int);
+} *thd_alloc_service;
+void *thd_alloc(void* thd, unsigned int size);
+void *thd_calloc(void* thd, unsigned int size);
+char *thd_strdup(void* thd, const char *str);
+char *thd_strmake(void* thd, const char *str, unsigned int size);
+void *thd_memdup(void* thd, const void* str, unsigned int size);
+MYSQL_LEX_STRING *thd_make_lex_string(void* thd, MYSQL_LEX_STRING *lex_str,
+ const char *str, unsigned int size,
+ int allocate_lex_string);
+#include <mysql/service_thd_wait.h>
+typedef enum _thd_wait_type_e {
+ THD_WAIT_MUTEX= 1,
+ THD_WAIT_DISKIO= 2,
+ THD_WAIT_ROW_TABLE_LOCK= 3,
+ THD_WAIT_GLOBAL_LOCK= 4
+} thd_wait_type;
+extern struct thd_wait_service_st {
+ void (*thd_wait_begin_func)(void*, thd_wait_type);
+ void (*thd_wait_end_func)(void*);
+} *thd_wait_service;
+void thd_wait_begin(void* thd, thd_wait_type wait_type);
+void thd_wait_end(void* thd);
+#include <mysql/service_thread_scheduler.h>
+struct scheduler_functions;
+extern struct my_thread_scheduler_service {
+ int (*set)(struct scheduler_functions *scheduler);
+ int (*reset)();
+} *my_thread_scheduler_service;
+int my_thread_scheduler_set(struct scheduler_functions *scheduler);
+int my_thread_scheduler_reset();
+struct st_mysql_xid {
+ long formatID;
+ long gtrid_length;
+ long bqual_length;
+ char data[128];
+};
+typedef struct st_mysql_xid MYSQL_XID;
+enum enum_mysql_show_type
+{
+ SHOW_UNDEF, SHOW_BOOL, SHOW_INT, SHOW_LONG,
+ SHOW_LONGLONG, SHOW_CHAR, SHOW_CHAR_PTR,
+ SHOW_ARRAY, SHOW_FUNC, SHOW_DOUBLE,
+ SHOW_always_last
+};
+struct st_mysql_show_var {
+ const char *name;
+ char *value;
+ enum enum_mysql_show_type type;
+};
+typedef int (*mysql_show_var_func)(void*, struct st_mysql_show_var*, char *);
+struct st_mysql_sys_var;
+struct st_mysql_value;
+typedef int (*mysql_var_check_func)(void* thd,
+ struct st_mysql_sys_var *var,
+ void *save, struct st_mysql_value *value);
+typedef void (*mysql_var_update_func)(void* thd,
+ struct st_mysql_sys_var *var,
+ void *var_ptr, const void *save);
+struct st_mysql_plugin
+{
+ int type;
+ void *info;
+ const char *name;
+ const char *author;
+ const char *descr;
+ int license;
+ int (*init)(void *);
+ int (*deinit)(void *);
+ unsigned int version;
+ struct st_mysql_show_var *status_vars;
+ struct st_mysql_sys_var **system_vars;
+ void * __reserved1;
+};
+#include "plugin_ftparser.h"
+#include "plugin.h"
+enum enum_ftparser_mode
+{
+ MYSQL_FTPARSER_SIMPLE_MODE= 0,
+ MYSQL_FTPARSER_WITH_STOPWORDS= 1,
+ MYSQL_FTPARSER_FULL_BOOLEAN_INFO= 2
+};
+enum enum_ft_token_type
+{
+ FT_TOKEN_EOF= 0,
+ FT_TOKEN_WORD= 1,
+ FT_TOKEN_LEFT_PAREN= 2,
+ FT_TOKEN_RIGHT_PAREN= 3,
+ FT_TOKEN_STOPWORD= 4
+};
+typedef struct st_mysql_ftparser_boolean_info
+{
+ enum enum_ft_token_type type;
+ int yesno;
+ int weight_adjust;
+ char wasign;
+ char trunc;
+ char prev;
+ char *quot;
+} MYSQL_FTPARSER_BOOLEAN_INFO;
+typedef struct st_mysql_ftparser_param
+{
+ int (*mysql_parse)(struct st_mysql_ftparser_param *,
+ char *doc, int doc_len);
+ int (*mysql_add_word)(struct st_mysql_ftparser_param *,
+ char *word, int word_len,
+ MYSQL_FTPARSER_BOOLEAN_INFO *boolean_info);
+ void *ftparser_state;
+ void *mysql_ftparam;
+ struct charset_info_st *cs;
+ char *doc;
+ int length;
+ int flags;
+ enum enum_ftparser_mode mode;
+} MYSQL_FTPARSER_PARAM;
+struct st_mysql_ftparser
+{
+ int interface_version;
+ int (*parse)(MYSQL_FTPARSER_PARAM *param);
+ int (*init)(MYSQL_FTPARSER_PARAM *param);
+ int (*deinit)(MYSQL_FTPARSER_PARAM *param);
+};
+struct st_mysql_daemon
+{
+ int interface_version;
+};
+struct st_mysql_information_schema
+{
+ int interface_version;
+};
+struct st_mysql_storage_engine
+{
+ int interface_version;
+};
+struct handlerton;
+ struct Mysql_replication {
+ int interface_version;
+ };
+struct st_mysql_value
+{
+ int (*value_type)(struct st_mysql_value *);
+ const char *(*val_str)(struct st_mysql_value *, char *buffer, int *length);
+ int (*val_real)(struct st_mysql_value *, double *realbuf);
+ int (*val_int)(struct st_mysql_value *, long long *intbuf);
+ int (*is_unsigned)(struct st_mysql_value *);
+};
+int thd_in_lock_tables(const void* thd);
+int thd_tablespace_op(const void* thd);
+long long thd_test_options(const void* thd, long long test_options);
+int thd_sql_command(const void* thd);
+const char *thd_proc_info(void* thd, const char *info);
+void **thd_ha_data(const void* thd, const struct handlerton *hton);
+void thd_storage_lock_wait(void* thd, long long value);
+int thd_tx_isolation(const void* thd);
+char *thd_security_context(void* thd, char *buffer, unsigned int length,
+ unsigned int max_query_len);
+void thd_inc_row_count(void* thd);
+int mysql_tmpfile(const char *prefix);
+int thd_killed(const void* thd);
+unsigned long thd_get_thread_id(const void* thd);
+void thd_get_xid(const void* thd, MYSQL_XID *xid);
+void mysql_query_cache_invalidate4(void* thd,
+ const char *key, unsigned int key_length,
+ int using_trx);
+void *thd_get_ha_data(const void* thd, const struct handlerton *hton);
+void thd_set_ha_data(void* thd, const struct handlerton *hton,
+ const void *ha_data);
+struct mysql_event
+{
+ unsigned int event_class;
+};
+struct mysql_event_general
+{
+ unsigned int event_class;
+ unsigned int event_subclass;
+ int general_error_code;
+ unsigned long general_thread_id;
+ const char *general_user;
+ unsigned int general_user_length;
+ const char *general_command;
+ unsigned int general_command_length;
+ const char *general_query;
+ unsigned int general_query_length;
+ struct charset_info_st *general_charset;
+ unsigned long long general_time;
+ unsigned long long general_rows;
+};
+struct st_mysql_audit
+{
+ int interface_version;
+ void (*release_thd)(void*);
+ void (*event_notify)(void*, const struct mysql_event *);
+ unsigned long class_mask[1];
+};
diff --git a/include/mysql/plugin_auth.h b/include/mysql/plugin_auth.h
new file mode 100644
index 00000000000..420eb3bb80f
--- /dev/null
+++ b/include/mysql/plugin_auth.h
@@ -0,0 +1,125 @@
+#ifndef MYSQL_PLUGIN_AUTH_INCLUDED
+/* Copyright (C) 2010 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
+
+ Authentication Plugin API.
+
+ This file defines the API for server authentication plugins.
+*/
+
+#define MYSQL_PLUGIN_AUTH_INCLUDED
+
+#include <mysql/plugin.h>
+
+#define MYSQL_AUTHENTICATION_INTERFACE_VERSION 0x0100
+
+#include <mysql/plugin_auth_common.h>
+
+/* defines for MYSQL_SERVER_AUTH_INFO.password_used */
+
+#define PASSWORD_USED_NO 0
+#define PASSWORD_USED_YES 1
+#define PASSWORD_USED_NO_MENTION 2
+
+
+/**
+ Provides server plugin access to authentication information
+*/
+typedef struct st_mysql_server_auth_info
+{
+ /**
+ User name as sent by the client and shown in USER().
+ NULL if the client packet with the user name was not received yet.
+ */
+ char *user_name;
+
+ /**
+ Length of user_name
+ */
+ unsigned int user_name_length;
+
+ /**
+ A corresponding column value from the mysql.user table for the
+ matching account name
+ */
+ const char *auth_string;
+
+ /**
+ Length of auth_string
+ */
+ unsigned long auth_string_length;
+
+ /**
+ Matching account name as found in the mysql.user table.
+ A plugin can override it with another name that will be
+ used by MySQL for authorization, and shown in CURRENT_USER()
+ */
+ char authenticated_as[MYSQL_USERNAME_LENGTH+1];
+
+
+ /**
+ The unique user name that was used by the plugin to authenticate.
+ Plugins should put null-terminated UTF-8 here.
+ Available through the @@EXTERNAL_USER variable.
+ */
+ char external_user[512];
+
+ /**
+ This only affects the "Authentication failed. Password used: %s"
+ error message. has the following values :
+ 0 : %s will be NO.
+ 1 : %s will be YES.
+ 2 : there will be no %s.
+ Set it as appropriate or ignore at will.
+ */
+ int password_used;
+
+ /**
+ Set to the name of the connected client host, if it can be resolved,
+ or to its IP address otherwise.
+ */
+ const char *host_or_ip;
+
+ /**
+ Length of host_or_ip
+ */
+ unsigned int host_or_ip_length;
+
+} MYSQL_SERVER_AUTH_INFO;
+
+/**
+ Server authentication plugin descriptor
+*/
+struct st_mysql_auth
+{
+ int interface_version; /** version plugin uses */
+ /**
+ A plugin that a client must use for authentication with this server
+ plugin. Can be NULL to mean "any plugin".
+ */
+ const char *client_auth_plugin;
+ /**
+ Function provided by the plugin which should perform authentication (using
+ the vio functions if necessary) and return 0 if successful. The plugin can
+ also fill the info.authenticated_as field if a different username should be
+ used for authorization.
+ */
+ int (*authenticate_user)(MYSQL_PLUGIN_VIO *vio, MYSQL_SERVER_AUTH_INFO *info);
+};
+#endif
+
diff --git a/include/mysql/plugin_auth.h.pp b/include/mysql/plugin_auth.h.pp
new file mode 100644
index 00000000000..88588d03b9e
--- /dev/null
+++ b/include/mysql/plugin_auth.h.pp
@@ -0,0 +1,224 @@
+#include <mysql/plugin.h>
+#include <mysql/services.h>
+#include <mysql/service_my_snprintf.h>
+extern struct my_snprintf_service_st {
+ size_t (*my_snprintf_type)(char*, size_t, const char*, ...);
+ size_t (*my_vsnprintf_type)(char *, size_t, const char*, va_list);
+} *my_snprintf_service;
+size_t my_snprintf(char* to, size_t n, const char* fmt, ...);
+size_t my_vsnprintf(char *to, size_t n, const char* fmt, va_list ap);
+#include <mysql/service_thd_alloc.h>
+struct st_mysql_lex_string
+{
+ char *str;
+ size_t length;
+};
+typedef struct st_mysql_lex_string MYSQL_LEX_STRING;
+extern struct thd_alloc_service_st {
+ void *(*thd_alloc_func)(void*, unsigned int);
+ void *(*thd_calloc_func)(void*, unsigned int);
+ char *(*thd_strdup_func)(void*, const char *);
+ char *(*thd_strmake_func)(void*, const char *, unsigned int);
+ void *(*thd_memdup_func)(void*, const void*, unsigned int);
+ MYSQL_LEX_STRING *(*thd_make_lex_string_func)(void*, MYSQL_LEX_STRING *,
+ const char *, unsigned int, int);
+} *thd_alloc_service;
+void *thd_alloc(void* thd, unsigned int size);
+void *thd_calloc(void* thd, unsigned int size);
+char *thd_strdup(void* thd, const char *str);
+char *thd_strmake(void* thd, const char *str, unsigned int size);
+void *thd_memdup(void* thd, const void* str, unsigned int size);
+MYSQL_LEX_STRING *thd_make_lex_string(void* thd, MYSQL_LEX_STRING *lex_str,
+ const char *str, unsigned int size,
+ int allocate_lex_string);
+#include <mysql/service_thd_wait.h>
+typedef enum _thd_wait_type_e {
+ THD_WAIT_MUTEX= 1,
+ THD_WAIT_DISKIO= 2,
+ THD_WAIT_ROW_TABLE_LOCK= 3,
+ THD_WAIT_GLOBAL_LOCK= 4
+} thd_wait_type;
+extern struct thd_wait_service_st {
+ void (*thd_wait_begin_func)(void*, thd_wait_type);
+ void (*thd_wait_end_func)(void*);
+} *thd_wait_service;
+void thd_wait_begin(void* thd, thd_wait_type wait_type);
+void thd_wait_end(void* thd);
+#include <mysql/service_thread_scheduler.h>
+struct scheduler_functions;
+extern struct my_thread_scheduler_service {
+ int (*set)(struct scheduler_functions *scheduler);
+ int (*reset)();
+} *my_thread_scheduler_service;
+int my_thread_scheduler_set(struct scheduler_functions *scheduler);
+int my_thread_scheduler_reset();
+struct st_mysql_xid {
+ long formatID;
+ long gtrid_length;
+ long bqual_length;
+ char data[128];
+};
+typedef struct st_mysql_xid MYSQL_XID;
+enum enum_mysql_show_type
+{
+ SHOW_UNDEF, SHOW_BOOL, SHOW_INT, SHOW_LONG,
+ SHOW_LONGLONG, SHOW_CHAR, SHOW_CHAR_PTR,
+ SHOW_ARRAY, SHOW_FUNC, SHOW_DOUBLE,
+ SHOW_always_last
+};
+struct st_mysql_show_var {
+ const char *name;
+ char *value;
+ enum enum_mysql_show_type type;
+};
+typedef int (*mysql_show_var_func)(void*, struct st_mysql_show_var*, char *);
+struct st_mysql_sys_var;
+struct st_mysql_value;
+typedef int (*mysql_var_check_func)(void* thd,
+ struct st_mysql_sys_var *var,
+ void *save, struct st_mysql_value *value);
+typedef void (*mysql_var_update_func)(void* thd,
+ struct st_mysql_sys_var *var,
+ void *var_ptr, const void *save);
+struct st_mysql_plugin
+{
+ int type;
+ void *info;
+ const char *name;
+ const char *author;
+ const char *descr;
+ int license;
+ int (*init)(void *);
+ int (*deinit)(void *);
+ unsigned int version;
+ struct st_mysql_show_var *status_vars;
+ struct st_mysql_sys_var **system_vars;
+ void * __reserved1;
+};
+#include "plugin_ftparser.h"
+#include "plugin.h"
+enum enum_ftparser_mode
+{
+ MYSQL_FTPARSER_SIMPLE_MODE= 0,
+ MYSQL_FTPARSER_WITH_STOPWORDS= 1,
+ MYSQL_FTPARSER_FULL_BOOLEAN_INFO= 2
+};
+enum enum_ft_token_type
+{
+ FT_TOKEN_EOF= 0,
+ FT_TOKEN_WORD= 1,
+ FT_TOKEN_LEFT_PAREN= 2,
+ FT_TOKEN_RIGHT_PAREN= 3,
+ FT_TOKEN_STOPWORD= 4
+};
+typedef struct st_mysql_ftparser_boolean_info
+{
+ enum enum_ft_token_type type;
+ int yesno;
+ int weight_adjust;
+ char wasign;
+ char trunc;
+ char prev;
+ char *quot;
+} MYSQL_FTPARSER_BOOLEAN_INFO;
+typedef struct st_mysql_ftparser_param
+{
+ int (*mysql_parse)(struct st_mysql_ftparser_param *,
+ char *doc, int doc_len);
+ int (*mysql_add_word)(struct st_mysql_ftparser_param *,
+ char *word, int word_len,
+ MYSQL_FTPARSER_BOOLEAN_INFO *boolean_info);
+ void *ftparser_state;
+ void *mysql_ftparam;
+ struct charset_info_st *cs;
+ char *doc;
+ int length;
+ int flags;
+ enum enum_ftparser_mode mode;
+} MYSQL_FTPARSER_PARAM;
+struct st_mysql_ftparser
+{
+ int interface_version;
+ int (*parse)(MYSQL_FTPARSER_PARAM *param);
+ int (*init)(MYSQL_FTPARSER_PARAM *param);
+ int (*deinit)(MYSQL_FTPARSER_PARAM *param);
+};
+struct st_mysql_daemon
+{
+ int interface_version;
+};
+struct st_mysql_information_schema
+{
+ int interface_version;
+};
+struct st_mysql_storage_engine
+{
+ int interface_version;
+};
+struct handlerton;
+ struct Mysql_replication {
+ int interface_version;
+ };
+struct st_mysql_value
+{
+ int (*value_type)(struct st_mysql_value *);
+ const char *(*val_str)(struct st_mysql_value *, char *buffer, int *length);
+ int (*val_real)(struct st_mysql_value *, double *realbuf);
+ int (*val_int)(struct st_mysql_value *, long long *intbuf);
+ int (*is_unsigned)(struct st_mysql_value *);
+};
+int thd_in_lock_tables(const void* thd);
+int thd_tablespace_op(const void* thd);
+long long thd_test_options(const void* thd, long long test_options);
+int thd_sql_command(const void* thd);
+const char *thd_proc_info(void* thd, const char *info);
+void **thd_ha_data(const void* thd, const struct handlerton *hton);
+void thd_storage_lock_wait(void* thd, long long value);
+int thd_tx_isolation(const void* thd);
+char *thd_security_context(void* thd, char *buffer, unsigned int length,
+ unsigned int max_query_len);
+void thd_inc_row_count(void* thd);
+int mysql_tmpfile(const char *prefix);
+int thd_killed(const void* thd);
+unsigned long thd_get_thread_id(const void* thd);
+void thd_get_xid(const void* thd, MYSQL_XID *xid);
+void mysql_query_cache_invalidate4(void* thd,
+ const char *key, unsigned int key_length,
+ int using_trx);
+void *thd_get_ha_data(const void* thd, const struct handlerton *hton);
+void thd_set_ha_data(void* thd, const struct handlerton *hton,
+ const void *ha_data);
+#include <mysql/plugin_auth_common.h>
+typedef struct st_plugin_vio_info
+{
+ enum { MYSQL_VIO_INVALID, MYSQL_VIO_TCP, MYSQL_VIO_SOCKET,
+ MYSQL_VIO_PIPE, MYSQL_VIO_MEMORY } protocol;
+ int socket;
+} MYSQL_PLUGIN_VIO_INFO;
+typedef struct st_plugin_vio
+{
+ int (*read_packet)(struct st_plugin_vio *vio,
+ unsigned char **buf);
+ int (*write_packet)(struct st_plugin_vio *vio,
+ const unsigned char *packet,
+ int packet_len);
+ void (*info)(struct st_plugin_vio *vio, struct st_plugin_vio_info *info);
+} MYSQL_PLUGIN_VIO;
+typedef struct st_mysql_server_auth_info
+{
+ char *user_name;
+ unsigned int user_name_length;
+ const char *auth_string;
+ unsigned long auth_string_length;
+ char authenticated_as[48 +1];
+ char external_user[512];
+ int password_used;
+ const char *host_or_ip;
+ unsigned int host_or_ip_length;
+} MYSQL_SERVER_AUTH_INFO;
+struct st_mysql_auth
+{
+ int interface_version;
+ const char *client_auth_plugin;
+ int (*authenticate_user)(MYSQL_PLUGIN_VIO *vio, MYSQL_SERVER_AUTH_INFO *info);
+};
diff --git a/include/mysql/plugin_auth_common.h b/include/mysql/plugin_auth_common.h
new file mode 100644
index 00000000000..4ad92d01bfb
--- /dev/null
+++ b/include/mysql/plugin_auth_common.h
@@ -0,0 +1,105 @@
+#ifndef MYSQL_PLUGIN_AUTH_COMMON_INCLUDED
+/* Copyright (C) 2010 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
+
+ This file defines constants and data structures that are the same for
+ both client- and server-side authentication plugins.
+*/
+#define MYSQL_PLUGIN_AUTH_COMMON_INCLUDED
+
+/** the max allowed length for a user name */
+#define MYSQL_USERNAME_LENGTH 48
+
+/**
+ return values of the plugin authenticate_user() method.
+*/
+
+/**
+ Authentication failed. Additionally, all other CR_xxx values
+ (libmysql error code) can be used too.
+
+ The client plugin may set the error code and the error message directly
+ in the MYSQL structure and return CR_ERROR. If a CR_xxx specific error
+ code was returned, an error message in the MYSQL structure will be
+ overwritten. If CR_ERROR is returned without setting the error in MYSQL,
+ CR_UNKNOWN_ERROR will be user.
+*/
+#define CR_ERROR 0
+/**
+ Authentication (client part) was successful. It does not mean that the
+ authentication as a whole was successful, usually it only means
+ that the client was able to send the user name and the password to the
+ server. If CR_OK is returned, the libmysql reads the next packet expecting
+ it to be one of OK, ERROR, or CHANGE_PLUGIN packets.
+*/
+#define CR_OK -1
+/**
+ Authentication was successful.
+ It means that the client has done its part successfully and also that
+ a plugin has read the last packet (one of OK, ERROR, CHANGE_PLUGIN).
+ In this case, libmysql will not read a packet from the server,
+ but it will use the data at mysql->net.read_pos.
+
+ A plugin may return this value if the number of roundtrips in the
+ authentication protocol is not known in advance, and the client plugin
+ needs to read one packet more to determine if the authentication is finished
+ or not.
+*/
+#define CR_OK_HANDSHAKE_COMPLETE -2
+
+typedef struct st_plugin_vio_info
+{
+ enum { MYSQL_VIO_INVALID, MYSQL_VIO_TCP, MYSQL_VIO_SOCKET,
+ MYSQL_VIO_PIPE, MYSQL_VIO_MEMORY } protocol;
+ int socket; /**< it's set, if the protocol is SOCKET or TCP */
+#ifdef _WIN32
+ HANDLE handle; /**< it's set, if the protocol is PIPE or MEMORY */
+#endif
+} MYSQL_PLUGIN_VIO_INFO;
+
+/**
+ Provides plugin access to communication channel
+*/
+typedef struct st_plugin_vio
+{
+ /**
+ Plugin provides a pointer reference and this function sets it to the
+ contents of any incoming packet. Returns the packet length, or -1 if
+ the plugin should terminate.
+ */
+ int (*read_packet)(struct st_plugin_vio *vio,
+ unsigned char **buf);
+
+ /**
+ Plugin provides a buffer with data and the length and this
+ function sends it as a packet. Returns 0 on success, 1 on failure.
+ */
+ int (*write_packet)(struct st_plugin_vio *vio,
+ const unsigned char *packet,
+ int packet_len);
+
+ /**
+ Fills in a st_plugin_vio_info structure, providing the information
+ about the connection.
+ */
+ void (*info)(struct st_plugin_vio *vio, struct st_plugin_vio_info *info);
+
+} MYSQL_PLUGIN_VIO;
+
+#endif
+
diff --git a/include/mysql/plugin_ftparser.h b/include/mysql/plugin_ftparser.h
new file mode 100644
index 00000000000..7f9bde3a6a0
--- /dev/null
+++ b/include/mysql/plugin_ftparser.h
@@ -0,0 +1,211 @@
+/* Copyright (C) 2005 MySQL AB
+
+ 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 _my_plugin_ftparser_h
+#define _my_plugin_ftparser_h
+#include "plugin.h"
+
+/*************************************************************************
+ API for Full-text parser plugin. (MYSQL_FTPARSER_PLUGIN)
+*/
+
+#define MYSQL_FTPARSER_INTERFACE_VERSION 0x0100
+
+/* Parsing modes. Set in MYSQL_FTPARSER_PARAM::mode */
+enum enum_ftparser_mode
+{
+/*
+ Fast and simple mode. This mode is used for indexing, and natural
+ language queries.
+
+ The parser is expected to return only those words that go into the
+ index. Stopwords or too short/long words should not be returned. The
+ 'boolean_info' argument of mysql_add_word() does not have to be set.
+*/
+ MYSQL_FTPARSER_SIMPLE_MODE= 0,
+
+/*
+ Parse with stopwords mode. This mode is used in boolean searches for
+ "phrase matching."
+
+ The parser is not allowed to ignore words in this mode. Every word
+ should be returned, including stopwords and words that are too short
+ or long. The 'boolean_info' argument of mysql_add_word() does not
+ have to be set.
+*/
+ MYSQL_FTPARSER_WITH_STOPWORDS= 1,
+
+/*
+ Parse in boolean mode. This mode is used to parse a boolean query string.
+
+ The parser should provide a valid MYSQL_FTPARSER_BOOLEAN_INFO
+ structure in the 'boolean_info' argument to mysql_add_word().
+ Usually that means that the parser should recognize boolean operators
+ in the parsing stream and set appropriate fields in
+ MYSQL_FTPARSER_BOOLEAN_INFO structure accordingly. As for
+ MYSQL_FTPARSER_WITH_STOPWORDS mode, no word should be ignored.
+ Instead, use FT_TOKEN_STOPWORD for the token type of such a word.
+*/
+ MYSQL_FTPARSER_FULL_BOOLEAN_INFO= 2
+};
+
+/*
+ Token types for boolean mode searching (used for the type member of
+ MYSQL_FTPARSER_BOOLEAN_INFO struct)
+
+ FT_TOKEN_EOF: End of data.
+ FT_TOKEN_WORD: Regular word.
+ FT_TOKEN_LEFT_PAREN: Left parenthesis (start of group/sub-expression).
+ FT_TOKEN_RIGHT_PAREN: Right parenthesis (end of group/sub-expression).
+ FT_TOKEN_STOPWORD: Stopword.
+*/
+
+enum enum_ft_token_type
+{
+ FT_TOKEN_EOF= 0,
+ FT_TOKEN_WORD= 1,
+ FT_TOKEN_LEFT_PAREN= 2,
+ FT_TOKEN_RIGHT_PAREN= 3,
+ FT_TOKEN_STOPWORD= 4
+};
+
+/*
+ This structure is used in boolean search mode only. It conveys
+ boolean-mode metadata to the MySQL search engine for every word in
+ the search query. A valid instance of this structure must be filled
+ in by the plugin parser and passed as an argument in the call to
+ mysql_add_word (the callback function in the MYSQL_FTPARSER_PARAM
+ structure) when a query is parsed in boolean mode.
+
+ type: The token type. Should be one of the enum_ft_token_type values.
+
+ yesno: Whether the word must be present for a match to occur:
+ >0 Must be present
+ <0 Must not be present
+ 0 Neither; the word is optional but its presence increases the relevance
+ With the default settings of the ft_boolean_syntax system variable,
+ >0 corresponds to the '+' operator, <0 corrresponds to the '-' operator,
+ and 0 means neither operator was used.
+
+ weight_adjust: A weighting factor that determines how much a match
+ for the word counts. Positive values increase, negative - decrease the
+ relative word's importance in the query.
+
+ wasign: The sign of the word's weight in the query. If it's non-negative
+ the match for the word will increase document relevance, if it's
+ negative - decrease (the word becomes a "noise word", the less of it the
+ better).
+
+ trunc: Corresponds to the '*' operator in the default setting of the
+ ft_boolean_syntax system variable.
+*/
+
+typedef struct st_mysql_ftparser_boolean_info
+{
+ enum enum_ft_token_type type;
+ int yesno;
+ int weight_adjust;
+ char wasign;
+ char trunc;
+ /* These are parser state and must be removed. */
+ char prev;
+ char *quot;
+} MYSQL_FTPARSER_BOOLEAN_INFO;
+
+/*
+ The following flag means that buffer with a string (document, word)
+ may be overwritten by the caller before the end of the parsing (that is
+ before st_mysql_ftparser::deinit() call). If one needs the string
+ to survive between two successive calls of the parsing function, she
+ needs to save a copy of it. The flag may be set by MySQL before calling
+ st_mysql_ftparser::parse(), or it may be set by a plugin before calling
+ st_mysql_ftparser_param::mysql_parse() or
+ st_mysql_ftparser_param::mysql_add_word().
+*/
+#define MYSQL_FTFLAGS_NEED_COPY 1
+
+/*
+ An argument of the full-text parser plugin. This structure is
+ filled in by MySQL server and passed to the parsing function of the
+ plugin as an in/out parameter.
+
+ mysql_parse: A pointer to the built-in parser implementation of the
+ server. It's set by the server and can be used by the parser plugin
+ to invoke the MySQL default parser. If plugin's role is to extract
+ textual data from .doc, .pdf or .xml content, it might extract
+ plaintext from the content, and then pass the text to the default
+ MySQL parser to be parsed.
+
+ mysql_add_word: A server callback to add a new word. When parsing
+ a document, the server sets this to point at a function that adds
+ the word to MySQL full-text index. When parsing a search query,
+ this function will add the new word to the list of words to search
+ for. The boolean_info argument can be NULL for all cases except
+ when mode is MYSQL_FTPARSER_FULL_BOOLEAN_INFO.
+
+ ftparser_state: A generic pointer. The plugin can set it to point
+ to information to be used internally for its own purposes.
+
+ mysql_ftparam: This is set by the server. It is used by MySQL functions
+ called via mysql_parse() and mysql_add_word() callback. The plugin
+ should not modify it.
+
+ cs: Information about the character set of the document or query string.
+
+ doc: A pointer to the document or query string to be parsed.
+
+ length: Length of the document or query string, in bytes.
+
+ flags: See MYSQL_FTFLAGS_* constants above.
+
+ mode: The parsing mode. With boolean operators, with stopwords, or
+ nothing. See enum_ftparser_mode above.
+*/
+
+typedef struct st_mysql_ftparser_param
+{
+ int (*mysql_parse)(struct st_mysql_ftparser_param *,
+ char *doc, int doc_len);
+ int (*mysql_add_word)(struct st_mysql_ftparser_param *,
+ char *word, int word_len,
+ MYSQL_FTPARSER_BOOLEAN_INFO *boolean_info);
+ void *ftparser_state;
+ void *mysql_ftparam;
+ struct charset_info_st *cs;
+ char *doc;
+ int length;
+ int flags;
+ enum enum_ftparser_mode mode;
+} MYSQL_FTPARSER_PARAM;
+
+/*
+ Full-text parser descriptor.
+
+ interface_version is, e.g., MYSQL_FTPARSER_INTERFACE_VERSION.
+ The parsing, initialization, and deinitialization functions are
+ invoked per SQL statement for which the parser is used.
+*/
+
+struct st_mysql_ftparser
+{
+ int interface_version;
+ int (*parse)(MYSQL_FTPARSER_PARAM *param);
+ int (*init)(MYSQL_FTPARSER_PARAM *param);
+ int (*deinit)(MYSQL_FTPARSER_PARAM *param);
+};
+
+
+#endif
+
diff --git a/include/mysql/plugin.h.pp b/include/mysql/plugin_ftparser.h.pp
index e4906ea6547..2c2c1adbf88 100644
--- a/include/mysql/plugin.h.pp
+++ b/include/mysql/plugin_ftparser.h.pp
@@ -1,9 +1,57 @@
+#include "plugin.h"
+#include <mysql/services.h>
+#include <mysql/service_my_snprintf.h>
+extern struct my_snprintf_service_st {
+ size_t (*my_snprintf_type)(char*, size_t, const char*, ...);
+ size_t (*my_vsnprintf_type)(char *, size_t, const char*, va_list);
+} *my_snprintf_service;
+size_t my_snprintf(char* to, size_t n, const char* fmt, ...);
+size_t my_vsnprintf(char *to, size_t n, const char* fmt, va_list ap);
+#include <mysql/service_thd_alloc.h>
struct st_mysql_lex_string
{
char *str;
- unsigned int length;
+ size_t length;
};
typedef struct st_mysql_lex_string MYSQL_LEX_STRING;
+extern struct thd_alloc_service_st {
+ void *(*thd_alloc_func)(void*, unsigned int);
+ void *(*thd_calloc_func)(void*, unsigned int);
+ char *(*thd_strdup_func)(void*, const char *);
+ char *(*thd_strmake_func)(void*, const char *, unsigned int);
+ void *(*thd_memdup_func)(void*, const void*, unsigned int);
+ MYSQL_LEX_STRING *(*thd_make_lex_string_func)(void*, MYSQL_LEX_STRING *,
+ const char *, unsigned int, int);
+} *thd_alloc_service;
+void *thd_alloc(void* thd, unsigned int size);
+void *thd_calloc(void* thd, unsigned int size);
+char *thd_strdup(void* thd, const char *str);
+char *thd_strmake(void* thd, const char *str, unsigned int size);
+void *thd_memdup(void* thd, const void* str, unsigned int size);
+MYSQL_LEX_STRING *thd_make_lex_string(void* thd, MYSQL_LEX_STRING *lex_str,
+ const char *str, unsigned int size,
+ int allocate_lex_string);
+#include <mysql/service_thd_wait.h>
+typedef enum _thd_wait_type_e {
+ THD_WAIT_MUTEX= 1,
+ THD_WAIT_DISKIO= 2,
+ THD_WAIT_ROW_TABLE_LOCK= 3,
+ THD_WAIT_GLOBAL_LOCK= 4
+} thd_wait_type;
+extern struct thd_wait_service_st {
+ void (*thd_wait_begin_func)(void*, thd_wait_type);
+ void (*thd_wait_end_func)(void*);
+} *thd_wait_service;
+void thd_wait_begin(void* thd, thd_wait_type wait_type);
+void thd_wait_end(void* thd);
+#include <mysql/service_thread_scheduler.h>
+struct scheduler_functions;
+extern struct my_thread_scheduler_service {
+ int (*set)(struct scheduler_functions *scheduler);
+ int (*reset)();
+} *my_thread_scheduler_service;
+int my_thread_scheduler_set(struct scheduler_functions *scheduler);
+int my_thread_scheduler_reset();
struct st_mysql_xid {
long formatID;
long gtrid_length;
@@ -15,7 +63,8 @@ enum enum_mysql_show_type
{
SHOW_UNDEF, SHOW_BOOL, SHOW_INT, SHOW_LONG,
SHOW_LONGLONG, SHOW_CHAR, SHOW_CHAR_PTR,
- SHOW_ARRAY, SHOW_FUNC, SHOW_DOUBLE
+ SHOW_ARRAY, SHOW_FUNC, SHOW_DOUBLE,
+ SHOW_always_last
};
struct st_mysql_show_var {
const char *name;
@@ -46,6 +95,52 @@ struct st_mysql_plugin
struct st_mysql_sys_var **system_vars;
void * __reserved1;
};
+#include "plugin_ftparser.h"
+struct st_mysql_daemon
+{
+ int interface_version;
+};
+struct st_mysql_information_schema
+{
+ int interface_version;
+};
+struct st_mysql_storage_engine
+{
+ int interface_version;
+};
+struct handlerton;
+ struct Mysql_replication {
+ int interface_version;
+ };
+struct st_mysql_value
+{
+ int (*value_type)(struct st_mysql_value *);
+ const char *(*val_str)(struct st_mysql_value *, char *buffer, int *length);
+ int (*val_real)(struct st_mysql_value *, double *realbuf);
+ int (*val_int)(struct st_mysql_value *, long long *intbuf);
+ int (*is_unsigned)(struct st_mysql_value *);
+};
+int thd_in_lock_tables(const void* thd);
+int thd_tablespace_op(const void* thd);
+long long thd_test_options(const void* thd, long long test_options);
+int thd_sql_command(const void* thd);
+const char *thd_proc_info(void* thd, const char *info);
+void **thd_ha_data(const void* thd, const struct handlerton *hton);
+void thd_storage_lock_wait(void* thd, long long value);
+int thd_tx_isolation(const void* thd);
+char *thd_security_context(void* thd, char *buffer, unsigned int length,
+ unsigned int max_query_len);
+void thd_inc_row_count(void* thd);
+int mysql_tmpfile(const char *prefix);
+int thd_killed(const void* thd);
+unsigned long thd_get_thread_id(const void* thd);
+void thd_get_xid(const void* thd, MYSQL_XID *xid);
+void mysql_query_cache_invalidate4(void* thd,
+ const char *key, unsigned int key_length,
+ int using_trx);
+void *thd_get_ha_data(const void* thd, const struct handlerton *hton);
+void thd_set_ha_data(void* thd, const struct handlerton *hton,
+ const void *ha_data);
enum enum_ftparser_mode
{
MYSQL_FTPARSER_SIMPLE_MODE= 0,
@@ -92,51 +187,3 @@ struct st_mysql_ftparser
int (*init)(MYSQL_FTPARSER_PARAM *param);
int (*deinit)(MYSQL_FTPARSER_PARAM *param);
};
-struct st_mysql_storage_engine
-{
- int interface_version;
-};
-struct handlerton;
-struct st_mysql_daemon
-{
- int interface_version;
-};
-struct st_mysql_information_schema
-{
- int interface_version;
-};
-struct st_mysql_value
-{
- int (*value_type)(struct st_mysql_value *);
- const char *(*val_str)(struct st_mysql_value *, char *buffer, int *length);
- int (*val_real)(struct st_mysql_value *, double *realbuf);
- int (*val_int)(struct st_mysql_value *, long long *intbuf);
-};
-int thd_in_lock_tables(const void* thd);
-int thd_tablespace_op(const void* thd);
-long long thd_test_options(const void* thd, long long test_options);
-int thd_sql_command(const void* thd);
-const char *thd_proc_info(void* thd, const char *info);
-void **thd_ha_data(const void* thd, const struct handlerton *hton);
-int thd_tx_isolation(const void* thd);
-char *thd_security_context(void* thd, char *buffer, unsigned int length,
- unsigned int max_query_len);
-void thd_inc_row_count(void* thd);
-int mysql_tmpfile(const char *prefix);
-int thd_killed(const void* thd);
-unsigned long thd_get_thread_id(const void* thd);
-void *thd_alloc(void* thd, unsigned int size);
-void *thd_calloc(void* thd, unsigned int size);
-char *thd_strdup(void* thd, const char *str);
-char *thd_strmake(void* thd, const char *str, unsigned int size);
-void *thd_memdup(void* thd, const void* str, unsigned int size);
-MYSQL_LEX_STRING *thd_make_lex_string(void* thd, MYSQL_LEX_STRING *lex_str,
- const char *str, unsigned int size,
- int allocate_lex_string);
-void thd_get_xid(const void* thd, MYSQL_XID *xid);
-void mysql_query_cache_invalidate4(void* thd,
- const char *key, unsigned int key_length,
- int using_trx);
-void *thd_get_ha_data(const void* thd, const struct handlerton *hton);
-void thd_set_ha_data(void* thd, const struct handlerton *hton,
- const void *ha_data);
diff --git a/include/mysql/psi/mysql_file.h b/include/mysql/psi/mysql_file.h
new file mode 100644
index 00000000000..de145f642e1
--- /dev/null
+++ b/include/mysql/psi/mysql_file.h
@@ -0,0 +1,1432 @@
+/* Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ 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,
+ 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
+
+#ifndef MYSQL_FILE_H
+#define MYSQL_FILE_H
+
+/* For strlen() */
+#include <string.h>
+/* For MY_STAT */
+#include <my_dir.h>
+/* For my_chsize */
+#include <my_sys.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;
+ PSI_file_locker_state state;
+ if (likely(PSI_server && file->m_psi))
+ {
+ locker= PSI_server->get_thread_file_stream_locker(&state, 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;
+ PSI_file_locker_state state;
+ if (likely(PSI_server && file->m_psi))
+ {
+ locker= PSI_server->get_thread_file_stream_locker(&state, 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;
+ PSI_file_locker_state state;
+ size_t bytes= 0;
+ if (likely(PSI_server && file->m_psi))
+ {
+ locker= PSI_server->get_thread_file_stream_locker(&state, 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;
+ PSI_file_locker_state state;
+ if (likely(PSI_server && file->m_psi))
+ {
+ locker= PSI_server->get_thread_file_stream_locker(&state, 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;
+ PSI_file_locker_state state;
+ if (likely(PSI_server && file->m_psi))
+ {
+ locker= PSI_server->get_thread_file_stream_locker(&state, 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;
+ PSI_file_locker_state state;
+ if (likely(PSI_server && file->m_psi))
+ {
+ locker= PSI_server->get_thread_file_stream_locker(&state, 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;
+ PSI_file_locker_state state;
+ if (likely(PSI_server && file->m_psi))
+ {
+ locker= PSI_server->get_thread_file_stream_locker(&state, 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;
+ PSI_file_locker_state state;
+ if (likely(PSI_server != NULL))
+ {
+ locker= PSI_server->get_thread_file_descriptor_locker(&state, 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;
+ PSI_file_locker_state state;
+ if (likely(PSI_server != NULL))
+ {
+ locker= PSI_server->get_thread_file_name_locker(&state,
+ 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;
+ PSI_file_locker_state state;
+ if (likely(PSI_server != NULL))
+ {
+ locker= PSI_server->get_thread_file_descriptor_locker(&state, 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;
+ PSI_file_locker_state state;
+ if (likely(PSI_server != NULL))
+ {
+ locker= PSI_server->get_thread_file_name_locker
+ (&state, 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);
+ 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;
+ PSI_file_locker_state state;
+ DBUG_ASSERT(file != NULL);
+ if (likely(PSI_server && file->m_psi))
+ {
+ locker= PSI_server->get_thread_file_stream_locker(&state, 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);
+ }
+ 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;
+ PSI_file_locker_state state;
+ if (likely(PSI_server && file->m_psi))
+ {
+ locker= PSI_server->get_thread_file_stream_locker(&state, 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;
+ PSI_file_locker_state state;
+ if (likely(PSI_server && file->m_psi))
+ {
+ locker= PSI_server->get_thread_file_stream_locker(&state, 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;
+ PSI_file_locker_state state;
+ if (likely(PSI_server && file->m_psi))
+ {
+ locker= PSI_server->get_thread_file_stream_locker(&state, 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;
+ PSI_file_locker_state state;
+ if (likely(PSI_server && file->m_psi))
+ {
+ locker= PSI_server->get_thread_file_stream_locker(&state, 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;
+ PSI_file_locker_state state;
+ if (likely(PSI_server != NULL))
+ {
+ locker= PSI_server->get_thread_file_name_locker(&state, 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;
+ PSI_file_locker_state state;
+ if (likely(PSI_server != NULL))
+ {
+ locker= PSI_server->get_thread_file_name_locker(&state, 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;
+ PSI_file_locker_state state;
+ if (likely(PSI_server != NULL))
+ {
+ locker= PSI_server->get_thread_file_descriptor_locker(&state, 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;
+ PSI_file_locker_state state;
+ if (likely(PSI_server != NULL))
+ {
+ locker= PSI_server->get_thread_file_descriptor_locker(&state, 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;
+ PSI_file_locker_state state;
+ if (likely(PSI_server != NULL))
+ {
+ locker= PSI_server->get_thread_file_descriptor_locker(&state, 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;
+ PSI_file_locker_state state;
+ if (likely(PSI_server != NULL))
+ {
+ locker= PSI_server->get_thread_file_descriptor_locker(&state, 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;
+ PSI_file_locker_state state;
+ if (likely(PSI_server != NULL))
+ {
+ locker= PSI_server->get_thread_file_descriptor_locker(&state, 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;
+ PSI_file_locker_state state;
+ if (likely(PSI_server != NULL))
+ {
+ locker= PSI_server->get_thread_file_descriptor_locker(&state, 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;
+ PSI_file_locker_state state;
+ if (likely(PSI_server != NULL))
+ {
+ locker= PSI_server->get_thread_file_descriptor_locker(&state, 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;
+ PSI_file_locker_state state;
+ if (likely(PSI_server != NULL))
+ {
+ locker= PSI_server->get_thread_file_name_locker(&state, 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;
+ PSI_file_locker_state state;
+ if (likely(PSI_server != NULL))
+ {
+ locker= PSI_server->get_thread_file_name_locker(&state, 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;
+ PSI_file_locker_state state;
+ if (likely(PSI_server != NULL))
+ {
+ locker= PSI_server->get_thread_file_name_locker(&state, 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;
+ PSI_file_locker_state state;
+ if (likely(PSI_server != NULL))
+ {
+ locker= PSI_server->get_thread_file_name_locker(&state, 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;
+ PSI_file_locker_state state;
+ if (likely(PSI_server != NULL))
+ {
+ locker= PSI_server->get_thread_file_name_locker(&state, 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;
+ PSI_file_locker_state state;
+ if (likely(PSI_server != NULL))
+ {
+ locker= PSI_server->get_thread_file_descriptor_locker(&state, 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..5b8ea3dc5dc
--- /dev/null
+++ b/include/mysql/psi/mysql_thread.h
@@ -0,0 +1,1071 @@
+/* Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ 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,
+ 51 Franklin Street, Suite 500, Boston, MA 02110-1335 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;
+};
+
+/**
+ An instrumented prlock structure.
+ @sa mysql_prlock_t
+*/
+struct st_mysql_prlock
+{
+ /** The real prlock */
+ rw_pr_lock_t m_prlock;
+ /**
+ 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;
+
+/**
+ Type of an instrumented prlock.
+ A prlock is a read write lock that 'prefers readers' (pr).
+ @c mysql_prlock_t is a drop-in replacement for @c rw_pr_lock_t.
+ @sa mysql_prlock_init
+ @sa mysql_prlock_rdlock
+ @sa mysql_prlock_wrlock
+ @sa mysql_prlock_unlock
+ @sa mysql_prlock_destroy
+*/
+typedef struct st_mysql_prlock mysql_prlock_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.
+ DISABLE_MYSQL_PRLOCK_H is similar, and is used to disable specifically
+ the prlock wrappers.
+*/
+#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)
+
+/** Wrappers for instrumented prlock objects. */
+
+#define mysql_prlock_assert_write_owner(M) \
+ rw_pr_lock_assert_write_owner(&(M)->m_prlock)
+
+#define mysql_prlock_assert_not_write_owner(M) \
+ rw_pr_lock_assert_not_write_owner(&(M)->m_prlock)
+
+/**
+ @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_prlock_init(K, RW)
+ Instrumented rw_pr_init.
+ @c mysql_prlock_init is a replacement for @c rw_pr_init.
+ @param K The PSI_rwlock_key for this instrumented prlock
+ @param RW The prlock to initialize
+*/
+#ifdef HAVE_PSI_INTERFACE
+ #define mysql_prlock_init(K, RW) inline_mysql_prlock_init(K, RW)
+#else
+ #define mysql_prlock_init(K, RW) inline_mysql_prlock_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_prlock_destroy(RW)
+ Instrumented rw_pr_destroy.
+ @c mysql_prlock_destroy is a drop-in replacement
+ for @c rw_pr_destroy.
+*/
+#define mysql_prlock_destroy(RW) inline_mysql_prlock_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_prlock_rdlock(RW)
+ Instrumented rw_pr_rdlock.
+ @c mysql_prlock_rdlock is a drop-in replacement
+ for @c rw_pr_rdlock.
+*/
+#ifdef HAVE_PSI_INTERFACE
+ #define mysql_prlock_rdlock(RW) \
+ inline_mysql_prlock_rdlock(RW, __FILE__, __LINE__)
+#else
+ #define mysql_prlock_rdlock(RW) \
+ inline_mysql_prlock_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_prlock_wrlock(RW)
+ Instrumented rw_pr_wrlock.
+ @c mysql_prlock_wrlock is a drop-in replacement
+ for @c rw_pr_wrlock.
+*/
+#ifdef HAVE_PSI_INTERFACE
+ #define mysql_prlock_wrlock(RW) \
+ inline_mysql_prlock_wrlock(RW, __FILE__, __LINE__)
+#else
+ #define mysql_prlock_wrlock(RW) \
+ inline_mysql_prlock_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_prlock_unlock(RW)
+ Instrumented rw_pr_unlock.
+ @c mysql_prlock_unlock is a drop-in replacement
+ for @c rw_pr_unlock.
+*/
+#define mysql_prlock_unlock(RW) inline_mysql_prlock_unlock(RW)
+
+/**
+ @def mysql_cond_init(K, C, A)
+ Instrumented cond_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;
+ PSI_mutex_locker_state state;
+ if (likely(PSI_server && that->m_psi))
+ {
+ locker= PSI_server->get_thread_mutex_locker(&state, 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;
+ PSI_mutex_locker_state state;
+ if (likely(PSI_server && that->m_psi))
+ {
+ locker= PSI_server->get_thread_mutex_locker(&state, 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
+ if (likely(PSI_server && that->m_psi))
+ PSI_server->unlock_mutex(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);
+}
+
+#ifndef DISABLE_MYSQL_PRLOCK_H
+static inline int inline_mysql_prlock_init(
+#ifdef HAVE_PSI_INTERFACE
+ PSI_rwlock_key key,
+#endif
+ mysql_prlock_t *that)
+{
+#ifdef HAVE_PSI_INTERFACE
+ that->m_psi= (PSI_server ? PSI_server->init_rwlock(key, &that->m_prlock)
+ : NULL);
+#else
+ that->m_psi= NULL;
+#endif
+ return rw_pr_init(&that->m_prlock);
+}
+#endif
+
+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);
+}
+
+#ifndef DISABLE_MYSQL_PRLOCK_H
+static inline int inline_mysql_prlock_destroy(
+ mysql_prlock_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 rw_pr_destroy(&that->m_prlock);
+}
+#endif
+
+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;
+ PSI_rwlock_locker_state state;
+ if (likely(PSI_server && that->m_psi))
+ {
+ locker= PSI_server->get_thread_rwlock_locker(&state, 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;
+}
+
+#ifndef DISABLE_MYSQL_PRLOCK_H
+static inline int inline_mysql_prlock_rdlock(
+ mysql_prlock_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;
+ PSI_rwlock_locker_state state;
+ if (likely(PSI_server && that->m_psi))
+ {
+ locker= PSI_server->get_thread_rwlock_locker(&state, that->m_psi,
+ PSI_RWLOCK_READLOCK);
+ if (likely(locker != NULL))
+ PSI_server->start_rwlock_rdwait(locker, src_file, src_line);
+ }
+#endif
+ result= rw_pr_rdlock(&that->m_prlock);
+#ifdef HAVE_PSI_INTERFACE
+ if (likely(locker != NULL))
+ PSI_server->end_rwlock_rdwait(locker, result);
+#endif
+ return result;
+}
+#endif
+
+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;
+ PSI_rwlock_locker_state state;
+ if (likely(PSI_server && that->m_psi))
+ {
+ locker= PSI_server->get_thread_rwlock_locker(&state, 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;
+}
+
+#ifndef DISABLE_MYSQL_PRLOCK_H
+static inline int inline_mysql_prlock_wrlock(
+ mysql_prlock_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;
+ PSI_rwlock_locker_state state;
+ if (likely(PSI_server && that->m_psi))
+ {
+ locker= PSI_server->get_thread_rwlock_locker(&state, that->m_psi,
+ PSI_RWLOCK_WRITELOCK);
+ if (likely(locker != NULL))
+ PSI_server->start_rwlock_wrwait(locker, src_file, src_line);
+ }
+#endif
+ result= rw_pr_wrlock(&that->m_prlock);
+#ifdef HAVE_PSI_INTERFACE
+ if (likely(locker != NULL))
+ PSI_server->end_rwlock_wrwait(locker, result);
+#endif
+ return result;
+}
+#endif
+
+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;
+ PSI_rwlock_locker_state state;
+ if (likely(PSI_server && that->m_psi))
+ {
+ locker= PSI_server->get_thread_rwlock_locker(&state, 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;
+ PSI_rwlock_locker_state state;
+ if (likely(PSI_server && that->m_psi))
+ {
+ locker= PSI_server->get_thread_rwlock_locker(&state, 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
+ if (likely(PSI_server && that->m_psi))
+ PSI_server->unlock_rwlock(that->m_psi);
+#endif
+ result= rw_unlock(&that->m_rwlock);
+ return result;
+}
+
+#ifndef DISABLE_MYSQL_PRLOCK_H
+static inline int inline_mysql_prlock_unlock(
+ mysql_prlock_t *that)
+{
+ int result;
+#ifdef HAVE_PSI_INTERFACE
+ if (likely(PSI_server && that->m_psi))
+ PSI_server->unlock_rwlock(that->m_psi);
+#endif
+ result= rw_pr_unlock(&that->m_prlock);
+ return result;
+}
+#endif
+
+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;
+ PSI_cond_locker_state state;
+ if (likely(PSI_server && that->m_psi))
+ {
+ locker= PSI_server->get_thread_cond_locker(&state, 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;
+ PSI_cond_locker_state state;
+ if (likely(PSI_server && that->m_psi))
+ {
+ locker= PSI_server->get_thread_cond_locker(&state, 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
+ if (likely(PSI_server && that->m_psi))
+ PSI_server->signal_cond(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
+ if (likely(PSI_server && that->m_psi))
+ PSI_server->broadcast_cond(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..562e4a80fd5
--- /dev/null
+++ b/include/mysql/psi/psi.h
@@ -0,0 +1,1312 @@
+/* Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ 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,
+ 51 Franklin Street, Suite 500, Boston, MA 02110-1335 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;
+};
+
+/**
+ State data storage for @c get_thread_mutex_locker_v1_t.
+ This structure provide temporary storage to a mutex locker.
+ The content of this structure is considered opaque,
+ the fields are only hints of what an implementation
+ of the psi interface can use.
+ This memory is provided by the instrumented code for performance reasons.
+ @sa get_thread_mutex_locker_v1_t
+*/
+struct PSI_mutex_locker_state_v1
+{
+ /** Internal state. */
+ uint m_flags;
+ /** Current mutex. */
+ struct PSI_mutex *m_mutex;
+ /** Current thread. */
+ struct PSI_thread *m_thread;
+ /** Timer start. */
+ ulonglong m_timer_start;
+ /** Timer function. */
+ ulonglong (*m_timer)(void);
+ /** Current operation. */
+ enum PSI_mutex_operation m_operation;
+ /** Source file. */
+ const char* m_src_file;
+ /** Source line number. */
+ int m_src_line;
+ /** Internal data. */
+ void *m_wait;
+};
+
+/**
+ State data storage for @c get_thread_rwlock_locker_v1_t.
+ This structure provide temporary storage to a rwlock locker.
+ The content of this structure is considered opaque,
+ the fields are only hints of what an implementation
+ of the psi interface can use.
+ This memory is provided by the instrumented code for performance reasons.
+ @sa get_thread_rwlock_locker_v1_t
+*/
+struct PSI_rwlock_locker_state_v1
+{
+ /** Internal state. */
+ uint m_flags;
+ /** Current rwlock. */
+ struct PSI_rwlock *m_rwlock;
+ /** Current thread. */
+ struct PSI_thread *m_thread;
+ /** Timer start. */
+ ulonglong m_timer_start;
+ /** Timer function. */
+ ulonglong (*m_timer)(void);
+ /** Current operation. */
+ enum PSI_rwlock_operation m_operation;
+ /** Source file. */
+ const char* m_src_file;
+ /** Source line number. */
+ int m_src_line;
+ /** Internal data. */
+ void *m_wait;
+};
+
+/**
+ State data storage for @c get_thread_cond_locker_v1_t.
+ This structure provide temporary storage to a condition locker.
+ The content of this structure is considered opaque,
+ the fields are only hints of what an implementation
+ of the psi interface can use.
+ This memory is provided by the instrumented code for performance reasons.
+ @sa get_thread_cond_locker_v1_t
+*/
+struct PSI_cond_locker_state_v1
+{
+ /** Internal state. */
+ uint m_flags;
+ /** Current condition. */
+ struct PSI_cond *m_cond;
+ /** Current mutex. */
+ struct PSI_mutex *m_mutex;
+ /** Current thread. */
+ struct PSI_thread *m_thread;
+ /** Timer start. */
+ ulonglong m_timer_start;
+ /** Timer function. */
+ ulonglong (*m_timer)(void);
+ /** Current operation. */
+ enum PSI_cond_operation m_operation;
+ /** Source file. */
+ const char* m_src_file;
+ /** Source line number. */
+ int m_src_line;
+ /** Internal data. */
+ void *m_wait;
+};
+
+/**
+ State data storage for @c get_thread_file_name_locker_v1_t.
+ This structure provide temporary storage to a file locker.
+ The content of this structure is considered opaque,
+ the fields are only hints of what an implementation
+ of the psi interface can use.
+ This memory is provided by the instrumented code for performance reasons.
+ @sa get_thread_file_name_locker_v1_t
+ @sa get_thread_file_stream_locker_v1_t
+ @sa get_thread_file_descriptor_locker_v1_t
+*/
+struct PSI_file_locker_state_v1
+{
+ /** Internal state. */
+ uint m_flags;
+ /** Current file. */
+ struct PSI_file *m_file;
+ /** Current thread. */
+ struct PSI_thread *m_thread;
+ /** Operation number of bytes. */
+ size_t m_number_of_bytes;
+ /** Timer start. */
+ ulonglong m_timer_start;
+ /** Timer function. */
+ ulonglong (*m_timer)(void);
+ /** Current operation. */
+ enum PSI_file_operation m_operation;
+ /** Source file. */
+ const char* m_src_file;
+ /** Source line number. */
+ int m_src_line;
+ /** Internal data. */
+ void *m_wait;
+};
+
+/**
+ State data storage for @c get_thread_table_locker_v1_t.
+ This structure provide temporary storage to a table locker.
+ The content of this structure is considered opaque,
+ the fields are only hints of what an implementation
+ of the psi interface can use.
+ This memory is provided by the instrumented code for performance reasons.
+ @sa get_thread_table_locker_v1_t
+*/
+struct PSI_table_locker_state_v1
+{
+ /** Internal state. */
+ uint m_flags;
+ /** Current table handle. */
+ struct PSI_table *m_table;
+ /** Current table share. */
+ struct PSI_table_share *m_table_share;
+ /** Instrumentation class. */
+ void *m_class;
+ /** Current thread. */
+ struct PSI_thread *m_thread;
+ /** Timer start. */
+ ulonglong m_timer_start;
+ /** Timer function. */
+ ulonglong (*m_timer)(void);
+ /* Current operation (waiting for WL#4895). */
+ /* enum PSI_table_operation m_operation; */
+ /** Current table io index. */
+ uint m_index;
+ /** Current table lock index. */
+ uint m_lock_index;
+ /** Source file. */
+ const char* m_src_file;
+ /** Source line number. */
+ int m_src_line;
+ /** Internal data. */
+ void *m_wait;
+};
+
+/* 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);
+
+/** Delete a thread instrumentation. */
+typedef void (*delete_thread_v1_t)(struct PSI_thread *thread);
+
+/**
+ Get a mutex instrumentation locker.
+ @param state data storage for the 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_locker_state_v1 *state,
+ struct PSI_mutex *mutex,
+ enum PSI_mutex_operation op);
+
+/**
+ Get a rwlock instrumentation locker.
+ @param state data storage for the 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_locker_state_v1 *state,
+ struct PSI_rwlock *rwlock,
+ enum PSI_rwlock_operation op);
+
+/**
+ Get a cond instrumentation locker.
+ @param state data storage for the 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_locker_state_v1 *state,
+ struct PSI_cond *cond, struct PSI_mutex *mutex,
+ enum PSI_cond_operation op);
+
+/**
+ Get a table instrumentation locker.
+ @param state data storage for the 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_locker_state_v1 *state,
+ struct PSI_table *table);
+
+/**
+ Get a file instrumentation locker, for opening or creating a file.
+ @param state data storage for the locker
+ @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)
+ (struct PSI_file_locker_state_v1 *state,
+ PSI_file_key key, enum PSI_file_operation op, const char *name,
+ const void *identity);
+
+/**
+ Get a file stream instrumentation locker.
+ @param state data storage for the 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_locker_state_v1 *state,
+ struct PSI_file *file, enum PSI_file_operation op);
+
+/**
+ Get a file instrumentation locker.
+ @param state data storage for the 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)
+ (struct PSI_file_locker_state_v1 *state,
+ File file, enum PSI_file_operation op);
+
+/**
+ Record a mutex instrumentation unlock event.
+ @param mutex the mutex instrumentation
+*/
+typedef void (*unlock_mutex_v1_t)
+ (struct PSI_mutex *mutex);
+
+/**
+ Record a rwlock instrumentation unlock event.
+ @param rwlock the rwlock instrumentation
+*/
+typedef void (*unlock_rwlock_v1_t)
+ (struct PSI_rwlock *rwlock);
+
+/**
+ Record a condition instrumentation signal event.
+ @param cond the cond instrumentation
+*/
+typedef void (*signal_cond_v1_t)
+ (struct PSI_cond *cond);
+
+/**
+ Record a condition instrumentation broadcast event.
+ @param cond the cond instrumentation
+*/
+typedef void (*broadcast_cond_v1_t)
+ (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 delete_thread_v1_t. */
+ delete_thread_v1_t delete_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;
+};
+
+struct PSI_mutex_locker_state_v2
+{
+ /** Placeholder */
+ int placeholder;
+};
+
+struct PSI_rwlock_locker_state_v2
+{
+ /** Placeholder */
+ int placeholder;
+};
+
+struct PSI_cond_locker_state_v2
+{
+ /** Placeholder */
+ int placeholder;
+};
+
+struct PSI_file_locker_state_v2
+{
+ /** Placeholder */
+ int placeholder;
+};
+
+struct PSI_table_locker_state_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;
+typedef struct PSI_mutex_locker_state_v1 PSI_mutex_locker_state;
+typedef struct PSI_rwlock_locker_state_v1 PSI_rwlock_locker_state;
+typedef struct PSI_cond_locker_state_v1 PSI_cond_locker_state;
+typedef struct PSI_file_locker_state_v1 PSI_file_locker_state;
+typedef struct PSI_table_locker_state_v1 PSI_table_locker_state;
+#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;
+typedef struct PSI_mutex_locker_state_v2 PSI_mutex_locker_state;
+typedef struct PSI_rwlock_locker_state_v2 PSI_rwlock_locker_state;
+typedef struct PSI_cond_locker_state_v2 PSI_cond_locker_state;
+typedef struct PSI_file_locker_state_v2 PSI_file_locker_state;
+typedef struct PSI_table_locker_state_v2 PSI_table_locker_state;
+#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..0f62291696f
--- /dev/null
+++ b/include/mysql/psi/psi_abi_v1.h
@@ -0,0 +1,26 @@
+/* Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ 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,
+ 51 Franklin Street, Suite 500, Boston, MA 02110-1335 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..adb3010469b
--- /dev/null
+++ b/include/mysql/psi/psi_abi_v1.h.pp
@@ -0,0 +1,323 @@
+#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;
+};
+struct PSI_mutex_locker_state_v1
+{
+ uint m_flags;
+ struct PSI_mutex *m_mutex;
+ struct PSI_thread *m_thread;
+ ulonglong m_timer_start;
+ ulonglong (*m_timer)(void);
+ enum PSI_mutex_operation m_operation;
+ const char* m_src_file;
+ int m_src_line;
+ void *m_wait;
+};
+struct PSI_rwlock_locker_state_v1
+{
+ uint m_flags;
+ struct PSI_rwlock *m_rwlock;
+ struct PSI_thread *m_thread;
+ ulonglong m_timer_start;
+ ulonglong (*m_timer)(void);
+ enum PSI_rwlock_operation m_operation;
+ const char* m_src_file;
+ int m_src_line;
+ void *m_wait;
+};
+struct PSI_cond_locker_state_v1
+{
+ uint m_flags;
+ struct PSI_cond *m_cond;
+ struct PSI_mutex *m_mutex;
+ struct PSI_thread *m_thread;
+ ulonglong m_timer_start;
+ ulonglong (*m_timer)(void);
+ enum PSI_cond_operation m_operation;
+ const char* m_src_file;
+ int m_src_line;
+ void *m_wait;
+};
+struct PSI_file_locker_state_v1
+{
+ uint m_flags;
+ struct PSI_file *m_file;
+ struct PSI_thread *m_thread;
+ size_t m_number_of_bytes;
+ ulonglong m_timer_start;
+ ulonglong (*m_timer)(void);
+ enum PSI_file_operation m_operation;
+ const char* m_src_file;
+ int m_src_line;
+ void *m_wait;
+};
+struct PSI_table_locker_state_v1
+{
+ uint m_flags;
+ struct PSI_table *m_table;
+ struct PSI_table_share *m_table_share;
+ void *m_class;
+ struct PSI_thread *m_thread;
+ ulonglong m_timer_start;
+ ulonglong (*m_timer)(void);
+ uint m_index;
+ uint m_lock_index;
+ const char* m_src_file;
+ int m_src_line;
+ void *m_wait;
+};
+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 void (*delete_thread_v1_t)(struct PSI_thread *thread);
+typedef struct PSI_mutex_locker* (*get_thread_mutex_locker_v1_t)
+ (struct PSI_mutex_locker_state_v1 *state,
+ struct PSI_mutex *mutex,
+ enum PSI_mutex_operation op);
+typedef struct PSI_rwlock_locker* (*get_thread_rwlock_locker_v1_t)
+ (struct PSI_rwlock_locker_state_v1 *state,
+ struct PSI_rwlock *rwlock,
+ enum PSI_rwlock_operation op);
+typedef struct PSI_cond_locker* (*get_thread_cond_locker_v1_t)
+ (struct PSI_cond_locker_state_v1 *state,
+ 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_locker_state_v1 *state,
+ struct PSI_table *table);
+typedef struct PSI_file_locker* (*get_thread_file_name_locker_v1_t)
+ (struct PSI_file_locker_state_v1 *state,
+ 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_locker_state_v1 *state,
+ struct PSI_file *file, enum PSI_file_operation op);
+typedef struct PSI_file_locker* (*get_thread_file_descriptor_locker_v1_t)
+ (struct PSI_file_locker_state_v1 *state,
+ File file, enum PSI_file_operation op);
+typedef void (*unlock_mutex_v1_t)
+ (struct PSI_mutex *mutex);
+typedef void (*unlock_rwlock_v1_t)
+ (struct PSI_rwlock *rwlock);
+typedef void (*signal_cond_v1_t)
+ (struct PSI_cond *cond);
+typedef void (*broadcast_cond_v1_t)
+ (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;
+ delete_thread_v1_t delete_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;
+typedef struct PSI_mutex_locker_state_v1 PSI_mutex_locker_state;
+typedef struct PSI_rwlock_locker_state_v1 PSI_rwlock_locker_state;
+typedef struct PSI_cond_locker_state_v1 PSI_cond_locker_state;
+typedef struct PSI_file_locker_state_v1 PSI_file_locker_state;
+typedef struct PSI_table_locker_state_v1 PSI_table_locker_state;
+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..08bca609b41
--- /dev/null
+++ b/include/mysql/psi/psi_abi_v2.h
@@ -0,0 +1,26 @@
+/* Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ 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,
+ 51 Franklin Street, Suite 500, Boston, MA 02110-1335 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..63f8c52c50a
--- /dev/null
+++ b/include/mysql/psi/psi_abi_v2.h.pp
@@ -0,0 +1,117 @@
+#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;
+};
+struct PSI_mutex_locker_state_v2
+{
+ int placeholder;
+};
+struct PSI_rwlock_locker_state_v2
+{
+ int placeholder;
+};
+struct PSI_cond_locker_state_v2
+{
+ int placeholder;
+};
+struct PSI_file_locker_state_v2
+{
+ int placeholder;
+};
+struct PSI_table_locker_state_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;
+typedef struct PSI_mutex_locker_state_v2 PSI_mutex_locker_state;
+typedef struct PSI_rwlock_locker_state_v2 PSI_rwlock_locker_state;
+typedef struct PSI_cond_locker_state_v2 PSI_cond_locker_state;
+typedef struct PSI_file_locker_state_v2 PSI_file_locker_state;
+typedef struct PSI_table_locker_state_v2 PSI_table_locker_state;
+extern MYSQL_PLUGIN_IMPORT PSI *PSI_server;
+C_MODE_END
diff --git a/include/mysql/service_my_snprintf.h b/include/mysql/service_my_snprintf.h
new file mode 100644
index 00000000000..f6b4aa39dc5
--- /dev/null
+++ b/include/mysql/service_my_snprintf.h
@@ -0,0 +1,101 @@
+#ifndef MYSQL_SERVICE_MY_SNPRINTF_INCLUDED
+/* Copyright (C) 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
+ my_snprintf service
+
+ Portable and limited vsnprintf() implementation.
+
+ This is a portable, limited vsnprintf() implementation, with some
+ extra features. "Portable" means that it'll produce identical result
+ on all platforms (for example, on Windows and Linux system printf %e
+ formats the exponent differently, on different systems %p either
+ prints leading 0x or not, %s may accept null pointer or crash on
+ it). "Limited" means that it does not support all the C89 features.
+ But it supports few extensions, not in any standard.
+
+ my_vsnprintf(to, n, fmt, ap)
+
+ @param[out] to A buffer to store the result in
+ @param[in] n Store up to n-1 characters, followed by an end 0
+ @param[in] fmt printf-like format string
+ @param[in] ap Arguments
+
+ @return a number of bytes written to a buffer *excluding* terminating '\0'
+
+ @post
+ The syntax of a format string is generally the same:
+ % <flag> <width> <precision> <length modifier> <format>
+ where everithing but the format is optional.
+
+ Three one-character flags are recognized:
+ '0' has the standard zero-padding semantics;
+ '-' is parsed, but silently ignored;
+ '`' (backtick) is only supported for strings (%s) and means that the
+ string will be quoted according to MySQL identifier quoting rules.
+
+ Both <width> and <precision> can be specified as numbers or '*'.
+
+ <length modifier> can be 'l', 'll', or 'z'.
+
+ Supported formats are 's' (null pointer is accepted, printed as
+ "(null)"), 'b' (extension, see below), 'c', 'd', 'i', 'u', 'x', 'o',
+ 'X', 'p' (works as 0x%x).
+
+ Standard syntax for positional arguments $n is supported.
+
+ Extensions:
+
+ Flag '`' (backtick): see above.
+
+ Format 'b': binary buffer, prints exactly <precision> bytes from the
+ argument, without stopping at '\0'.
+*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifndef MYSQL_ABI_CHECK
+#include <stdarg.h>
+#include <stdlib.h>
+#endif
+
+extern struct my_snprintf_service_st {
+ size_t (*my_snprintf_type)(char*, size_t, const char*, ...);
+ size_t (*my_vsnprintf_type)(char *, size_t, const char*, va_list);
+} *my_snprintf_service;
+
+#ifdef MYSQL_DYNAMIC_PLUGIN
+
+#define my_vsnprintf my_snprintf_service->my_vsnprintf_type
+#define my_snprintf my_snprintf_service->my_snprintf_type
+
+#else
+
+size_t my_snprintf(char* to, size_t n, const char* fmt, ...);
+size_t my_vsnprintf(char *to, size_t n, const char* fmt, va_list ap);
+
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#define MYSQL_SERVICE_MY_SNPRINTF_INCLUDED
+#endif
+
diff --git a/include/mysql/service_thd_alloc.h b/include/mysql/service_thd_alloc.h
new file mode 100644
index 00000000000..7061c2bd4d5
--- /dev/null
+++ b/include/mysql/service_thd_alloc.h
@@ -0,0 +1,130 @@
+#ifndef MYSQL_SERVICE_THD_ALLOC_INCLUDED
+/* Copyright (C) 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
+ This service provdes functions to allocate memory in a connection local
+ memory pool. The memory allocated there will be automatically freed at the
+ end of the statement, don't use it for allocations that should live longer
+ than that. For short living allocations this is more efficient than
+ using my_malloc and friends, and automatic "garbage collection" allows not
+ to think about memory leaks.
+
+ The pool is best for small to medium objects, don't use it for large
+ allocations - they are better served with my_malloc.
+*/
+
+#ifndef MYSQL_ABI_CHECK
+#include <stdlib.h>
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct st_mysql_lex_string
+{
+ char *str;
+ size_t length;
+};
+typedef struct st_mysql_lex_string MYSQL_LEX_STRING;
+
+extern struct thd_alloc_service_st {
+ void *(*thd_alloc_func)(MYSQL_THD, unsigned int);
+ void *(*thd_calloc_func)(MYSQL_THD, unsigned int);
+ char *(*thd_strdup_func)(MYSQL_THD, const char *);
+ char *(*thd_strmake_func)(MYSQL_THD, const char *, unsigned int);
+ void *(*thd_memdup_func)(MYSQL_THD, const void*, unsigned int);
+ MYSQL_LEX_STRING *(*thd_make_lex_string_func)(MYSQL_THD, MYSQL_LEX_STRING *,
+ const char *, unsigned int, int);
+} *thd_alloc_service;
+
+#ifdef MYSQL_DYNAMIC_PLUGIN
+
+#define thd_alloc(thd,size) (thd_alloc_service->thd_alloc_func((thd), (size)))
+
+#define thd_calloc(thd,size) (thd_alloc_service->thd_calloc_func((thd), (size)))
+
+#define thd_strdup(thd,str) (thd_alloc_service->thd_strdup_func((thd), (str)))
+
+#define thd_strmake(thd,str,size) \
+ (thd_alloc_service->thd_strmake_func((thd), (str), (size)))
+
+#define thd_memdup(thd,str,size) \
+ (thd_alloc_service->thd_memdup_func((thd), (str), (size)))
+
+#define thd_make_lex_string(thd, lex_str, str, size, allocate_lex_string) \
+ (thd_alloc_service->thd_make_lex_string_func((thd), (lex_str), (str), \
+ (size), (allocate_lex_string)))
+
+#else
+
+/**
+ Allocate memory in the connection's local memory pool
+
+ @details
+ When properly used in place of @c my_malloc(), this can significantly
+ improve concurrency. Don't use this or related functions to allocate
+ large chunks of memory. Use for temporary storage only. The memory
+ will be freed automatically at the end of the statement; no explicit
+ code is required to prevent memory leaks.
+
+ @see alloc_root()
+*/
+void *thd_alloc(MYSQL_THD thd, unsigned int size);
+/**
+ @see thd_alloc()
+*/
+void *thd_calloc(MYSQL_THD thd, unsigned int size);
+/**
+ @see thd_alloc()
+*/
+char *thd_strdup(MYSQL_THD thd, const char *str);
+/**
+ @see thd_alloc()
+*/
+char *thd_strmake(MYSQL_THD thd, const char *str, unsigned int size);
+/**
+ @see thd_alloc()
+*/
+void *thd_memdup(MYSQL_THD thd, const void* str, unsigned int size);
+
+/**
+ Create a LEX_STRING in this connection's local memory pool
+
+ @param thd user thread connection handle
+ @param lex_str pointer to LEX_STRING object to be initialized
+ @param str initializer to be copied into lex_str
+ @param size length of str, in bytes
+ @param allocate_lex_string flag: if TRUE, allocate new LEX_STRING object,
+ instead of using lex_str value
+ @return NULL on failure, or pointer to the LEX_STRING object
+
+ @see thd_alloc()
+*/
+MYSQL_LEX_STRING *thd_make_lex_string(MYSQL_THD thd, MYSQL_LEX_STRING *lex_str,
+ const char *str, unsigned int size,
+ int allocate_lex_string);
+
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#define MYSQL_SERVICE_THD_ALLOC_INCLUDED
+#endif
+
diff --git a/include/mysql/service_thd_wait.h b/include/mysql/service_thd_wait.h
new file mode 100644
index 00000000000..2a8f5e610a3
--- /dev/null
+++ b/include/mysql/service_thd_wait.h
@@ -0,0 +1,83 @@
+/* Copyright (C) 2010, Oracle and/or its affiliates. All rights reserved.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ 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_SERVICE_THD_WAIT_INCLUDED
+#define MYSQL_SERVICE_THD_WAIT_INCLUDED
+
+/**
+ @file include/mysql/service_thd_wait.h
+ This service provides functions for plugins and storage engines to report
+ when they are going to sleep/stall.
+
+ SYNOPSIS
+ thd_wait_begin() - call just before a wait begins
+ thd Thread object
+ Use NULL if the thd is NOT known.
+ wait_type Type of wait
+ 1 -- short wait (e.g. for mutex)
+ 2 -- medium wait (e.g. for disk io)
+ 3 -- large wait (e.g. for locked row/table)
+ NOTES
+ This is used by the threadpool to have better knowledge of which
+ threads that currently are actively running on CPUs. When a thread
+ reports that it's going to sleep/stall, the threadpool scheduler is
+ free to start another thread in the pool most likely. The expected wait
+ time is simply an indication of how long the wait is expected to
+ become, the real wait time could be very different.
+
+ thd_wait_end() called immediately after the wait is complete
+
+ thd_wait_end() MUST be called if thd_wait_begin() was called.
+
+ Using thd_wait_...() service is optional but recommended. Using it will
+ improve performance as the thread pool will be more active at managing the
+ thread workload.
+*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef enum _thd_wait_type_e {
+ THD_WAIT_MUTEX= 1,
+ THD_WAIT_DISKIO= 2,
+ THD_WAIT_ROW_TABLE_LOCK= 3,
+ THD_WAIT_GLOBAL_LOCK= 4
+} thd_wait_type;
+
+extern struct thd_wait_service_st {
+ void (*thd_wait_begin_func)(MYSQL_THD, thd_wait_type);
+ void (*thd_wait_end_func)(MYSQL_THD);
+} *thd_wait_service;
+
+#ifdef MYSQL_DYNAMIC_PLUGIN
+
+#define thd_wait_begin(_THD, _WAIT_TYPE) \
+ thd_wait_service->thd_wait_begin_func(_THD, _WAIT_TYPE)
+#define thd_wait_end(_THD) thd_wait_service->thd_wait_end_func(_THD)
+
+#else
+
+void thd_wait_begin(MYSQL_THD thd, thd_wait_type wait_type);
+void thd_wait_end(MYSQL_THD thd);
+
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
diff --git a/include/mysql/service_thread_scheduler.h b/include/mysql/service_thread_scheduler.h
new file mode 100644
index 00000000000..a4396b721bd
--- /dev/null
+++ b/include/mysql/service_thread_scheduler.h
@@ -0,0 +1,65 @@
+/*
+ Copyright (C) 2010, Oracle and/or its affiliates. All rights reserved.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ 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 SERVICE_THREAD_SCHEDULER_INCLUDED
+#define SERVICE_THREAD_SCHEDULER_INCLUDED
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct scheduler_functions;
+
+extern struct my_thread_scheduler_service {
+ int (*set)(struct scheduler_functions *scheduler);
+ int (*reset)();
+} *my_thread_scheduler_service;
+
+#ifdef MYSQL_DYNAMIC_PLUGIN
+
+#define my_thread_scheduler_set(F) my_thread_scheduler_service->set((F))
+#define my_thread_scheduler_reset() my_thread_scheduler_service->reset()
+
+#else
+
+/**
+ Set the thread scheduler to use for the server.
+
+ @param scheduler Pointer to scheduler callbacks to use.
+ @retval 0 Scheduler installed correctly.
+ @retval 1 Invalid value (NULL) used for scheduler.
+*/
+int my_thread_scheduler_set(struct scheduler_functions *scheduler);
+
+/**
+ Restore the previous thread scheduler.
+
+ @note If no thread scheduler was installed previously with
+ thd_set_thread_scheduler, this function will report an error.
+
+ @retval 0 Scheduler installed correctly.
+ @retval 1 No scheduler installed.
+*/
+int my_thread_scheduler_reset();
+
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* SERVICE_THREAD_SCHEDULER_INCLUDED */
diff --git a/include/help_end.h b/include/mysql/services.h
index 4426cb80bce..6c67a582fb8 100644
--- a/include/help_end.h
+++ b/include/mysql/services.h
@@ -1,4 +1,5 @@
-/* Copyright (C) 2004-2005 MySQL AB
+#ifndef MYSQL_SERVICES_INCLUDED
+/* Copyright (C) 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
@@ -11,12 +12,21 @@
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
-
-#ifdef __NETWARE__
-#undef printf
-#undef puts
-#undef fputs
-#undef fputc
-#undef putchar
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <mysql/service_my_snprintf.h>
+#include <mysql/service_thd_alloc.h>
+#include <mysql/service_thd_wait.h>
+#include <mysql/service_thread_scheduler.h>
+
+#ifdef __cplusplus
+}
#endif
+
+#define MYSQL_SERVICES_INCLUDED
+#endif
+
diff --git a/include/mysql_com.h b/include/mysql_com.h
index 7d3dd3d4f34..bc9296a6d02 100644
--- a/include/mysql_com.h
+++ b/include/mysql_com.h
@@ -27,10 +27,20 @@
#define NAME_LEN (NAME_CHAR_LEN*SYSTEM_CHARSET_MBMAXLEN)
#define USERNAME_LENGTH (USERNAME_CHAR_LENGTH*SYSTEM_CHARSET_MBMAXLEN)
+#define MYSQL_AUTODETECT_CHARSET_NAME "auto"
+
#define SERVER_VERSION_LENGTH 60
#define SQLSTATE_LENGTH 5
/*
+ Maximum length of comments
+*/
+#define TABLE_COMMENT_INLINE_MAXLEN 180 /* pre 6.0: 60 characters */
+#define TABLE_COMMENT_MAXLEN 2048
+#define COLUMN_COMMENT_MAXLEN 1024
+#define INDEX_COMMENT_MAXLEN 1024
+
+/*
USER_HOST_BUFF_SIZE -- length of string buffer, that is enough to contain
username and hostname parts of the user identifier with trailing zero in
MySQL standard format:
@@ -115,6 +125,12 @@ enum enum_server_command
thread */
#define REFRESH_MASTER 128 /* Remove all bin logs in the index
and truncate the index */
+#define REFRESH_ERROR_LOG 256 /* Rotate only the erorr log */
+#define REFRESH_ENGINE_LOG 512 /* Flush all storage engine logs */
+#define REFRESH_BINARY_LOG 1024 /* Flush the binary log */
+#define REFRESH_RELAY_LOG 2048 /* Flush the relay log */
+#define REFRESH_GENERAL_LOG 4096 /* Flush the general log */
+#define REFRESH_SLOW_LOG 8192 /* Flush the slow query log */
/* The following can't be set with mysql_refresh() */
#define REFRESH_READ_LOCK 16384 /* Lock tables for read */
@@ -144,10 +160,19 @@ enum enum_server_command
#define CLIENT_SECURE_CONNECTION 32768 /* New 4.1 authentication */
#define CLIENT_MULTI_STATEMENTS (1UL << 16) /* Enable/disable multi-stmt support */
#define CLIENT_MULTI_RESULTS (1UL << 17) /* Enable/disable multi-results */
+#define CLIENT_PS_MULTI_RESULTS (1UL << 18) /* Multi-results in PS-protocol */
+
+#define CLIENT_PLUGIN_AUTH (1UL << 19) /* Client supports plugin authentication */
#define CLIENT_SSL_VERIFY_SERVER_CERT (1UL << 30)
#define CLIENT_REMEMBER_OPTIONS (1UL << 31)
+#ifdef HAVE_COMPRESS
+#define CAN_CLIENT_COMPRESS CLIENT_COMPRESS
+#else
+#define CAN_CLIENT_COMPRESS 0
+#endif
+
/* Gather all possible capabilites (flags) supported by the server */
#define CLIENT_ALL_FLAGS (CLIENT_LONG_PASSWORD | \
CLIENT_FOUND_ROWS | \
@@ -167,8 +192,10 @@ enum enum_server_command
CLIENT_SECURE_CONNECTION | \
CLIENT_MULTI_STATEMENTS | \
CLIENT_MULTI_RESULTS | \
+ CLIENT_PS_MULTI_RESULTS | \
CLIENT_SSL_VERIFY_SERVER_CERT | \
- CLIENT_REMEMBER_OPTIONS)
+ CLIENT_REMEMBER_OPTIONS | \
+ CLIENT_PLUGIN_AUTH)
/*
Switch off the flags that are optional and depending on build flags
@@ -179,7 +206,14 @@ enum enum_server_command
& ~CLIENT_COMPRESS) \
& ~CLIENT_SSL_VERIFY_SERVER_CERT)
-#define SERVER_STATUS_IN_TRANS 1 /* Transaction has started */
+/**
+ Is raised when a multi-statement transaction
+ has been started, either explicitly, by means
+ of BEGIN or COMMIT AND CHAIN, or
+ implicitly, by the first transactional
+ statement, when autocommit=off.
+*/
+#define SERVER_STATUS_IN_TRANS 1
#define SERVER_STATUS_AUTOCOMMIT 2 /* Server in auto_commit mode */
#define SERVER_MORE_RESULTS_EXISTS 8 /* Multi query - next query exists */
#define SERVER_QUERY_NO_GOOD_INDEX_USED 16
@@ -203,6 +237,12 @@ enum enum_server_command
number of result set columns.
*/
#define SERVER_STATUS_METADATA_CHANGED 1024
+#define SERVER_QUERY_WAS_SLOW 2048
+
+/**
+ To mark ResultSet containing output parameter values.
+*/
+#define SERVER_PS_OUT_PARAMS 4096
/**
Server status flags that must be cleared when starting
@@ -215,7 +255,11 @@ enum enum_server_command
#define SERVER_STATUS_CLEAR_SET (SERVER_QUERY_NO_GOOD_INDEX_USED| \
SERVER_QUERY_NO_INDEX_USED|\
SERVER_MORE_RESULTS_EXISTS|\
- SERVER_STATUS_METADATA_CHANGED)
+ SERVER_STATUS_METADATA_CHANGED |\
+ SERVER_QUERY_WAS_SLOW |\
+ SERVER_STATUS_DB_DROPPED |\
+ SERVER_STATUS_CURSOR_EXISTS|\
+ SERVER_STATUS_LAST_ROW_SENT)
#define MYSQL_ERRMSG_SIZE 512
#define NET_READ_TIMEOUT 30 /* Timeout on read */
@@ -254,24 +298,23 @@ typedef struct st_net {
unsigned int *return_status;
unsigned char reading_or_writing;
char save_char;
- my_bool unused0; /* Please remove with the next incompatible ABI change. */
- my_bool unused; /* Please remove with the next incompatible ABI change */
- my_bool compress;
my_bool unused1; /* Please remove with the next incompatible ABI change. */
+ my_bool unused2; /* Please remove with the next incompatible ABI change */
+ my_bool compress;
+ my_bool unused3; /* Please remove with the next incompatible ABI change. */
/*
Pointer to query object in query cache, do not equal NULL (0) for
queries in cache that have not stored its results yet
*/
#endif
/*
- 'query_cache_query' should be accessed only via query cache
- functions and methods to maintain proper locking.
+ Unused, please remove with the next incompatible ABI change.
*/
- unsigned char *query_cache_query;
+ unsigned char *unused;
unsigned int last_errno;
unsigned char error;
- my_bool unused2; /* Please remove with the next incompatible ABI change. */
- my_bool return_errno;
+ my_bool unused4; /* Please remove with the next incompatible ABI change. */
+ my_bool unused5; /* Please remove with the next incompatible ABI change. */
/** Client library error message buffer. Actually belongs to struct MYSQL. */
char last_error[MYSQL_ERRMSG_SIZE];
/** Client library sqlstate buffer. Set along with the error message. */
@@ -419,10 +462,6 @@ void my_net_set_write_timeout(NET *net, uint timeout);
void my_net_set_read_timeout(NET *net, uint timeout);
#endif
-/*
- The following function is not meant for normal usage
- Currently it's used internally by manager.c
-*/
struct sockaddr;
int my_connect(my_socket s, const struct sockaddr *name, unsigned int namelen,
unsigned int timeout);
@@ -492,14 +531,14 @@ void create_random_string(char *to, unsigned int length, struct rand_struct *ran
void hash_password(unsigned long *to, const char *password, unsigned int password_len);
void make_scrambled_password_323(char *to, const char *password);
void scramble_323(char *to, const char *message, const char *password);
-my_bool check_scramble_323(const char *, const char *message,
+my_bool check_scramble_323(const unsigned char *reply, const char *message,
unsigned long *salt);
void get_salt_from_password_323(unsigned long *res, const char *password);
void make_password_from_salt_323(char *to, const unsigned long *salt);
void make_scrambled_password(char *to, const char *password);
void scramble(char *to, const char *message, const char *password);
-my_bool check_scramble(const char *reply, const char *message,
+my_bool check_scramble(const unsigned char *reply, const char *message,
const unsigned char *hash_stage2);
void get_salt_from_password(unsigned char *res, const char *password);
void make_password_from_salt(char *to, const unsigned char *hash_stage2);
@@ -529,4 +568,5 @@ uchar *net_store_length(uchar *pkg, ulonglong length);
#define MYSQL_STMT_HEADER 4
#define MYSQL_LONG_DATA_HEADER 6
+#define NOT_FIXED_DEC 31
#endif
diff --git a/include/mysql_embed.h b/include/mysql_embed.h
index a7d6e610918..e860a4486eb 100644
--- a/include/mysql_embed.h
+++ b/include/mysql_embed.h
@@ -1,3 +1,6 @@
+#ifndef MYSQL_EMBED_INCLUDED
+#define MYSQL_EMBED_INCLUDED
+
/* Copyright (C) 2000 MySQL AB
This program is free software; you can redistribute it and/or modify
@@ -20,10 +23,9 @@
/* Things we don't need in the embedded version of MySQL */
/* TODO HF add #undef HAVE_VIO if we don't want client in embedded library */
-#undef HAVE_OPENSSL
+#undef HAVE_DLOPEN /* No udf functions */
#undef HAVE_SMEM /* No shared memory */
#undef HAVE_NDBCLUSTER_DB /* No NDB cluster */
-#define DONT_USE_RAID
-
#endif /* EMBEDDED_LIBRARY */
+#endif /* MYSQL_EMBED_INCLUDED */
diff --git a/include/mysys_err.h b/include/mysys_err.h
index 6294b37f773..4067a3cfbd1 100644
--- a/include/mysys_err.h
+++ b/include/mysys_err.h
@@ -15,6 +15,7 @@
#ifndef _mysys_err_h
#define _mysys_err_h
+
#ifdef __cplusplus
extern "C" {
#endif
@@ -22,7 +23,7 @@ extern "C" {
#define GLOBERRS (EE_ERROR_LAST - EE_ERROR_FIRST + 1) /* Nr of global errors */
#define EE(X) (globerrs[(X) - EE_ERROR_FIRST])
-extern const char * NEAR globerrs[]; /* my_error_messages is here */
+extern const char *globerrs[]; /* my_error_messages is here */
/* Error message numbers in global map */
/*
diff --git a/include/password.h b/include/password.h
new file mode 100644
index 00000000000..e75b09297a3
--- /dev/null
+++ b/include/password.h
@@ -0,0 +1,32 @@
+/* Copyright 2006-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
+ 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
+
+#ifndef PASSWORD_INCLUDED
+#define PASSWORD_INCLUDED
+
+#include "my_global.h"
+
+C_MODE_START
+
+void my_make_scrambled_password_323(char *to, const char *password,
+ size_t pass_len);
+void my_make_scrambled_password(char *to, const char *password,
+ size_t pass_len);
+
+void hash_password(ulong *result, const char *password, uint password_len);
+
+C_MODE_END
+
+#endif /* PASSWORD_INCLUDED */
diff --git a/include/probes_mysql.d.base b/include/probes_mysql.d.base
new file mode 100644
index 00000000000..958e3042dde
--- /dev/null
+++ b/include/probes_mysql.d.base
@@ -0,0 +1,176 @@
+/* Copyright (C) 2008 MySQL AB
+
+ 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 */
+
+/*
+ The actual probe names in DTrace scripts will replace '__' by '-'. Thus
+ insert__row__start will be insert-row-start.
+
+ Recommendations for adding new probes:
+
+ - each probe should have the minimal set of arguments required to
+ unambiguously identify the context in which the probe fires. Redundant
+ arguments (i.e. the ones that can be obtained in user scripts from previous
+ probes' arguments or otherwise) may be added for convenience.
+
+ - try to avoid computationally expensive probe arguments. If impossible,
+ use *_ENABLED() macros to check if the probe is activated before
+ performing expensive calculations for a probe argument.
+
+ - all *-done probes should have a status argument wherever applicable to make
+ it possible for user scripts to figure out whether the completed operation
+ was successful or not.
+
+ - for all status arguments, a non-zero value should be returned on error or
+ failure, 0 should be returned on success.
+*/
+
+provider mysql {
+
+ /* The following ones fire when creating or closing a client connection */
+ probe connection__start(unsigned long conn_id, char *user, char *host);
+ probe connection__done(int status, unsigned long conn_id);
+
+ /*
+ Fire at the start/end of any client command processing (including SQL
+ queries).
+ */
+ probe command__start(unsigned long conn_id, int command,
+ char *user, char *host);
+ probe command__done(int status);
+
+ /*
+ The following probes fire at the start/end of any SQL query processing,
+ respectively.
+
+ query_start() has a lot of parameters that can be used to pick up
+ parameters for a lot of other probes here. For simplicity reasons we also
+ add the query string to most other DTrace probes as well. Hostname is
+ either the hostname or the IP address of the MySQL Client.
+ */
+ probe query__start(char *query,
+ unsigned long conn_id,
+ char *db_name,
+ char *user,
+ char *host);
+ probe query__done(int status);
+
+ /* Fire at the start/end of SQL query parsing */
+ probe query__parse__start(char *query);
+ probe query__parse__done(int status);
+
+ /* Track whether the query hits the query cache or not */
+ probe query__cache__hit(char *query, unsigned long rows);
+ probe query__cache__miss(char *query);
+
+ /*
+ This probe fires when the actual query execution starts, i.e. after
+ parsing and checking the query cache, but before privilege checks,
+ optimizing, etc.
+
+ Query means also all independent queries of a stored procedure and prepared
+ statements. Also the stored procedure itself is a query.
+
+ exec_type is:
+ 0: Executed query from sql_parse, top-level query (sql_parse.cc)
+ 1: Executed prepared statement (sql_prepare.cc)
+ 2: Executed cursor statement (sql_cursor.cc)
+ 3: Executed query in stored procedure (sp_head.cc)
+ */
+ probe query__exec__start(char *query,
+ unsigned long connid,
+ char *db_name,
+ char *user,
+ char *host,
+ int exec_type);
+ probe query__exec__done(int status);
+
+ /* These probes fire when performing row operations towards any handler */
+ probe insert__row__start(char *db, char *table);
+ probe insert__row__done(int status);
+ probe update__row__start(char *db, char *table);
+ probe update__row__done(int status);
+ probe delete__row__start(char *db, char *table);
+ probe delete__row__done(int status);
+ probe read__row__start(char *db, char *table, int scan_flag);
+ probe read__row__done(int status);
+ probe index__read__row__start(char *db, char *table);
+ probe index__read__row__done(int status);
+
+ /*
+ These probes fire when calling external_lock for any handler
+ depending on the lock type being acquired or released.
+ */
+ probe handler__rdlock__start(char *db, char *table);
+ probe handler__wrlock__start(char *db, char *table);
+ probe handler__unlock__start(char *db, char *table);
+ probe handler__rdlock__done(int status);
+ probe handler__wrlock__done(int status);
+ probe handler__unlock__done(int status);
+
+ /*
+ These probes fire when a filesort activity happens in a query.
+ */
+ probe filesort__start(char *db, char *table);
+ probe filesort__done(int status, unsigned long rows);
+ /*
+ The query types SELECT, INSERT, INSERT AS SELECT, UPDATE, UPDATE with
+ multiple tables, DELETE, DELETE with multiple tables are all probed.
+ The start probe always contains the query text.
+ */
+ probe select__start(char *query);
+ probe select__done(int status, unsigned long rows);
+ probe insert__start(char *query);
+ probe insert__done(int status, unsigned long rows);
+ probe insert__select__start(char *query);
+ probe insert__select__done(int status, unsigned long rows);
+ probe update__start(char *query);
+ probe update__done(int status,
+ unsigned long rowsmatches, unsigned long rowschanged);
+ probe multi__update__start(char *query);
+ probe multi__update__done(int status,
+ unsigned long rowsmatches,
+ unsigned long rowschanged);
+ probe delete__start(char *query);
+ probe delete__done(int status, unsigned long rows);
+ probe multi__delete__start(char *query);
+ probe multi__delete__done(int status, unsigned long rows);
+
+ /*
+ These probes can be used to measure the time waiting for network traffic
+ or identify network-related problems.
+ */
+ probe net__read__start();
+ probe net__read__done(int status, unsigned long bytes);
+ probe net__write__start(unsigned long bytes);
+ probe net__write__done(int status);
+
+ /* MyISAM Key cache probes */
+ probe keycache__read__start(char *filepath, unsigned long bytes,
+ unsigned long mem_used, unsigned long mem_free);
+ probe keycache__read__block(unsigned long bytes);
+ probe keycache__read__hit();
+ probe keycache__read__miss();
+ probe keycache__read__done(unsigned long mem_used, unsigned long mem_free);
+ probe keycache__write__start(char *filepath, unsigned long bytes,
+ unsigned long mem_used, unsigned long mem_free);
+ probe keycache__write__block(unsigned long bytes);
+ probe keycache__write__done(unsigned long mem_used, unsigned long mem_free);
+};
+
+#pragma D attributes Evolving/Evolving/Common provider mysql provider
+#pragma D attributes Evolving/Evolving/Common provider mysql module
+#pragma D attributes Evolving/Evolving/Common provider mysql function
+#pragma D attributes Evolving/Evolving/Common provider mysql name
+#pragma D attributes Evolving/Evolving/Common provider mysql args
diff --git a/include/probes_mysql.h b/include/probes_mysql.h
new file mode 100644
index 00000000000..13491c661fd
--- /dev/null
+++ b/include/probes_mysql.h
@@ -0,0 +1,13 @@
+#ifndef PROBES_MYSQL_H
+
+#define PROBES_MYSQL_H
+
+#include <my_global.h>
+
+#if defined(HAVE_DTRACE) && !defined(DISABLE_DTRACE)
+#include "probes_mysql_dtrace.h"
+#else
+#include "probes_mysql_nodtrace.h"
+#endif
+
+#endif /* PROBES_MYSQL_H */
diff --git a/include/probes_mysql_nodtrace.h b/include/probes_mysql_nodtrace.h
new file mode 100644
index 00000000000..bc3b65a00e5
--- /dev/null
+++ b/include/probes_mysql_nodtrace.h
@@ -0,0 +1,129 @@
+/*
+ * Generated by dheadgen(1).
+ */
+
+#ifndef _PROBES_MYSQL_D
+#define _PROBES_MYSQL_D
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define MYSQL_CONNECTION_START(arg0, arg1, arg2)
+#define MYSQL_CONNECTION_START_ENABLED() (0)
+#define MYSQL_CONNECTION_DONE(arg0, arg1)
+#define MYSQL_CONNECTION_DONE_ENABLED() (0)
+#define MYSQL_COMMAND_START(arg0, arg1, arg2, arg3)
+#define MYSQL_COMMAND_START_ENABLED() (0)
+#define MYSQL_COMMAND_DONE(arg0)
+#define MYSQL_COMMAND_DONE_ENABLED() (0)
+#define MYSQL_QUERY_START(arg0, arg1, arg2, arg3, arg4)
+#define MYSQL_QUERY_START_ENABLED() (0)
+#define MYSQL_QUERY_DONE(arg0)
+#define MYSQL_QUERY_DONE_ENABLED() (0)
+#define MYSQL_QUERY_PARSE_START(arg0)
+#define MYSQL_QUERY_PARSE_START_ENABLED() (0)
+#define MYSQL_QUERY_PARSE_DONE(arg0)
+#define MYSQL_QUERY_PARSE_DONE_ENABLED() (0)
+#define MYSQL_QUERY_CACHE_HIT(arg0, arg1)
+#define MYSQL_QUERY_CACHE_HIT_ENABLED() (0)
+#define MYSQL_QUERY_CACHE_MISS(arg0)
+#define MYSQL_QUERY_CACHE_MISS_ENABLED() (0)
+#define MYSQL_QUERY_EXEC_START(arg0, arg1, arg2, arg3, arg4, arg5)
+#define MYSQL_QUERY_EXEC_START_ENABLED() (0)
+#define MYSQL_QUERY_EXEC_DONE(arg0)
+#define MYSQL_QUERY_EXEC_DONE_ENABLED() (0)
+#define MYSQL_INSERT_ROW_START(arg0, arg1)
+#define MYSQL_INSERT_ROW_START_ENABLED() (0)
+#define MYSQL_INSERT_ROW_DONE(arg0)
+#define MYSQL_INSERT_ROW_DONE_ENABLED() (0)
+#define MYSQL_UPDATE_ROW_START(arg0, arg1)
+#define MYSQL_UPDATE_ROW_START_ENABLED() (0)
+#define MYSQL_UPDATE_ROW_DONE(arg0)
+#define MYSQL_UPDATE_ROW_DONE_ENABLED() (0)
+#define MYSQL_DELETE_ROW_START(arg0, arg1)
+#define MYSQL_DELETE_ROW_START_ENABLED() (0)
+#define MYSQL_DELETE_ROW_DONE(arg0)
+#define MYSQL_DELETE_ROW_DONE_ENABLED() (0)
+#define MYSQL_READ_ROW_START(arg0, arg1, arg2)
+#define MYSQL_READ_ROW_START_ENABLED() (0)
+#define MYSQL_READ_ROW_DONE(arg0)
+#define MYSQL_READ_ROW_DONE_ENABLED() (0)
+#define MYSQL_INDEX_READ_ROW_START(arg0, arg1)
+#define MYSQL_INDEX_READ_ROW_START_ENABLED() (0)
+#define MYSQL_INDEX_READ_ROW_DONE(arg0)
+#define MYSQL_INDEX_READ_ROW_DONE_ENABLED() (0)
+#define MYSQL_HANDLER_RDLOCK_START(arg0, arg1)
+#define MYSQL_HANDLER_RDLOCK_START_ENABLED() (0)
+#define MYSQL_HANDLER_WRLOCK_START(arg0, arg1)
+#define MYSQL_HANDLER_WRLOCK_START_ENABLED() (0)
+#define MYSQL_HANDLER_UNLOCK_START(arg0, arg1)
+#define MYSQL_HANDLER_UNLOCK_START_ENABLED() (0)
+#define MYSQL_HANDLER_RDLOCK_DONE(arg0)
+#define MYSQL_HANDLER_RDLOCK_DONE_ENABLED() (0)
+#define MYSQL_HANDLER_WRLOCK_DONE(arg0)
+#define MYSQL_HANDLER_WRLOCK_DONE_ENABLED() (0)
+#define MYSQL_HANDLER_UNLOCK_DONE(arg0)
+#define MYSQL_HANDLER_UNLOCK_DONE_ENABLED() (0)
+#define MYSQL_FILESORT_START(arg0, arg1)
+#define MYSQL_FILESORT_START_ENABLED() (0)
+#define MYSQL_FILESORT_DONE(arg0, arg1)
+#define MYSQL_FILESORT_DONE_ENABLED() (0)
+#define MYSQL_SELECT_START(arg0)
+#define MYSQL_SELECT_START_ENABLED() (0)
+#define MYSQL_SELECT_DONE(arg0, arg1)
+#define MYSQL_SELECT_DONE_ENABLED() (0)
+#define MYSQL_INSERT_START(arg0)
+#define MYSQL_INSERT_START_ENABLED() (0)
+#define MYSQL_INSERT_DONE(arg0, arg1)
+#define MYSQL_INSERT_DONE_ENABLED() (0)
+#define MYSQL_INSERT_SELECT_START(arg0)
+#define MYSQL_INSERT_SELECT_START_ENABLED() (0)
+#define MYSQL_INSERT_SELECT_DONE(arg0, arg1)
+#define MYSQL_INSERT_SELECT_DONE_ENABLED() (0)
+#define MYSQL_UPDATE_START(arg0)
+#define MYSQL_UPDATE_START_ENABLED() (0)
+#define MYSQL_UPDATE_DONE(arg0, arg1, arg2)
+#define MYSQL_UPDATE_DONE_ENABLED() (0)
+#define MYSQL_MULTI_UPDATE_START(arg0)
+#define MYSQL_MULTI_UPDATE_START_ENABLED() (0)
+#define MYSQL_MULTI_UPDATE_DONE(arg0, arg1, arg2)
+#define MYSQL_MULTI_UPDATE_DONE_ENABLED() (0)
+#define MYSQL_DELETE_START(arg0)
+#define MYSQL_DELETE_START_ENABLED() (0)
+#define MYSQL_DELETE_DONE(arg0, arg1)
+#define MYSQL_DELETE_DONE_ENABLED() (0)
+#define MYSQL_MULTI_DELETE_START(arg0)
+#define MYSQL_MULTI_DELETE_START_ENABLED() (0)
+#define MYSQL_MULTI_DELETE_DONE(arg0, arg1)
+#define MYSQL_MULTI_DELETE_DONE_ENABLED() (0)
+#define MYSQL_NET_READ_START()
+#define MYSQL_NET_READ_START_ENABLED() (0)
+#define MYSQL_NET_READ_DONE(arg0, arg1)
+#define MYSQL_NET_READ_DONE_ENABLED() (0)
+#define MYSQL_NET_WRITE_START(arg0)
+#define MYSQL_NET_WRITE_START_ENABLED() (0)
+#define MYSQL_NET_WRITE_DONE(arg0)
+#define MYSQL_NET_WRITE_DONE_ENABLED() (0)
+#define MYSQL_KEYCACHE_READ_START(arg0, arg1, arg2, arg3)
+#define MYSQL_KEYCACHE_READ_START_ENABLED() (0)
+#define MYSQL_KEYCACHE_READ_BLOCK(arg0)
+#define MYSQL_KEYCACHE_READ_BLOCK_ENABLED() (0)
+#define MYSQL_KEYCACHE_READ_HIT()
+#define MYSQL_KEYCACHE_READ_HIT_ENABLED() (0)
+#define MYSQL_KEYCACHE_READ_MISS()
+#define MYSQL_KEYCACHE_READ_MISS_ENABLED() (0)
+#define MYSQL_KEYCACHE_READ_DONE(arg0, arg1)
+#define MYSQL_KEYCACHE_READ_DONE_ENABLED() (0)
+#define MYSQL_KEYCACHE_WRITE_START(arg0, arg1, arg2, arg3)
+#define MYSQL_KEYCACHE_WRITE_START_ENABLED() (0)
+#define MYSQL_KEYCACHE_WRITE_BLOCK(arg0)
+#define MYSQL_KEYCACHE_WRITE_BLOCK_ENABLED() (0)
+#define MYSQL_KEYCACHE_WRITE_DONE(arg0, arg1)
+#define MYSQL_KEYCACHE_WRITE_DONE_ENABLED() (0)
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _PROBES_MYSQL_D */
diff --git a/include/queues.h b/include/queues.h
index d01b73ba999..07962f09201 100644
--- a/include/queues.h
+++ b/include/queues.h
@@ -22,6 +22,9 @@
#ifndef _queues_h
#define _queues_h
+
+#include "my_global.h" /* uchar */
+
#ifdef __cplusplus
extern "C" {
#endif
diff --git a/include/rijndael.h b/include/rijndael.h
index 89963a85c99..71df1c48dbf 100644
--- a/include/rijndael.h
+++ b/include/rijndael.h
@@ -1,3 +1,6 @@
+#ifndef RIJNDAEL_INCLUDED
+#define RIJNDAEL_INCLUDED
+
/* Copyright (C) 2002 MySQL AB
This program is free software; you can redistribute it and/or modify
@@ -39,3 +42,5 @@ void rijndaelEncrypt(const uint32 rk[/*4*(Nr + 1)*/], int Nr,
const uint8 pt[16], uint8 ct[16]);
void rijndaelDecrypt(const uint32 rk[/*4*(Nr + 1)*/], int Nr,
const uint8 ct[16], uint8 pt[16]);
+
+#endif /* RIJNDAEL_INCLUDED */
diff --git a/include/help_start.h b/include/service_versions.h
index 3ae20eea7d7..4fd886c8a83 100644
--- a/include/help_start.h
+++ b/include/service_versions.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 2004-2005 MySQL AB
+/* Copyright (C) 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
@@ -11,14 +11,15 @@
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
-/* Divert all help information on NetWare to logger screen. */
-
-#ifdef __NETWARE__
-#define printf consoleprintf
-#define puts(s) consoleprintf("%s\n",s)
-#define fputs(s,f) puts(s)
-#define fputc(s,f) consoleprintf("%c", s)
-#define putchar(s) consoleprintf("%c", s)
+#ifdef _WIN32
+#define SERVICE_VERSION __declspec(dllexport) void *
+#else
+#define SERVICE_VERSION void *
#endif
+
+#define VERSION_my_snprintf 0x0100
+#define VERSION_thd_alloc 0x0100
+#define VERSION_thd_wait 0x0100
+#define VERSION_my_thread_scheduler 0x0100
diff --git a/include/sha1.h b/include/sha1.h
index 787896e7476..d60d5e17c60 100644
--- a/include/sha1.h
+++ b/include/sha1.h
@@ -1,3 +1,6 @@
+#ifndef SHA1_INCLUDED
+#define SHA1_INCLUDED
+
/* Copyright (C) 2002, 2006 MySQL AB
This program is free software; you can redistribute it and/or modify
@@ -97,3 +100,5 @@ int mysql_sha1_input(SHA1_CONTEXT*, const uint8 *, unsigned int);
int mysql_sha1_result(SHA1_CONTEXT* , uint8 Message_Digest[SHA1_HASH_SIZE]);
C_MODE_END
+
+#endif /* SHA__INCLUDED */
diff --git a/include/sha2.h b/include/sha2.h
new file mode 100644
index 00000000000..e67a4100ff2
--- /dev/null
+++ b/include/sha2.h
@@ -0,0 +1,72 @@
+/* Copyright (C) 2007 MySQL AB
+
+ 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 included_sha2_h
+#define included_sha2_h
+
+#include <my_config.h>
+
+#if defined(HAVE_YASSL) || defined(HAVE_OPENSSL)
+
+# ifdef HAVE_STDDEF_H
+# include <stddef.h>
+# endif
+
+# ifndef HAVE_YASSL
+# include <openssl/sha.h>
+
+# else
+
+#include "../extra/yassl/taocrypt/include/sha.hpp"
+
+# ifdef __cplusplus
+extern "C" {
+# endif
+
+#ifndef SHA512_DIGEST_LENGTH
+#define SHA512_DIGEST_LENGTH TaoCrypt::SHA512::DIGEST_SIZE
+#endif
+
+#ifndef SHA384_DIGEST_LENGTH
+#define SHA384_DIGEST_LENGTH TaoCrypt::SHA384::DIGEST_SIZE
+#endif
+
+#ifndef SHA256_DIGEST_LENGTH
+#define SHA256_DIGEST_LENGTH TaoCrypt::SHA256::DIGEST_SIZE
+#endif
+
+#ifndef SHA224_DIGEST_LENGTH
+#define SHA224_DIGEST_LENGTH TaoCrypt::SHA224::DIGEST_SIZE
+#endif
+
+#define GEN_YASSL_SHA2_BRIDGE(size) \
+unsigned char* SHA##size(const unsigned char *input_ptr, size_t input_length, \
+ char unsigned *output_ptr);
+
+GEN_YASSL_SHA2_BRIDGE(512);
+GEN_YASSL_SHA2_BRIDGE(384);
+GEN_YASSL_SHA2_BRIDGE(256);
+GEN_YASSL_SHA2_BRIDGE(224);
+
+#undef GEN_YASSL_SHA2_BRIDGE
+
+# ifdef __cplusplus
+}
+# endif
+
+# endif /* HAVE_YASSL */
+
+#endif /* HAVE_OPENSSL || HAVE_YASSL */
+#endif /* included_sha2_h */
diff --git a/include/sql_common.h b/include/sql_common.h
index 9e43d076ba9..a9a3168b691 100644
--- a/include/sql_common.h
+++ b/include/sql_common.h
@@ -1,3 +1,6 @@
+#ifndef SQL_COMMON_INCLUDED
+#define SQL_COMMON_INCLUDED
+
/* Copyright (C) 2003-2004, 2006 MySQL AB
This program is free software; you can redistribute it and/or modify
@@ -13,14 +16,60 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+#define SQL_COMMON_INCLUDED
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <mysql.h>
extern const char *unknown_sqlstate;
extern const char *cant_connect_sqlstate;
extern const char *not_error_sqlstate;
-#ifdef __cplusplus
-extern "C" {
+struct st_mysql_options_extention {
+ char *plugin_dir;
+ char *default_auth;
+};
+
+typedef struct st_mysql_methods
+{
+ my_bool (*read_query_result)(MYSQL *mysql);
+ my_bool (*advanced_command)(MYSQL *mysql,
+ enum enum_server_command command,
+ const unsigned char *header,
+ unsigned long header_length,
+ const unsigned char *arg,
+ unsigned long arg_length,
+ my_bool skip_check,
+ MYSQL_STMT *stmt);
+ MYSQL_DATA *(*read_rows)(MYSQL *mysql,MYSQL_FIELD *mysql_fields,
+ unsigned int fields);
+ MYSQL_RES * (*use_result)(MYSQL *mysql);
+ void (*fetch_lengths)(unsigned long *to,
+ MYSQL_ROW column, unsigned int field_count);
+ void (*flush_use_result)(MYSQL *mysql, my_bool flush_all_results);
+ int (*read_change_user_result)(MYSQL *mysql);
+#if !defined(MYSQL_SERVER) || defined(EMBEDDED_LIBRARY)
+ MYSQL_FIELD * (*list_fields)(MYSQL *mysql);
+ my_bool (*read_prepare_result)(MYSQL *mysql, MYSQL_STMT *stmt);
+ int (*stmt_execute)(MYSQL_STMT *stmt);
+ int (*read_binary_rows)(MYSQL_STMT *stmt);
+ int (*unbuffered_fetch)(MYSQL *mysql, char **row);
+ void (*free_embedded_thd)(MYSQL *mysql);
+ const char *(*read_statistics)(MYSQL *mysql);
+ my_bool (*next_result)(MYSQL *mysql);
+ int (*read_rows_from_cursor)(MYSQL_STMT *stmt);
#endif
+} MYSQL_METHODS;
+
+#define simple_command(mysql, command, arg, length, skip_check) \
+ (*(mysql)->methods->advanced_command)(mysql, command, 0, \
+ 0, arg, length, skip_check, NULL)
+#define stmt_command(mysql, command, arg, length, stmt) \
+ (*(mysql)->methods->advanced_command)(mysql, command, 0, \
+ 0, arg, length, 1, stmt)
extern CHARSET_INFO *default_client_charset_info;
MYSQL_FIELD *unpack_fields(MYSQL_DATA *data,MEM_ROOT *alloc,uint fields,
@@ -42,9 +91,23 @@ void set_stmt_errmsg(MYSQL_STMT *stmt, NET *net);
void set_stmt_error(MYSQL_STMT *stmt, int errcode, const char *sqlstate,
const char *err);
void set_mysql_error(MYSQL *mysql, int errcode, const char *sqlstate);
+void set_mysql_extended_error(MYSQL *mysql, int errcode, const char *sqlstate,
+ const char *format, ...);
+
+/* client side of the pluggable authentication */
+struct st_plugin_vio_info;
+void mpvio_info(Vio *vio, struct st_plugin_vio_info *info);
+int run_plugin_auth(MYSQL *mysql, char *data, uint data_len,
+ const char *data_plugin, const char *db);
+int mysql_client_plugin_init();
+void mysql_client_plugin_deinit();
+struct st_mysql_client_plugin;
+extern struct st_mysql_client_plugin *mysql_client_builtins[];
+
#ifdef __cplusplus
}
#endif
#define protocol_41(A) ((A)->server_capabilities & CLIENT_PROTOCOL_41)
+#endif /* SQL_COMMON_INCLUDED */
diff --git a/include/sslopt-case.h b/include/sslopt-case.h
index adb9a28503b..3b64a225fe2 100644
--- a/include/sslopt-case.h
+++ b/include/sslopt-case.h
@@ -1,3 +1,6 @@
+#ifndef SSLOPT_CASE_INCLUDED
+#define SSLOPT_CASE_INCLUDED
+
/* Copyright (C) 2000 MySQL AB
This program is free software; you can redistribute it and/or modify
@@ -13,7 +16,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
-#ifdef HAVE_OPENSSL
+#if defined(HAVE_OPENSSL) && !defined(EMBEDDED_LIBRARY)
case OPT_SSL_KEY:
case OPT_SSL_CERT:
case OPT_SSL_CA:
@@ -26,3 +29,4 @@
opt_use_ssl= 1;
break;
#endif
+#endif /* SSLOPT_CASE_INCLUDED */
diff --git a/include/sslopt-longopts.h b/include/sslopt-longopts.h
index c038ece1644..5315b2e12b1 100644
--- a/include/sslopt-longopts.h
+++ b/include/sslopt-longopts.h
@@ -1,3 +1,6 @@
+#ifndef SSLOPT_LONGOPTS_INCLUDED
+#define SSLOPT_LONGOPTS_INCLUDED
+
/* Copyright (C) 2000 MySQL AB
This program is free software; you can redistribute it and/or modify
@@ -13,12 +16,11 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
-#ifdef HAVE_OPENSSL
+#if defined(HAVE_OPENSSL) && !defined(EMBEDDED_LIBRARY)
{"ssl", OPT_SSL_SSL,
- "Enable SSL for connection (automatically enabled with other flags)."
- "Disable with --skip-ssl.", &opt_use_ssl, &opt_use_ssl, 0, GET_BOOL,
- NO_ARG, 0, 0, 0, 0, 0, 0},
+ "Enable SSL for connection (automatically enabled with other flags).",
+ &opt_use_ssl, &opt_use_ssl, 0, GET_BOOL, OPT_ARG, 0, 0, 0, 0, 0, 0},
{"ssl-ca", OPT_SSL_CA,
"CA file in PEM format (check OpenSSL docs, implies --ssl).",
&opt_ssl_ca, &opt_ssl_ca, 0, GET_STR, REQUIRED_ARG,
@@ -41,6 +43,7 @@
"Verify server's \"Common Name\" in its cert against hostname used "
"when connecting. This option is disabled by default.",
&opt_ssl_verify_server_cert, &opt_ssl_verify_server_cert,
- 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
+ 0, GET_BOOL, OPT_ARG, 0, 0, 0, 0, 0, 0},
#endif
#endif /* HAVE_OPENSSL */
+#endif /* SSLOPT_LONGOPTS_INCLUDED */
diff --git a/include/sslopt-vars.h b/include/sslopt-vars.h
index 3369f870db2..d0eec3b6d74 100644
--- a/include/sslopt-vars.h
+++ b/include/sslopt-vars.h
@@ -1,3 +1,6 @@
+#ifndef SSLOPT_VARS_INCLUDED
+#define SSLOPT_VARS_INCLUDED
+
/* Copyright (C) 2000 MySQL AB
This program is free software; you can redistribute it and/or modify
@@ -13,7 +16,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
-#ifdef HAVE_OPENSSL
+#if defined(HAVE_OPENSSL) && !defined(EMBEDDED_LIBRARY)
#ifdef SSL_VARS_NOT_STATIC
#define SSL_STATIC
#else
@@ -29,3 +32,4 @@ SSL_STATIC char *opt_ssl_key = 0;
SSL_STATIC my_bool opt_ssl_verify_server_cert= 0;
#endif
#endif
+#endif /* SSLOPT_VARS_INCLUDED */
diff --git a/include/thr_alarm.h b/include/thr_alarm.h
index fb906039269..8d7f5bcdee0 100644
--- a/include/thr_alarm.h
+++ b/include/thr_alarm.h
@@ -64,7 +64,7 @@ typedef my_bool ALARM;
#if defined(__WIN__)
typedef struct st_thr_alarm_entry
{
- rf_SetTimer crono;
+ UINT_PTR crono;
} thr_alarm_entry;
#else /* System with posix threads */
diff --git a/include/thr_lock.h b/include/thr_lock.h
index fb70c57c0e7..91473737be3 100644
--- a/include/thr_lock.h
+++ b/include/thr_lock.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
@@ -54,12 +54,6 @@ enum thr_lock_type { TL_IGNORE=-1,
*/
TL_WRITE_ALLOW_WRITE,
/*
- Write lock, but allow other threads to read.
- Used by ALTER TABLE in MySQL to allow readers
- to use the table until ALTER TABLE is finished.
- */
- TL_WRITE_ALLOW_READ,
- /*
WRITE lock used by concurrent insert. Will allow
READ, if one could use concurrent insert on table.
*/
@@ -83,7 +77,6 @@ enum enum_thr_lock_result { THR_LOCK_SUCCESS= 0, THR_LOCK_ABORTED= 1,
extern ulong max_write_lock_count;
-extern ulong table_lock_wait_timeout;
extern my_bool thr_lock_inited;
extern enum thr_lock_type thr_upgraded_concurrent_insert_lock;
@@ -96,29 +89,18 @@ typedef struct st_thr_lock_info
{
pthread_t thread;
my_thread_id thread_id;
- ulong n_cursors;
} THR_LOCK_INFO;
-/*
- Lock owner identifier. Globally identifies the lock owner within the
- thread and among all the threads. The address of an instance of this
- structure is used as id.
-*/
-
-typedef struct st_thr_lock_owner
-{
- THR_LOCK_INFO *info;
-} THR_LOCK_OWNER;
-
typedef struct st_thr_lock_data {
- THR_LOCK_OWNER *owner;
+ THR_LOCK_INFO *owner;
struct st_thr_lock_data *next,**prev;
struct st_thr_lock *lock;
- pthread_cond_t *cond;
+ mysql_cond_t *cond;
enum thr_lock_type type;
void *status_param; /* Param to status functions */
void *debug_print_param;
+ struct PSI_table *m_psi;
} THR_LOCK_DATA;
struct st_lock_list {
@@ -127,7 +109,7 @@ struct st_lock_list {
typedef struct st_thr_lock {
LIST list;
- pthread_mutex_t mutex;
+ mysql_mutex_t mutex;
struct st_lock_list read_wait;
struct st_lock_list read;
struct st_lock_list write_wait;
@@ -144,30 +126,37 @@ typedef struct st_thr_lock {
extern LIST *thr_lock_thread_list;
-extern pthread_mutex_t THR_LOCK_lock;
+extern mysql_mutex_t THR_LOCK_lock;
my_bool init_thr_lock(void); /* Must be called once/thread */
-#define thr_lock_owner_init(owner, info_arg) (owner)->info= (info_arg)
void thr_lock_info_init(THR_LOCK_INFO *info);
void thr_lock_init(THR_LOCK *lock);
void thr_lock_delete(THR_LOCK *lock);
void thr_lock_data_init(THR_LOCK *lock,THR_LOCK_DATA *data,
void *status_param);
enum enum_thr_lock_result thr_lock(THR_LOCK_DATA *data,
- THR_LOCK_OWNER *owner,
- enum thr_lock_type lock_type);
+ THR_LOCK_INFO *owner,
+ enum thr_lock_type lock_type,
+ ulong lock_wait_timeout);
void thr_unlock(THR_LOCK_DATA *data);
enum enum_thr_lock_result thr_multi_lock(THR_LOCK_DATA **data,
- uint count, THR_LOCK_OWNER *owner);
+ uint count, THR_LOCK_INFO *owner,
+ ulong lock_wait_timeout);
void thr_multi_unlock(THR_LOCK_DATA **data,uint count);
+void
+thr_lock_merge_status(THR_LOCK_DATA **data, uint count);
void thr_abort_locks(THR_LOCK *lock, my_bool upgrade_lock);
my_bool thr_abort_locks_for_thread(THR_LOCK *lock, my_thread_id thread);
void thr_print_locks(void); /* For debugging */
my_bool thr_upgrade_write_delay_lock(THR_LOCK_DATA *data,
- enum thr_lock_type new_lock_type);
+ enum thr_lock_type new_lock_type,
+ ulong lock_wait_timeout);
void thr_downgrade_write_lock(THR_LOCK_DATA *data,
enum thr_lock_type new_lock_type);
-my_bool thr_reschedule_write_lock(THR_LOCK_DATA *data);
+my_bool thr_reschedule_write_lock(THR_LOCK_DATA *data,
+ ulong lock_wait_timeout);
+void thr_set_lock_wait_callback(void (*before_wait)(void),
+ void (*after_wait)(void));
#ifdef __cplusplus
}
#endif
diff --git a/include/typelib.h b/include/typelib.h
index 46106d1bdab..3badb14c96e 100644
--- a/include/typelib.h
+++ b/include/typelib.h
@@ -36,4 +36,9 @@ extern TYPELIB *copy_typelib(MEM_ROOT *root, TYPELIB *from);
extern TYPELIB sql_protocol_typelib;
+my_ulonglong find_set_from_flags(const TYPELIB *lib, unsigned int default_name,
+ my_ulonglong cur_set, my_ulonglong default_set,
+ const char *str, unsigned int length,
+ char **err_pos, unsigned int *err_len);
+
#endif /* _typelib_h */
diff --git a/include/violite.h b/include/violite.h
index 1eef3ef5730..f4083216894 100644
--- a/include/violite.h
+++ b/include/violite.h
@@ -30,6 +30,10 @@
extern "C" {
#endif /* __cplusplus */
+#ifdef __cplusplus
+typedef struct st_vio Vio;
+#endif /* __cplusplus */
+
enum enum_vio_type
{
VIO_CLOSED, VIO_TYPE_TCPIP, VIO_TYPE_SOCKET, VIO_TYPE_NAMEDPIPE,
@@ -51,9 +55,6 @@ Vio* vio_new_win32shared_memory(HANDLE handle_file_map,
HANDLE event_client_wrote,
HANDLE event_client_read,
HANDLE event_conn_closed);
-size_t vio_read_pipe(Vio *vio, uchar * buf, size_t size);
-size_t vio_write_pipe(Vio *vio, const uchar * buf, size_t size);
-int vio_close_pipe(Vio * vio);
#else
#define HANDLE void *
#endif /* __WIN__ */
@@ -84,10 +85,18 @@ int vio_errno(Vio*vio);
/* Get socket number */
my_socket vio_fd(Vio*vio);
/* Remote peer's address and name in text form */
-my_bool vio_peer_addr(Vio* vio, char *buf, uint16 *port);
-/* Remotes in_addr */
-void vio_in_addr(Vio *vio, struct in_addr *in);
-my_bool vio_poll_read(Vio *vio,uint timeout);
+my_bool vio_peer_addr(Vio *vio, char *buf, uint16 *port, size_t buflen);
+my_bool vio_poll_read(Vio *vio, uint timeout);
+my_bool vio_is_connected(Vio *vio);
+ssize_t vio_pending(Vio *vio);
+
+my_bool vio_get_normalized_ip_string(const struct sockaddr *addr, int addr_length,
+ char *ip_string, size_t ip_string_size);
+
+int vio_getnameinfo(const struct sockaddr *sa,
+ char *hostname, size_t hostname_size,
+ char *port, size_t port_size,
+ int flags);
#ifdef HAVE_OPENSSL
#include <openssl/opensslv.h>
@@ -109,6 +118,7 @@ typedef my_socket YASSL_SOCKET_T;
#include <openssl/ssl.h>
#include <openssl/err.h>
+#ifndef EMBEDDED_LIBRARY
enum enum_ssl_init_error
{
SSL_INITERR_NOERROR= 0, SSL_INITERR_CERT, SSL_INITERR_KEY,
@@ -134,14 +144,9 @@ struct st_VioSSLFd
const char *ca_file,const char *ca_path,
const char *cipher, enum enum_ssl_init_error* error);
void free_vio_ssl_acceptor_fd(struct st_VioSSLFd *fd);
+#endif /* ! EMBEDDED_LIBRARY */
#endif /* HAVE_OPENSSL */
-#ifdef HAVE_SMEM
-size_t vio_read_shared_memory(Vio *vio, uchar * buf, size_t size);
-size_t vio_write_shared_memory(Vio *vio, const uchar * buf, size_t size);
-int vio_close_shared_memory(Vio * vio);
-#endif
-
void vio_end(void);
#ifdef __cplusplus
@@ -161,9 +166,10 @@ void vio_end(void);
#define vio_should_retry(vio) (vio)->should_retry(vio)
#define vio_was_interrupted(vio) (vio)->was_interrupted(vio)
#define vio_close(vio) ((vio)->vioclose)(vio)
-#define vio_peer_addr(vio, buf, prt) (vio)->peer_addr(vio, buf, prt)
-#define vio_in_addr(vio, in) (vio)->in_addr(vio, in)
+#define vio_peer_addr(vio, buf, prt, buflen) (vio)->peer_addr(vio, buf, prt, buflen)
#define vio_timeout(vio, which, seconds) (vio)->timeout(vio, which, seconds)
+#define vio_poll_read(vio, timeout) (vio)->poll_read(vio, timeout)
+#define vio_is_connected(vio) (vio)->is_connected(vio)
#endif /* !defined(DONT_MAP_VIO) */
/* This enumerator is used in parser - should be always visible */
@@ -185,8 +191,9 @@ struct st_vio
HANDLE hPipe;
my_bool localhost; /* Are we from localhost? */
int fcntl_mode; /* Buffered fcntl(sd,F_GETFL) */
- struct sockaddr_in local; /* Local internet address */
- struct sockaddr_in remote; /* Remote internet address */
+ struct sockaddr_storage local; /* Local internet address */
+ struct sockaddr_storage remote; /* Remote internet address */
+ int addrLen; /* Length of remote address */
enum enum_vio_type type; /* Type of connection */
char desc[30]; /* String description */
char *read_buffer; /* buffer for vio_read_buff */
@@ -202,12 +209,15 @@ struct st_vio
my_bool (*is_blocking)(Vio*);
int (*viokeepalive)(Vio*, my_bool);
int (*fastsend)(Vio*);
- my_bool (*peer_addr)(Vio*, char *, uint16*);
- void (*in_addr)(Vio*, struct in_addr*);
+ my_bool (*peer_addr)(Vio*, char *, uint16*, size_t);
+ void (*in_addr)(Vio*, struct sockaddr_storage*);
my_bool (*should_retry)(Vio*);
my_bool (*was_interrupted)(Vio*);
int (*vioclose)(Vio*);
void (*timeout)(Vio*, unsigned int which, unsigned int timeout);
+ my_bool (*poll_read)(Vio *vio, uint timeout);
+ my_bool (*is_connected)(Vio*);
+ my_bool (*has_data) (Vio*);
#ifdef HAVE_OPENSSL
void *ssl_arg;
#endif
diff --git a/include/welcome_copyright_notice.h b/include/welcome_copyright_notice.h
new file mode 100644
index 00000000000..c3ffad1527d
--- /dev/null
+++ b/include/welcome_copyright_notice.h
@@ -0,0 +1,31 @@
+/* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ 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 _welcome_copyright_notice_h_
+#define _welcome_copyright_notice_h_
+
+/*
+ This define specifies copyright notice which is displayed by every MySQL
+ program on start, or on help screen.
+*/
+
+#define ORACLE_WELCOME_COPYRIGHT_NOTICE(years) \
+ "Copyright (c) " years ", Oracle and/or its affiliates. All rights reserved.\n" \
+ "\n" \
+ "Oracle is a registered trademark of Oracle Corporation and/or its\n" \
+ "affiliates. Other names may be trademarks of their respective\n" \
+ "owners.\n"
+
+#endif /* _welcome_copyright_notice_h_ */