From dced2bce9932d4b850db7c9598eb9a4404c14bac Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Mon, 16 Nov 2009 14:14:54 -0700 Subject: [PATCH 01/23] New tree for merges --- .bzr-mysql/default.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.bzr-mysql/default.conf b/.bzr-mysql/default.conf index e9ae26ca793..1dcfe53534b 100644 --- a/.bzr-mysql/default.conf +++ b/.bzr-mysql/default.conf @@ -1,4 +1,4 @@ [MYSQL] post_commit_to = "commits@lists.mysql.com" post_push_to = "commits@lists.mysql.com" -tree_name = "mysql-5.5-next-mr" +tree_name = "mysql-5.6-mext-mr-marc" From 1e46d6a032d238bf3ca749289ca8abc8432c4e23 Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Tue, 17 Nov 2009 17:11:32 -0700 Subject: [PATCH 02/23] WL#2595 kernel-independent atomic operations Backport from 6.0.14 to 5.6.0 Original code from Sergei Golubchik --- configure.in | 90 ++++++----- include/Makefile.am | 6 +- include/atomic/gcc_builtins.h | 5 +- include/atomic/generic-msvc.h | 116 ++++++++++++++ include/atomic/nolock.h | 45 +++--- include/atomic/rwlock.h | 70 +++++++-- include/atomic/solaris.h | 8 +- include/atomic/x86-gcc.h | 28 ++-- include/my_atomic.h | 285 +++++++++++++++++++++++++--------- mysys/my_atomic.c | 33 +++- mysys/my_getncpus.c | 34 ++-- unittest/mysys/Makefile.am | 2 + unittest/mysys/my_atomic-t.c | 155 ++++++------------ unittest/mysys/thr_template.c | 92 +++++++++++ 14 files changed, 681 insertions(+), 288 deletions(-) create mode 100644 include/atomic/generic-msvc.h create mode 100644 unittest/mysys/thr_template.c diff --git a/configure.in b/configure.in index 3910422a0f7..dd2c53a2b52 100644 --- a/configure.in +++ b/configure.in @@ -1750,64 +1750,74 @@ then fi AC_ARG_WITH([atomic-ops], - AC_HELP_STRING([--with-atomic-ops=rwlocks|smp|up], - [Implement atomic operations using pthread rwlocks or atomic CPU - instructions for multi-processor (default) or uniprocessor - configuration]), , [with_atomic_ops=smp]) + AS_HELP_STRING([--with-atomic-ops=rwlocks|smp|up], + [Implement atomic operations using pthread rwlocks or atomic CPU + instructions for multi-processor or uniprocessor + configuration. By default gcc built-in sync functions are used, + if available and 'smp' configuration otherwise.])) case "$with_atomic_ops" in "up") AC_DEFINE([MY_ATOMIC_MODE_DUMMY], [1], [Assume single-CPU mode, no concurrency]) ;; "rwlocks") AC_DEFINE([MY_ATOMIC_MODE_RWLOCKS], [1], [Use pthread rwlocks for atomic ops]) ;; "smp") ;; + "") + ;; *) AC_MSG_ERROR(["$with_atomic_ops" is not a valid value for --with-atomic-ops]) ;; esac AC_CACHE_CHECK([whether the compiler provides atomic builtins], - [mysql_cv_gcc_atomic_builtins], [AC_TRY_RUN([ - int main() - { - int foo= -10; int bar= 10; - if (!__sync_fetch_and_add(&foo, bar) || foo) - return -1; - bar= __sync_lock_test_and_set(&foo, bar); - if (bar || foo != 10) - return -1; - bar= __sync_val_compare_and_swap(&bar, foo, 15); - if (bar) - return -1; - return 0; - } -], [mysql_cv_gcc_atomic_builtins=yes], + [mysql_cv_gcc_atomic_builtins], + [AC_RUN_IFELSE( + [AC_LANG_PROGRAM( + [ + ], + [[ + int foo= -10; int bar= 10; + if (!__sync_fetch_and_add(&foo, bar) || foo) + return -1; + bar= __sync_lock_test_and_set(&foo, bar); + if (bar || foo != 10) + return -1; + bar= __sync_val_compare_and_swap(&bar, foo, 15); + if (bar) + return -1; + return 0; + ]] + )], + [mysql_cv_gcc_atomic_builtins=yes], [mysql_cv_gcc_atomic_builtins=no], - [mysql_cv_gcc_atomic_builtins=no])]) - + [mysql_cv_gcc_atomic_builtins=no] +)]) if test "x$mysql_cv_gcc_atomic_builtins" = xyes; then AC_DEFINE(HAVE_GCC_ATOMIC_BUILTINS, 1, [Define to 1 if compiler provides atomic builtins.]) fi AC_CACHE_CHECK([whether the OS provides atomic_* functions like Solaris], - [mysql_cv_solaris_atomic], [AC_TRY_RUN([ -#include -int -main() -{ - int foo = -10; int bar = 10; - if (atomic_add_int_nv((uint_t *)&foo, bar) || foo) - return -1; - bar = atomic_swap_uint((uint_t *)&foo, (uint_t)bar); - if (bar || foo != 10) - return -1; - bar = atomic_cas_uint((uint_t *)&bar, (uint_t)foo, 15); - if (bar) - return -1; - return 0; -} -], [mysql_cv_solaris_atomic=yes], + [mysql_cv_solaris_atomic], + [AC_RUN_IFELSE( + [AC_LANG_PROGRAM( + [ + #include + ] + [[ + int foo = -10; int bar = 10; + if (atomic_add_int_nv((uint_t *)&foo, bar) || foo) + return -1; + bar = atomic_swap_uint((uint_t *)&foo, (uint_t)bar); + if (bar || foo != 10) + return -1; + bar = atomic_cas_uint((uint_t *)&bar, (uint_t)foo, 15); + if (bar) + return -1; + return 0; + ]] + )], + [mysql_cv_solaris_atomic=yes], [mysql_cv_solaris_atomic=no], - [mysql_cv_solaris_atomic=no])]) - + [mysql_cv_solaris_atomic=no] +)]) if test "x$mysql_cv_solaris_atomic" = xyes; then AC_DEFINE(HAVE_SOLARIS_ATOMIC, 1, [Define to 1 if OS provides atomic_* functions like Solaris.]) diff --git a/include/Makefile.am b/include/Makefile.am index 0a7a35bd6fa..e20b08afe35 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -39,9 +39,9 @@ noinst_HEADERS = config-win.h config-netware.h my_bit.h \ thr_lock.h t_ctype.h violite.h my_md5.h base64.h \ my_handler.h my_time.h service_versions.h \ my_vle.h my_user.h my_atomic.h atomic/nolock.h \ - atomic/rwlock.h atomic/x86-gcc.h atomic/x86-msvc.h \ - atomic/solaris.h \ - atomic/gcc_builtins.h my_libwrap.h my_stacktrace.h + atomic/rwlock.h atomic/x86-gcc.h atomic/generic-msvc.h \ + atomic/gcc_builtins.h my_libwrap.h my_stacktrace.h \ + atomic/solaris.h EXTRA_DIST = mysql.h.pp mysql/plugin.h.pp probes_mysql.d.base diff --git a/include/atomic/gcc_builtins.h b/include/atomic/gcc_builtins.h index 01ebc38707e..100ff80cacd 100644 --- a/include/atomic/gcc_builtins.h +++ b/include/atomic/gcc_builtins.h @@ -18,7 +18,7 @@ #define make_atomic_add_body(S) \ v= __sync_fetch_and_add(a, v); -#define make_atomic_swap_body(S) \ +#define make_atomic_fas_body(S) \ v= __sync_lock_test_and_set(a, v); #define make_atomic_cas_body(S) \ int ## S sav; \ @@ -28,7 +28,10 @@ #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) \ diff --git a/include/atomic/generic-msvc.h b/include/atomic/generic-msvc.h new file mode 100644 index 00000000000..f1e1b0e88c9 --- /dev/null +++ b/include/atomic/generic-msvc.h @@ -0,0 +1,116 @@ +/* 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 + +/* + 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 +#else +C_MODE_START +/*Visual Studio 2003 and earlier do not have prototypes for atomic intrinsics*/ +LONG _InterlockedExchange (LONG volatile *Target,LONG Value); +LONG _InterlockedCompareExchange (LONG volatile *Target, LONG Value, LONG Comp); +LONG _InterlockedExchangeAdd (LONG volatile *Addend, LONG Value); +C_MODE_END + +#pragma intrinsic(_InterlockedExchangeAdd) +#pragma intrinsic(_InterlockedCompareExchange) +#pragma intrinsic(_InterlockedExchange) +#endif + +#define InterlockedExchange _InterlockedExchange +#define InterlockedExchangeAdd _InterlockedExchangeAdd +#define InterlockedCompareExchange _InterlockedCompareExchange +/* + 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" +#define IL_EXCHG_ADD32(X,Y) InterlockedExchangeAdd((volatile LONG *)(X),(Y)) +#define IL_COMP_EXCHG32(X,Y,Z) InterlockedCompareExchange((volatile LONG *)(X),(Y),(Z)) +#define IL_COMP_EXCHGptr InterlockedCompareExchangePointer +#define IL_EXCHG32(X,Y) InterlockedExchange((volatile LONG *)(X),(Y)) +#define IL_EXCHGptr InterlockedExchangePointer +#define make_atomic_add_body(S) \ + v= IL_EXCHG_ADD ## S (a, v) +#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; +#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); + +/* + 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; irw) -#define my_atomic_rwlock_init(name) pthread_rwlock_init(& (name)->rw, 0) -#define my_atomic_rwlock_rdlock(name) pthread_rwlock_rdlock(& (name)->rw) -#define my_atomic_rwlock_wrlock(name) pthread_rwlock_wrlock(& (name)->rw) -#define my_atomic_rwlock_rdunlock(name) pthread_rwlock_unlock(& (name)->rw) -#define my_atomic_rwlock_wrunlock(name) pthread_rwlock_unlock(& (name)->rw) -#define MY_ATOMIC_MODE "rwlocks" +#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_swap_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; diff --git a/include/atomic/solaris.h b/include/atomic/solaris.h index 4c51253d2d5..45efd9faaba 100644 --- a/include/atomic/solaris.h +++ b/include/atomic/solaris.h @@ -186,25 +186,25 @@ my_atomic_storeptr(void * volatile *a, void *v) /* ------------------------------------------------------------------------ */ STATIC_INLINE int8 -my_atomic_swap8(int8 volatile *a, int8 v) +my_atomic_fas8(int8 volatile *a, int8 v) { return ((int8) atomic_swap_8((volatile uint8_t *)a, (uint8_t)v)); } STATIC_INLINE int16 -my_atomic_swap16(int16 volatile *a, int16 v) +my_atomic_fas16(int16 volatile *a, int16 v) { return ((int16) atomic_swap_16((volatile uint16_t *)a, (uint16_t)v)); } STATIC_INLINE int32 -my_atomic_swap32(int32 volatile *a, int32 v) +my_atomic_fas32(int32 volatile *a, int32 v) { return ((int32) atomic_swap_32((volatile uint32_t *)a, (uint32_t)v)); } STATIC_INLINE void * -my_atomic_swapptr(void * volatile *a, void *v) +my_atomic_fasptr(void * volatile *a, void *v) { return (atomic_swap_ptr(a, v)); } diff --git a/include/atomic/x86-gcc.h b/include/atomic/x86-gcc.h index c3029f9c1b4..59090bc26b7 100644 --- a/include/atomic/x86-gcc.h +++ b/include/atomic/x86-gcc.h @@ -22,10 +22,18 @@ architectures support double-word (128-bit) cas. */ -#ifdef MY_ATOMIC_NO_XADD -#define MY_ATOMIC_MODE "gcc-x86" LOCK "-no-xadd" +#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 -#define MY_ATOMIC_MODE "gcc-x86" LOCK +# 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 */ @@ -35,12 +43,12 @@ #ifndef MY_ATOMIC_NO_XADD #define make_atomic_add_body(S) \ - asm volatile (LOCK "; xadd %0, %1;" : "+r" (v) , "+m" (*a)) + asm volatile (LOCK_prefix "; xadd %0, %1;" : "+r" (v) , "+m" (*a)) #endif -#define make_atomic_swap_body(S) \ - asm volatile ("; xchg %0, %1;" : "+q" (v) , "+m" (*a)) +#define make_atomic_fas_body(S) \ + asm volatile ("xchg %0, %1;" : "+q" (v) , "+m" (*a)) #define make_atomic_cas_body(S) \ - asm volatile (LOCK "; cmpxchg %3, %0; setz %2;" \ + asm volatile (LOCK_prefix "; cmpxchg %3, %0; setz %2;" \ : "+m" (*a), "+a" (*cmp), "=q" (ret): "r" (set)) #ifdef MY_ATOMIC_MODE_DUMMY @@ -49,14 +57,14 @@ #else /* Actually 32-bit reads/writes are always atomic on x86 - But we add LOCK here anyway to force memory barriers + But we add LOCK_prefix here anyway to force memory barriers */ #define make_atomic_load_body(S) \ ret=0; \ - asm volatile (LOCK "; cmpxchg %2, %0" \ + asm volatile (LOCK_prefix "; cmpxchg %2, %0" \ : "+m" (*a), "+a" (ret): "r" (ret)) #define make_atomic_store_body(S) \ - asm volatile ("; xchg %0, %1;" : "+m" (*a) : "r" (v)) + asm volatile ("; xchg %0, %1;" : "+m" (*a), "+r" (v)) #endif #endif /* ATOMIC_X86_GCC_INCLUDED */ diff --git a/include/my_atomic.h b/include/my_atomic.h index f5da6e6a0d9..85cf87165fb 100644 --- a/include/my_atomic.h +++ b/include/my_atomic.h @@ -16,9 +16,51 @@ 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) + 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) + 'Compare And Swap' + if *var is equal to *old, then store 'new' in *var, and return TRUE + otherwise store *var in *old, and return FALSE + + my_atomic_load#(&var) + return *var + + my_atomic_store#(&var, what) + store 'what' in *var + + '#' is substituted by a size suffix - 8, 16, 32, 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 * +/** + On most platforms we implement 8-bit, 16-bit, 32-bit and "pointer" + operations. Thus the symbol below is defined by default; platforms + where we leave out 8-bit or 16-bit operations should undefine it. +*/ +#define MY_ATOMIC_HAS_8_16 1 #ifndef MY_ATOMIC_MODE_RWLOCKS /* @@ -27,126 +69,225 @@ #include "atomic/nolock.h" #endif -#ifndef MY_ATOMIC_NOLOCK -/* - * Have to use rw-locks for atomic ops - */ +#ifndef make_atomic_cas_body +/* nolock.h was not able to generate even a CAS function, fall back */ #include "atomic/rwlock.h" -#endif - -#ifndef MY_ATOMICS_MADE - +#else +/* define missing functions by using the already generated ones */ #ifndef make_atomic_add_body -#define make_atomic_add_body(S) \ +#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 +#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)) +/* + 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(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_ptr intptr +#define Uv_8 int8 +#define Uv_16 int16 +#define Uv_32 int32 +#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 */ #ifdef HAVE_INLINE -#define make_atomic_add(S) \ -STATIC_INLINE int ## S my_atomic_add ## S( \ - int ## S volatile *a, int ## S v) \ -{ \ - make_atomic_add_body(S); \ - return v; \ +#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_swap(S) \ -STATIC_INLINE int ## S my_atomic_swap ## S( \ - int ## S volatile *a, int ## S v) \ -{ \ - make_atomic_swap_body(S); \ - return v; \ +#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_cas(S) \ -STATIC_INLINE int my_atomic_cas ## S(int ## S volatile *a, \ - int ## S *cmp, int ## S set) \ -{ \ - int8 ret; \ - make_atomic_cas_body(S); \ - return ret; \ +#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(int ## S volatile *a) \ -{ \ - int ## S ret; \ - make_atomic_load_body(S); \ - return ret; \ +#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( \ - int ## S volatile *a, int ## S v) \ -{ \ - make_atomic_store_body(S); \ +#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); \ } #else /* no inline functions */ -#define make_atomic_add(S) \ -extern int ## S my_atomic_add ## S(int ## S volatile *a, int ## S v); +#define make_atomic_add(S) \ +extern int ## S my_atomic_add ## S(Uv_ ## S U_a, U_ ## S U_v); -#define make_atomic_swap(S) \ -extern int ## S my_atomic_swap ## S(int ## S volatile *a, int ## S v); +#define make_atomic_fas(S) \ +extern int ## S my_atomic_fas ## S(Uv_ ## S U_a, U_ ## S U_v); -#define make_atomic_cas(S) \ -extern int my_atomic_cas ## S(int ## S volatile *a, int ## S *cmp, int ## S set); +#define make_atomic_cas(S) \ +extern int my_atomic_cas ## S(Uv_ ## S U_a, Uv_ ## S U_cmp, U_ ## S U_set); -#define make_atomic_load(S) \ -extern int ## S my_atomic_load ## S(int ## S volatile *a); +#define make_atomic_load(S) \ +extern int ## S my_atomic_load ## S(Uv_ ## S U_a); -#define make_atomic_store(S) \ -extern void my_atomic_store ## S(int ## S volatile *a, int ## S v); +#define make_atomic_store(S) \ +extern void my_atomic_store ## S(Uv_ ## S U_a, U_ ## S U_v); #endif /* HAVE_INLINE */ -make_atomic_cas( 8) +#ifdef MY_ATOMIC_HAS_8_16 +make_atomic_cas(8) make_atomic_cas(16) +#endif make_atomic_cas(32) make_atomic_cas(ptr) -make_atomic_add( 8) +#ifdef MY_ATOMIC_HAS_8_16 +make_atomic_add(8) make_atomic_add(16) +#endif make_atomic_add(32) -make_atomic_load( 8) +#ifdef MY_ATOMIC_HAS_8_16 +make_atomic_load(8) make_atomic_load(16) +#endif make_atomic_load(32) make_atomic_load(ptr) -make_atomic_store( 8) +#ifdef MY_ATOMIC_HAS_8_16 +make_atomic_fas(8) +make_atomic_fas(16) +#endif +make_atomic_fas(32) +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(ptr) -make_atomic_swap( 8) -make_atomic_swap(16) -make_atomic_swap(32) -make_atomic_swap(ptr) - -#undef make_atomic_add -#undef make_atomic_cas -#undef make_atomic_load -#undef make_atomic_store -#undef make_atomic_swap -#undef make_atomic_add_body -#undef make_atomic_cas_body -#undef make_atomic_load_body -#undef make_atomic_store_body -#undef make_atomic_swap_body -#undef intptr - -#endif /* MY_ATOMICS_MADE */ - #ifdef _atomic_h_cleanup_ #include _atomic_h_cleanup_ #undef _atomic_h_cleanup_ #endif +#undef U_8 +#undef U_16 +#undef U_32 +#undef U_ptr +#undef Uv_8 +#undef Uv_16 +#undef Uv_32 +#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(); diff --git a/mysys/my_atomic.c b/mysys/my_atomic.c index aa04d55f624..6bc76f0de3c 100644 --- a/mysys/my_atomic.c +++ b/mysys/my_atomic.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2006 MySQL AB +/* Copyright (C) 2006 MySQL AB, 2008-2009 Sun Microsystems, Inc This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -14,7 +14,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include -#include +#include #ifndef HAVE_INLINE /* the following will cause all inline functions to be instantiated */ @@ -43,3 +43,32 @@ int my_atomic_initialize() #endif } +#ifdef SAFE_MUTEX +#undef pthread_mutex_init +#undef pthread_mutex_destroy +#undef pthread_mutex_lock +#undef pthread_mutex_unlock + +void plain_pthread_mutex_init(safe_mutex_t *m) +{ + pthread_mutex_init(& m->mutex, NULL); +} + +void plain_pthread_mutex_destroy(safe_mutex_t *m) +{ + pthread_mutex_destroy(& m->mutex); +} + +void plain_pthread_mutex_lock(safe_mutex_t *m) +{ + pthread_mutex_lock(& m->mutex); +} + +void plain_pthread_mutex_unlock(safe_mutex_t *m) +{ + pthread_mutex_unlock(& m->mutex); +} + +#endif + + diff --git a/mysys/my_getncpus.c b/mysys/my_getncpus.c index 82e87dee2e4..5be961e3bc9 100644 --- a/mysys/my_getncpus.c +++ b/mysys/my_getncpus.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2006 MySQL AB +/* Copyright (C) 2006 MySQL AB, 2008-2009 Sun Microsystems, Inc This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -16,24 +16,34 @@ /* get the number of (online) CPUs */ #include "mysys_priv.h" +#ifdef HAVE_UNISTD_H #include +#endif static int ncpus=0; -#ifdef _SC_NPROCESSORS_ONLN int my_getncpus() { if (!ncpus) + { +#ifdef _SC_NPROCESSORS_ONLN ncpus= sysconf(_SC_NPROCESSORS_ONLN); +#elif defined(__WIN__) + SYSTEM_INFO sysinfo; + + /* + * We are not calling GetNativeSystemInfo here because (1) we + * don't believe that they return different values for number + * of processors and (2) if WOW64 limits processors for Win32 + * then we don't want to try to override that. + */ + GetSystemInfo(&sysinfo); + + ncpus= sysinfo.dwNumberOfProcessors; +#else +/* unknown so play safe: assume SMP and forbid uniprocessor build */ + ncpus= 2; +#endif + } return ncpus; } - -#else -/* unknown */ -int my_getncpus() -{ - return 2; -} - -#endif - diff --git a/unittest/mysys/Makefile.am b/unittest/mysys/Makefile.am index 56c65d71396..6e8058c4d9b 100644 --- a/unittest/mysys/Makefile.am +++ b/unittest/mysys/Makefile.am @@ -16,6 +16,8 @@ AM_CPPFLAGS = @ZLIB_INCLUDES@ -I$(top_builddir)/include AM_CPPFLAGS += -I$(top_srcdir)/include -I$(top_srcdir)/unittest/mytap +noinst_HEADERS = thr_template.c + LDADD = $(top_builddir)/unittest/mytap/libmytap.a \ $(top_builddir)/mysys/libmysys.a \ $(top_builddir)/dbug/libdbug.a \ diff --git a/unittest/mysys/my_atomic-t.c b/unittest/mysys/my_atomic-t.c index f2bcd360508..1a558e8cb73 100644 --- a/unittest/mysys/my_atomic-t.c +++ b/unittest/mysys/my_atomic-t.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2006 MySQL AB +/* Copyright (C) 2006-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 @@ -13,10 +13,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include -#include -#include -#include +#include "thr_template.c" /* at least gcc 3.4.5 and 3.4.6 (but not 3.2.3) on RHEL */ #if __GNUC__ == 3 && __GNUC_MINOR__ == 4 @@ -25,181 +22,125 @@ #define GCC_BUG_WORKAROUND #endif -int32 a32,b32,c32; +volatile uint32 b32; +volatile int32 c32; my_atomic_rwlock_t rwl; -pthread_attr_t thr_attr; -pthread_mutex_t mutex; -pthread_cond_t cond; -int N; - /* add and sub a random number in a loop. Must get 0 at the end */ -pthread_handler_t test_atomic_add_handler(void *arg) +pthread_handler_t test_atomic_add(void *arg) { - int m=*(int *)arg; + int m= (*(int *)arg)/2; GCC_BUG_WORKAROUND int32 x; - for (x=((int)((long)(&m))); m ; m--) + for (x= ((int)(intptr)(&m)); m ; m--) { - x=x*m+0x87654321; + x= (x*m+0x87654321) & INT_MAX32; my_atomic_rwlock_wrlock(&rwl); - my_atomic_add32(&a32, x); + my_atomic_add32(&bad, x); my_atomic_rwlock_wrunlock(&rwl); my_atomic_rwlock_wrlock(&rwl); - my_atomic_add32(&a32, -x); + my_atomic_add32(&bad, -x); my_atomic_rwlock_wrunlock(&rwl); } pthread_mutex_lock(&mutex); - N--; - if (!N) pthread_cond_signal(&cond); + if (!--running_threads) pthread_cond_signal(&cond); pthread_mutex_unlock(&mutex); return 0; } /* 1. generate thread number 0..N-1 from b32 - 2. add it to a32 + 2. add it to bad 3. swap thread numbers in c32 4. (optionally) one more swap to avoid 0 as a result - 5. subtract result from a32 - must get 0 in a32 at the end + 5. subtract result from bad + must get 0 in bad at the end */ -pthread_handler_t test_atomic_swap_handler(void *arg) +pthread_handler_t test_atomic_fas(void *arg) { - int m=*(int *)arg; - int32 x; + int m= *(int *)arg; + int32 x; my_atomic_rwlock_wrlock(&rwl); - x=my_atomic_add32(&b32, 1); + x= my_atomic_add32(&b32, 1); my_atomic_rwlock_wrunlock(&rwl); my_atomic_rwlock_wrlock(&rwl); - my_atomic_add32(&a32, x); + my_atomic_add32(&bad, x); my_atomic_rwlock_wrunlock(&rwl); for (; m ; m--) { my_atomic_rwlock_wrlock(&rwl); - x=my_atomic_swap32(&c32, x); + x= my_atomic_fas32(&c32, x); my_atomic_rwlock_wrunlock(&rwl); } if (!x) { my_atomic_rwlock_wrlock(&rwl); - x=my_atomic_swap32(&c32, x); + x= my_atomic_fas32(&c32, x); my_atomic_rwlock_wrunlock(&rwl); } my_atomic_rwlock_wrlock(&rwl); - my_atomic_add32(&a32, -x); + my_atomic_add32(&bad, -x); my_atomic_rwlock_wrunlock(&rwl); pthread_mutex_lock(&mutex); - N--; - if (!N) pthread_cond_signal(&cond); + if (!--running_threads) pthread_cond_signal(&cond); pthread_mutex_unlock(&mutex); return 0; } /* - same as test_atomic_add_handler, but my_atomic_add32 is emulated with - (slower) my_atomic_cas32 + same as test_atomic_add, but my_atomic_add32 is emulated with + my_atomic_cas32 - notice that the slowdown is proportional to the + number of CPUs */ -pthread_handler_t test_atomic_cas_handler(void *arg) +pthread_handler_t test_atomic_cas(void *arg) { - int m=*(int *)arg, ok; - GCC_BUG_WORKAROUND int32 x,y; - for (x=((int)((long)(&m))); m ; m--) + int m= (*(int *)arg)/2, ok= 0; + GCC_BUG_WORKAROUND int32 x, y; + for (x= ((int)(intptr)(&m)); m ; m--) { my_atomic_rwlock_wrlock(&rwl); - y=my_atomic_load32(&a32); + y= my_atomic_load32(&bad); my_atomic_rwlock_wrunlock(&rwl); - - x=x*m+0x87654321; + x= (x*m+0x87654321) & INT_MAX32; do { my_atomic_rwlock_wrlock(&rwl); - ok=my_atomic_cas32(&a32, &y, y+x); + ok= my_atomic_cas32(&bad, &y, (uint32)y+x); my_atomic_rwlock_wrunlock(&rwl); - } while (!ok); + } while (!ok) ; do { my_atomic_rwlock_wrlock(&rwl); - ok=my_atomic_cas32(&a32, &y, y-x); + ok= my_atomic_cas32(&bad, &y, y-x); my_atomic_rwlock_wrunlock(&rwl); - } while (!ok); + } while (!ok) ; } pthread_mutex_lock(&mutex); - N--; - if (!N) pthread_cond_signal(&cond); + if (!--running_threads) pthread_cond_signal(&cond); pthread_mutex_unlock(&mutex); return 0; } -void test_atomic(const char *test, pthread_handler handler, int n, int m) + +void do_tests() { - pthread_t t; - ulonglong now=my_getsystime(); - - a32= 0; - b32= 0; - c32= 0; - - diag("Testing %s with %d threads, %d iterations... ", test, n, m); - for (N=n ; n ; n--) - { - if (pthread_create(&t, &thr_attr, handler, &m) != 0) - { - diag("Could not create thread"); - a32= 1; - goto err; - } - } - - pthread_mutex_lock(&mutex); - while (N) - pthread_cond_wait(&cond, &mutex); - pthread_mutex_unlock(&mutex); - now=my_getsystime()-now; -err: - ok(a32 == 0, "tested %s in %g secs", test, ((double)now)/1e7); -} - -int main() -{ - int err; - MY_INIT("my_atomic-t.c"); - - diag("N CPUs: %d", my_getncpus()); - err= my_atomic_initialize(); - plan(4); - ok(err == 0, "my_atomic_initialize() returned %d", err); - pthread_attr_init(&thr_attr); - pthread_attr_setdetachstate(&thr_attr,PTHREAD_CREATE_DETACHED); - pthread_mutex_init(&mutex, 0); - pthread_cond_init(&cond, 0); + bad= my_atomic_initialize(); + ok(!bad, "my_atomic_initialize() returned %d", bad); + my_atomic_rwlock_init(&rwl); -#ifdef HPUX11 -#define CYCLES 1000 -#else -#define CYCLES 10000 -#endif -#define THREADS 100 - test_atomic("my_atomic_add32", test_atomic_add_handler, THREADS, CYCLES); - test_atomic("my_atomic_swap32", test_atomic_swap_handler, THREADS, CYCLES); - test_atomic("my_atomic_cas32", test_atomic_cas_handler, THREADS, CYCLES); - /* - workaround until we know why it crashes randomly on some machine - (BUG#22320). - */ - sleep(2); + b32= c32= 0; + test_concurrently("my_atomic_add32", test_atomic_add, THREADS, CYCLES); + b32= c32= 0; + test_concurrently("my_atomic_fas32", test_atomic_fas, THREADS, CYCLES); + b32= c32= 0; + test_concurrently("my_atomic_cas32", test_atomic_cas, THREADS, CYCLES); - pthread_mutex_destroy(&mutex); - pthread_cond_destroy(&cond); - pthread_attr_destroy(&thr_attr); my_atomic_rwlock_destroy(&rwl); - return exit_status(); } - diff --git a/unittest/mysys/thr_template.c b/unittest/mysys/thr_template.c new file mode 100644 index 00000000000..1ac03e474fd --- /dev/null +++ b/unittest/mysys/thr_template.c @@ -0,0 +1,92 @@ +/* Copyright (C) 2006-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 */ + +#include +#include +#include +#include + +volatile uint32 bad; +pthread_attr_t thr_attr; +pthread_mutex_t mutex; +pthread_cond_t cond; +uint running_threads; + +void do_tests(); + +void test_concurrently(const char *test, pthread_handler handler, int n, int m) +{ + pthread_t t; + ulonglong now= my_getsystime(); + + bad= 0; + + diag("Testing %s with %d threads, %d iterations... ", test, n, m); + for (running_threads= n ; n ; n--) + { + if (pthread_create(&t, &thr_attr, handler, &m) != 0) + { + diag("Could not create thread"); + abort(); + } + } + pthread_mutex_lock(&mutex); + while (running_threads) + pthread_cond_wait(&cond, &mutex); + pthread_mutex_unlock(&mutex); + + now= my_getsystime()-now; + ok(!bad, "tested %s in %g secs (%d)", test, ((double)now)/1e7, bad); +} + +int main(int argc __attribute__((unused)), char **argv) +{ + MY_INIT("thd_template"); + + if (argv[1] && *argv[1]) + DBUG_SET_INITIAL(argv[1]); + + pthread_mutex_init(&mutex, 0); + pthread_cond_init(&cond, 0); + pthread_attr_init(&thr_attr); + pthread_attr_setdetachstate(&thr_attr,PTHREAD_CREATE_DETACHED); + +#ifdef MY_ATOMIC_MODE_RWLOCKS +#if defined(HPUX11) || defined(__POWERPC__) /* showed to be very slow (scheduler-related) */ +#define CYCLES 300 +#else +#define CYCLES 3000 +#endif +#else +#define CYCLES 3000 +#endif +#define THREADS 30 + + diag("N CPUs: %d, atomic ops: %s", my_getncpus(), MY_ATOMIC_MODE); + + do_tests(); + + /* + workaround until we know why it crashes randomly on some machine + (BUG#22320). + */ + sleep(2); + pthread_mutex_destroy(&mutex); + pthread_cond_destroy(&cond); + pthread_attr_destroy(&thr_attr); + my_end(0); + return exit_status(); +} + From b16be935d418897051b72f0a4b1ff272a46446a7 Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Tue, 17 Nov 2009 17:36:39 -0700 Subject: [PATCH 03/23] Misc cleanup --- include/Makefile.am | 2 +- include/atomic/x86-msvc.h | 96 --------------------------------------- 2 files changed, 1 insertion(+), 97 deletions(-) delete mode 100644 include/atomic/x86-msvc.h diff --git a/include/Makefile.am b/include/Makefile.am index e20b08afe35..e712ef18722 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -41,7 +41,7 @@ noinst_HEADERS = config-win.h config-netware.h my_bit.h \ my_vle.h my_user.h my_atomic.h atomic/nolock.h \ atomic/rwlock.h atomic/x86-gcc.h atomic/generic-msvc.h \ atomic/gcc_builtins.h my_libwrap.h my_stacktrace.h \ - atomic/solaris.h + atomic/solaris.h EXTRA_DIST = mysql.h.pp mysql/plugin.h.pp probes_mysql.d.base diff --git a/include/atomic/x86-msvc.h b/include/atomic/x86-msvc.h deleted file mode 100644 index c4885bb8451..00000000000 --- a/include/atomic/x86-msvc.h +++ /dev/null @@ -1,96 +0,0 @@ -/* 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 -*/ - -// Would it be better to use intrinsics ? -// (InterlockedCompareExchange, InterlockedCompareExchange16 -// InterlockedExchangeAdd, InterlockedExchange) - -#ifndef _atomic_h_cleanup_ -#define _atomic_h_cleanup_ "atomic/x86-msvc.h" - -#define MY_ATOMIC_MODE "msvc-x86" LOCK - -#define make_atomic_add_body(S) \ - _asm { \ - _asm mov reg_ ## S, v \ - _asm LOCK xadd *a, reg_ ## S \ - _asm movzx v, reg_ ## S \ - } -#define make_atomic_cas_body(S) \ - _asm { \ - _asm mov areg_ ## S, *cmp \ - _asm mov reg2_ ## S, set \ - _asm LOCK cmpxchg *a, reg2_ ## S \ - _asm mov *cmp, areg_ ## S \ - _asm setz al \ - _asm movzx ret, al \ - } -#define make_atomic_swap_body(S) \ - _asm { \ - _asm mov reg_ ## S, v \ - _asm xchg *a, reg_ ## S \ - _asm mov v, reg_ ## S \ - } - -#ifdef MY_ATOMIC_MODE_DUMMY -#define make_atomic_load_body(S) ret=*a -#define make_atomic_store_body(S) *a=v -#else -/* - Actually 32-bit reads/writes are always atomic on x86 - But we add LOCK here anyway to force memory barriers -*/ -#define make_atomic_load_body(S) \ - _asm { \ - _asm mov areg_ ## S, 0 \ - _asm mov reg2_ ## S, areg_ ## S \ - _asm LOCK cmpxchg *a, reg2_ ## S \ - _asm mov ret, areg_ ## S \ - } -#define make_atomic_store_body(S) \ - _asm { \ - _asm mov reg_ ## S, v \ - _asm xchg *a, reg_ ## S \ - } -#endif - -#define reg_8 al -#define reg_16 ax -#define reg_32 eax -#define areg_8 al -#define areg_16 ax -#define areg_32 eax -#define reg2_8 bl -#define reg2_16 bx -#define reg2_32 ebx - -#else /* cleanup */ - -#undef reg_8 -#undef reg_16 -#undef reg_32 -#undef areg_8 -#undef areg_16 -#undef areg_32 -#undef reg2_8 -#undef reg2_16 -#undef reg2_32 -#endif - From 3ff74fb5fadc1cae7718216b47a8afc6b712e6f1 Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Tue, 17 Nov 2009 19:31:40 -0700 Subject: [PATCH 04/23] WL#3230 concurrent hash Backport from 6.0.14 to 5.6.0 Original code from Sergei Golubchik --- configure.in | 2 +- include/Makefile.am | 2 +- include/lf.h | 268 +++++++++++++++++++ include/my_pthread.h | 13 + mysys/Makefile.am | 3 +- mysys/lf_alloc-pin.c | 534 +++++++++++++++++++++++++++++++++++++ mysys/lf_dynarray.c | 207 ++++++++++++++ mysys/lf_hash.c | 505 +++++++++++++++++++++++++++++++++++ mysys/my_thr_init.c | 3 + unittest/mysys/Makefile.am | 2 +- unittest/mysys/lf-t.c | 178 +++++++++++++ 11 files changed, 1713 insertions(+), 4 deletions(-) create mode 100644 include/lf.h create mode 100644 mysys/lf_alloc-pin.c create mode 100644 mysys/lf_dynarray.c create mode 100644 mysys/lf_hash.c create mode 100644 unittest/mysys/lf-t.c diff --git a/configure.in b/configure.in index dd2c53a2b52..db86eeaa779 100644 --- a/configure.in +++ b/configure.in @@ -2114,7 +2114,7 @@ AC_CHECK_FUNCS(alarm bcmp bfill bmove bsearch bzero \ pthread_setprio_np pthread_setschedparam pthread_sigmask readlink \ realpath rename rint rwlock_init setupterm \ shmget shmat shmdt shmctl sigaction sigemptyset sigaddset \ - sighold sigset sigthreadmask port_create sleep \ + sighold sigset sigthreadmask port_create sleep thr_yield \ snprintf socket stpcpy strcasecmp strerror strsignal strnlen strpbrk strstr \ strtol strtoll strtoul strtoull tell tempnam thr_setconcurrency vidattr \ posix_fallocate backtrace backtrace_symbols backtrace_symbols_fd) diff --git a/include/Makefile.am b/include/Makefile.am index e712ef18722..83a22f1beec 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -30,7 +30,7 @@ pkginclude_HEADERS = $(HEADERS_ABI) my_dbug.h m_string.h my_sys.h \ m_ctype.h my_attribute.h $(HEADERS_GEN_CONFIGURE) \ $(HEADERS_GEN_MAKE) probes_mysql.h probes_mysql_nodtrace.h -noinst_HEADERS = config-win.h config-netware.h my_bit.h \ +noinst_HEADERS = config-win.h config-netware.h lf.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 \ diff --git a/include/lf.h b/include/lf.h new file mode 100644 index 00000000000..7e8f05f4ada --- /dev/null +++ b/include/lf.h @@ -0,0 +1,268 @@ +/* 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 + +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; + void (*constructor)(uchar *); /* called, when an object is malloc()'ed */ + void (*destructor)(uchar *); /* called, when an object is free()'d */ +} 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((uchar*)(ADDR), MYF(0)) + +lock_wrap(lf_alloc_new, void *, + (LF_PINS *pins), + (pins), + &pins->pinbox->pinarray.lock) + +C_MODE_END + +/* + extendible hash, lf_hash.c +*/ +#include + +C_MODE_START + +#define LF_HASH_UNIQUE 1 + +/* lf_hash overhead per element (that is, sizeof(LF_SLIST) */ +extern const int LF_HASH_OVERHEAD; + +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/my_pthread.h b/include/my_pthread.h index b6d9feae067..3e23c0fa410 100644 --- a/include/my_pthread.h +++ b/include/my_pthread.h @@ -152,6 +152,7 @@ int pthread_join(pthread_t thread, void **value_ptr); #define pthread_detach_this_thread() #define pthread_condattr_init(A) #define pthread_condattr_destroy(A) +#define pthread_yield() SwitchToThread() #define my_pthread_getprio(thread_id) pthread_dummy(0) @@ -385,6 +386,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 @@ -663,6 +675,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]; diff --git a/mysys/Makefile.am b/mysys/Makefile.am index 68fde34ee07..3b53fc1dd59 100644 --- a/mysys/Makefile.am +++ b/mysys/Makefile.am @@ -30,7 +30,8 @@ libmysys_a_SOURCES = my_init.c my_getwd.c mf_getdate.c my_mmap.c \ mf_tempdir.c my_lock.c mf_brkhant.c my_alarm.c \ my_malloc.c my_realloc.c my_once.c mulalloc.c \ my_alloc.c safemalloc.c my_new.cc \ - my_vle.c my_atomic.c \ + my_vle.c my_atomic.c lf_hash.c \ + lf_dynarray.c lf_alloc-pin.c \ my_fopen.c my_fstream.c my_getsystime.c \ my_error.c errors.c my_div.c my_messnc.c \ mf_format.c mf_same.c mf_dirname.c mf_fn_ext.c \ diff --git a/mysys/lf_alloc-pin.c b/mysys/lf_alloc-pin.c new file mode 100644 index 00000000000..fda9b97791d --- /dev/null +++ b/mysys/lf_alloc-pin.c @@ -0,0 +1,534 @@ +/* QQ: TODO multi-pinbox */ +/* 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 */ + +/* + wait-free concurrent allocator based on pinning addresses + + It works as follows: every thread (strictly speaking - every CPU, but + it's too difficult to do) has a small array of pointers. They're called + "pins". Before using an object its address must be stored in this array + (pinned). When an object is no longer necessary its address must be + removed from this array (unpinned). When a thread wants to free() an + object it scans all pins of all threads to see if somebody has this + object pinned. If yes - the object is not freed (but stored in a + "purgatory"). To reduce the cost of a single free() pins are not scanned + on every free() but only added to (thread-local) purgatory. On every + LF_PURGATORY_SIZE free() purgatory is scanned and all unpinned objects + are freed. + + Pins are used to solve ABA problem. To use pins one must obey + a pinning protocol: + + 1. Let's assume that PTR is a shared pointer to an object. Shared means + that any thread may modify it anytime to point to a different object + and free the old object. Later the freed object may be potentially + allocated by another thread. If we're unlucky that other thread may + set PTR to point to this object again. This is ABA problem. + 2. Create a local pointer LOCAL_PTR. + 3. Pin the PTR in a loop: + do + { + LOCAL_PTR= PTR; + pin(PTR, PIN_NUMBER); + } while (LOCAL_PTR != PTR) + 4. It is guaranteed that after the loop has ended, LOCAL_PTR + points to an object (or NULL, if PTR may be NULL), that + will never be freed. It is not guaranteed though + that LOCAL_PTR == PTR (as PTR can change any time) + 5. When done working with the object, remove the pin: + unpin(PIN_NUMBER) + 6. When copying pins (as in the list traversing loop: + pin(CUR, 1); + while () + { + do // standard + { // pinning + NEXT=CUR->next; // loop + pin(NEXT, 0); // see #3 + } while (NEXT != CUR->next); // above + ... + ... + CUR=NEXT; + pin(CUR, 1); // copy pin[0] to pin[1] + } + which keeps CUR address constantly pinned), note than pins may be + copied only upwards (!!!), that is pin[N] to pin[M], M > N. + 7. Don't keep the object pinned longer than necessary - the number of + pins you have is limited (and small), keeping an object pinned + prevents its reuse and cause unnecessary mallocs. + + Explanations: + + 3. The loop is important. The following can occur: + thread1> LOCAL_PTR= PTR + thread2> free(PTR); PTR=0; + thread1> pin(PTR, PIN_NUMBER); + now thread1 cannot access LOCAL_PTR, even if it's pinned, + because it points to a freed memory. That is, it *must* + verify that it has indeed pinned PTR, the shared pointer. + + 6. When a thread wants to free some LOCAL_PTR, and it scans + all lists of pins to see whether it's pinned, it does it + upwards, from low pin numbers to high. Thus another thread + must copy an address from one pin to another in the same + direction - upwards, otherwise the scanning thread may + miss it. + + Implementation details: + + Pins are given away from a "pinbox". Pinbox is stack-based allocator. + It used dynarray for storing pins, new elements are allocated by dynarray + as necessary, old are pushed in the stack for reuse. ABA is solved by + versioning a pointer - because we use an array, a pointer to pins is 16 bit, + upper 16 bits are used for a version. + + It is assumed that pins belong to a THD and are not transferable + between THD's (LF_PINS::stack_ends_here being a primary reason + for this limitation). +*/ +#include +#include +#include + +#define LF_PINBOX_MAX_PINS 65536 + +static void _lf_pinbox_real_free(LF_PINS *pins); + +/* + Initialize a pinbox. Normally called from lf_alloc_init. + See the latter for details. +*/ +void lf_pinbox_init(LF_PINBOX *pinbox, uint free_ptr_offset, + lf_pinbox_free_func *free_func, void *free_func_arg) +{ + DBUG_ASSERT(free_ptr_offset % sizeof(void *) == 0); + compile_time_assert(sizeof(LF_PINS) == 64); + lf_dynarray_init(&pinbox->pinarray, sizeof(LF_PINS)); + pinbox->pinstack_top_ver= 0; + pinbox->pins_in_array= 0; + pinbox->free_ptr_offset= free_ptr_offset; + pinbox->free_func= free_func; + pinbox->free_func_arg= free_func_arg; +} + +void lf_pinbox_destroy(LF_PINBOX *pinbox) +{ + lf_dynarray_destroy(&pinbox->pinarray); +} + +/* + Get pins from a pinbox. Usually called via lf_alloc_get_pins() or + lf_hash_get_pins(). + + SYNOPSYS + pinbox - + + DESCRIPTION + get a new LF_PINS structure from a stack of unused pins, + or allocate a new one out of dynarray. + + NOTE + It is assumed that pins belong to a thread and are not transferable + between threads. +*/ +LF_PINS *_lf_pinbox_get_pins(LF_PINBOX *pinbox) +{ + uint32 pins, next, top_ver; + LF_PINS *el; + /* + We have an array of max. 64k elements. + The highest index currently allocated is pinbox->pins_in_array. + Freed elements are in a lifo stack, pinstack_top_ver. + pinstack_top_ver is 32 bits; 16 low bits are the index in the + array, to the first element of the list. 16 high bits are a version + (every time the 16 low bits are updated, the 16 high bits are + incremented). Versioniong prevents the ABA problem. + */ + top_ver= pinbox->pinstack_top_ver; + do + { + if (!(pins= top_ver % LF_PINBOX_MAX_PINS)) + { + /* the stack of free elements is empty */ + pins= my_atomic_add32((int32 volatile*) &pinbox->pins_in_array, 1)+1; + if (unlikely(pins >= LF_PINBOX_MAX_PINS)) + return 0; + /* + note that the first allocated element has index 1 (pins==1). + index 0 is reserved to mean "NULL pointer" + */ + el= (LF_PINS *)_lf_dynarray_lvalue(&pinbox->pinarray, pins); + if (unlikely(!el)) + return 0; + break; + } + el= (LF_PINS *)_lf_dynarray_value(&pinbox->pinarray, pins); + next= el->link; + } while (!my_atomic_cas32((int32 volatile*) &pinbox->pinstack_top_ver, + (int32*) &top_ver, + top_ver-pins+next+LF_PINBOX_MAX_PINS)); + /* + set el->link to the index of el in the dynarray (el->link has two usages: + - if element is allocated, it's its own index + - if element is free, it's its next element in the free stack + */ + el->link= pins; + el->purgatory_count= 0; + el->pinbox= pinbox; + el->stack_ends_here= & my_thread_var->stack_ends_here; + return el; +} + +/* + Put pins back to a pinbox. Usually called via lf_alloc_put_pins() or + lf_hash_put_pins(). + + DESCRIPTION + empty the purgatory (XXX deadlock warning below!), + push LF_PINS structure to a stack +*/ +void _lf_pinbox_put_pins(LF_PINS *pins) +{ + LF_PINBOX *pinbox= pins->pinbox; + uint32 top_ver, nr; + nr= pins->link; +#ifdef MY_LF_EXTRA_DEBUG + { + int i; + for (i= 0; i < LF_PINBOX_PINS; i++) + DBUG_ASSERT(pins->pin[i] == 0); + } +#endif + /* + XXX this will deadlock if other threads will wait for + the caller to do something after _lf_pinbox_put_pins(), + and they would have pinned addresses that the caller wants to free. + Thus: only free pins when all work is done and nobody can wait for you!!! + */ + while (pins->purgatory_count) + { + _lf_pinbox_real_free(pins); + if (pins->purgatory_count) + { + my_atomic_rwlock_wrunlock(&pins->pinbox->pinarray.lock); + pthread_yield(); + my_atomic_rwlock_wrlock(&pins->pinbox->pinarray.lock); + } + } + top_ver= pinbox->pinstack_top_ver; + do + { + pins->link= top_ver % LF_PINBOX_MAX_PINS; + } while (!my_atomic_cas32((int32 volatile*) &pinbox->pinstack_top_ver, + (int32*) &top_ver, + top_ver-pins->link+nr+LF_PINBOX_MAX_PINS)); + return; +} + +static int ptr_cmp(void **a, void **b) +{ + return *a < *b ? -1 : *a == *b ? 0 : 1; +} + +#define add_to_purgatory(PINS, ADDR) \ + do \ + { \ + *(void **)((char *)(ADDR)+(PINS)->pinbox->free_ptr_offset)= \ + (PINS)->purgatory; \ + (PINS)->purgatory= (ADDR); \ + (PINS)->purgatory_count++; \ + } while (0) + +/* + Free an object allocated via pinbox allocator + + DESCRIPTION + add an object to purgatory. if necessary, call _lf_pinbox_real_free() + to actually free something. +*/ +void _lf_pinbox_free(LF_PINS *pins, void *addr) +{ + add_to_purgatory(pins, addr); + if (pins->purgatory_count % LF_PURGATORY_SIZE) + _lf_pinbox_real_free(pins); +} + +struct st_harvester { + void **granary; + int npins; +}; + +/* + callback for _lf_dynarray_iterate: + scan all pins of all threads and accumulate all pins +*/ +static int harvest_pins(LF_PINS *el, struct st_harvester *hv) +{ + int i; + LF_PINS *el_end= el+min(hv->npins, LF_DYNARRAY_LEVEL_LENGTH); + for (; el < el_end; el++) + { + for (i= 0; i < LF_PINBOX_PINS; i++) + { + void *p= el->pin[i]; + if (p) + *hv->granary++= p; + } + } + /* + hv->npins may become negative below, but it means that + we're on the last dynarray page and harvest_pins() won't be + called again. We don't bother to make hv->npins() correct + (that is 0) in this case. + */ + hv->npins-= LF_DYNARRAY_LEVEL_LENGTH; + return 0; +} + +/* + callback for _lf_dynarray_iterate: + scan all pins of all threads and see if addr is present there +*/ +static int match_pins(LF_PINS *el, void *addr) +{ + int i; + LF_PINS *el_end= el+LF_DYNARRAY_LEVEL_LENGTH; + for (; el < el_end; el++) + for (i= 0; i < LF_PINBOX_PINS; i++) + if (el->pin[i] == addr) + return 1; + return 0; +} + +#if STACK_DIRECTION < 0 +#define available_stack_size(CUR,END) (long) ((char*)(CUR) - (char*)(END)) +#else +#define available_stack_size(CUR,END) (long) ((char*)(END) - (char*)(CUR)) +#endif + +#define next_node(P, X) (*((uchar * volatile *)(((uchar *)(X)) + (P)->free_ptr_offset))) +#define anext_node(X) next_node(&allocator->pinbox, (X)) + +/* + Scan the purgatory and free everything that can be freed +*/ +static void _lf_pinbox_real_free(LF_PINS *pins) +{ + int npins, alloca_size; + void *list, **addr; + void *first, *last= NULL; + LF_PINBOX *pinbox= pins->pinbox; + + LINT_INIT(first); + npins= pinbox->pins_in_array+1; + +#ifdef HAVE_ALLOCA + alloca_size= sizeof(void *)*LF_PINBOX_PINS*npins; + /* create a sorted list of pinned addresses, to speed up searches */ + if (available_stack_size(&pinbox, *pins->stack_ends_here) > alloca_size) + { + struct st_harvester hv; + addr= (void **) alloca(alloca_size); + hv.granary= addr; + hv.npins= npins; + /* scan the dynarray and accumulate all pinned addresses */ + _lf_dynarray_iterate(&pinbox->pinarray, + (lf_dynarray_func)harvest_pins, &hv); + + npins= hv.granary-addr; + /* and sort them */ + if (npins) + qsort(addr, npins, sizeof(void *), (qsort_cmp)ptr_cmp); + } + else +#endif + addr= 0; + + list= pins->purgatory; + pins->purgatory= 0; + pins->purgatory_count= 0; + while (list) + { + void *cur= list; + list= *(void **)((char *)cur+pinbox->free_ptr_offset); + if (npins) + { + if (addr) /* use binary search */ + { + void **a, **b, **c; + for (a= addr, b= addr+npins-1, c= a+(b-a)/2; (b-a) > 1; c= a+(b-a)/2) + if (cur == *c) + a= b= c; + else if (cur > *c) + a= c; + else + b= c; + if (cur == *a || cur == *b) + goto found; + } + else /* no alloca - no cookie. linear search here */ + { + if (_lf_dynarray_iterate(&pinbox->pinarray, + (lf_dynarray_func)match_pins, cur)) + goto found; + } + } + /* not pinned - freeing */ + if (last) + last= next_node(pinbox, last)= (uchar *)cur; + else + first= last= (uchar *)cur; + continue; +found: + /* pinned - keeping */ + add_to_purgatory(pins, cur); + } + if (last) + pinbox->free_func(first, last, pinbox->free_func_arg); +} + +/* lock-free memory allocator for fixed-size objects */ + +LF_REQUIRE_PINS(1) + +/* + callback for _lf_pinbox_real_free to free a list of unpinned objects - + add it back to the allocator stack + + DESCRIPTION + 'first' and 'last' are the ends of the linked list of nodes: + first->el->el->....->el->last. Use first==last to free only one element. +*/ +static void alloc_free(uchar *first, + uchar volatile *last, + LF_ALLOCATOR *allocator) +{ + /* + we need a union here to access type-punned pointer reliably. + otherwise gcc -fstrict-aliasing will not see 'tmp' changed in the loop + */ + union { uchar * node; void *ptr; } tmp; + tmp.node= allocator->top; + do + { + anext_node(last)= tmp.node; + } while (!my_atomic_casptr((void **)(char *)&allocator->top, + (void **)&tmp.ptr, first) && LF_BACKOFF); +} + +/* + initialize lock-free allocator + + SYNOPSYS + allocator - + size a size of an object to allocate + free_ptr_offset an offset inside the object to a sizeof(void *) + memory that is guaranteed to be unused after + the object is put in the purgatory. Unused by ANY + thread, not only the purgatory owner. + This memory will be used to link waiting-to-be-freed + objects in a purgatory list. +*/ +void lf_alloc_init(LF_ALLOCATOR *allocator, uint size, uint free_ptr_offset) +{ + lf_pinbox_init(&allocator->pinbox, free_ptr_offset, + (lf_pinbox_free_func *)alloc_free, allocator); + allocator->top= 0; + allocator->mallocs= 0; + allocator->element_size= size; + allocator->constructor= 0; + allocator->destructor= 0; + DBUG_ASSERT(size >= sizeof(void*) + free_ptr_offset); +} + +/* + destroy the allocator, free everything that's in it + + NOTE + As every other init/destroy function here and elsewhere it + is not thread safe. No, this function is no different, ensure + that no thread needs the allocator before destroying it. + We are not responsible for any damage that may be caused by + accessing the allocator when it is being or has been destroyed. + Oh yes, and don't put your cat in a microwave. +*/ +void lf_alloc_destroy(LF_ALLOCATOR *allocator) +{ + uchar *node= allocator->top; + while (node) + { + uchar *tmp= anext_node(node); + if (allocator->destructor) + allocator->destructor(node); + my_free((void *)node, MYF(0)); + node= tmp; + } + lf_pinbox_destroy(&allocator->pinbox); + allocator->top= 0; +} + +/* + Allocate and return an new object. + + DESCRIPTION + Pop an unused object from the stack or malloc it is the stack is empty. + pin[0] is used, it's removed on return. +*/ +void *_lf_alloc_new(LF_PINS *pins) +{ + LF_ALLOCATOR *allocator= (LF_ALLOCATOR *)(pins->pinbox->free_func_arg); + uchar *node; + for (;;) + { + do + { + node= allocator->top; + _lf_pin(pins, 0, node); + } while (node != allocator->top && LF_BACKOFF); + if (!node) + { + node= (void *)my_malloc(allocator->element_size, MYF(MY_WME)); + if (allocator->constructor) + allocator->constructor(node); +#ifdef MY_LF_EXTRA_DEBUG + if (likely(node != 0)) + my_atomic_add32(&allocator->mallocs, 1); +#endif + break; + } + if (my_atomic_casptr((void **)(char *)&allocator->top, + (void *)&node, anext_node(node))) + break; + } + _lf_unpin(pins, 0); + return node; +} + +/* + count the number of objects in a pool. + + NOTE + This is NOT thread-safe !!! +*/ +uint lf_alloc_pool_count(LF_ALLOCATOR *allocator) +{ + uint i; + uchar *node; + for (node= allocator->top, i= 0; node; node= anext_node(node), i++) + /* no op */; + return i; +} + diff --git a/mysys/lf_dynarray.c b/mysys/lf_dynarray.c new file mode 100644 index 00000000000..b1cdce698a9 --- /dev/null +++ b/mysys/lf_dynarray.c @@ -0,0 +1,207 @@ +/* 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 */ + +/* + Analog of DYNAMIC_ARRAY that never reallocs + (so no pointer into the array may ever become invalid). + + Memory is allocated in non-contiguous chunks. + This data structure is not space efficient for sparse arrays. + + Every element is aligned to sizeof(element) boundary + (to avoid false sharing if element is big enough). + + LF_DYNARRAY is a recursive structure. On the zero level + LF_DYNARRAY::level[0] it's an array of LF_DYNARRAY_LEVEL_LENGTH elements, + on the first level it's an array of LF_DYNARRAY_LEVEL_LENGTH pointers + to arrays of elements, on the second level it's an array of pointers + to arrays of pointers to arrays of elements. And so on. + + With four levels the number of elements is limited to 4311810304 + (but as in all functions index is uint, the real limit is 2^32-1) + + Actually, it's wait-free, not lock-free ;-) +*/ + +#include +#include +#include +#include + +void lf_dynarray_init(LF_DYNARRAY *array, uint element_size) +{ + bzero(array, sizeof(*array)); + array->size_of_element= element_size; + my_atomic_rwlock_init(&array->lock); +} + +static void recursive_free(void **alloc, int level) +{ + if (!alloc) + return; + + if (level) + { + int i; + for (i= 0; i < LF_DYNARRAY_LEVEL_LENGTH; i++) + recursive_free(alloc[i], level-1); + my_free((void *)alloc, MYF(0)); + } + else + my_free(alloc[-1], MYF(0)); +} + +void lf_dynarray_destroy(LF_DYNARRAY *array) +{ + int i; + for (i= 0; i < LF_DYNARRAY_LEVELS; i++) + recursive_free(array->level[i], i); + my_atomic_rwlock_destroy(&array->lock); +} + +static const ulong dynarray_idxes_in_prev_levels[LF_DYNARRAY_LEVELS]= +{ + 0, /* +1 here to to avoid -1's below */ + LF_DYNARRAY_LEVEL_LENGTH, + LF_DYNARRAY_LEVEL_LENGTH * LF_DYNARRAY_LEVEL_LENGTH + + LF_DYNARRAY_LEVEL_LENGTH, + LF_DYNARRAY_LEVEL_LENGTH * LF_DYNARRAY_LEVEL_LENGTH * + LF_DYNARRAY_LEVEL_LENGTH + LF_DYNARRAY_LEVEL_LENGTH * + LF_DYNARRAY_LEVEL_LENGTH + LF_DYNARRAY_LEVEL_LENGTH +}; + +static const ulong dynarray_idxes_in_prev_level[LF_DYNARRAY_LEVELS]= +{ + 0, /* +1 here to to avoid -1's below */ + LF_DYNARRAY_LEVEL_LENGTH, + LF_DYNARRAY_LEVEL_LENGTH * LF_DYNARRAY_LEVEL_LENGTH, + LF_DYNARRAY_LEVEL_LENGTH * LF_DYNARRAY_LEVEL_LENGTH * + LF_DYNARRAY_LEVEL_LENGTH, +}; + +/* + Returns a valid lvalue pointer to the element number 'idx'. + Allocates memory if necessary. +*/ +void *_lf_dynarray_lvalue(LF_DYNARRAY *array, uint idx) +{ + void * ptr, * volatile * ptr_ptr= 0; + int i; + + for (i= LF_DYNARRAY_LEVELS-1; idx < dynarray_idxes_in_prev_levels[i]; i--) + /* no-op */; + ptr_ptr= &array->level[i]; + idx-= dynarray_idxes_in_prev_levels[i]; + for (; i > 0; i--) + { + if (!(ptr= *ptr_ptr)) + { + void *alloc= my_malloc(LF_DYNARRAY_LEVEL_LENGTH * sizeof(void *), + MYF(MY_WME|MY_ZEROFILL)); + if (unlikely(!alloc)) + return(NULL); + if (my_atomic_casptr(ptr_ptr, &ptr, alloc)) + ptr= alloc; + else + my_free(alloc, MYF(0)); + } + ptr_ptr= ((void **)ptr) + idx / dynarray_idxes_in_prev_level[i]; + idx%= dynarray_idxes_in_prev_level[i]; + } + if (!(ptr= *ptr_ptr)) + { + uchar *alloc, *data; + alloc= my_malloc(LF_DYNARRAY_LEVEL_LENGTH * array->size_of_element + + max(array->size_of_element, sizeof(void *)), + MYF(MY_WME|MY_ZEROFILL)); + if (unlikely(!alloc)) + return(NULL); + /* reserve the space for free() address */ + data= alloc + sizeof(void *); + { /* alignment */ + intptr mod= ((intptr)data) % array->size_of_element; + if (mod) + data+= array->size_of_element - mod; + } + ((void **)data)[-1]= alloc; /* free() will need the original pointer */ + if (my_atomic_casptr(ptr_ptr, &ptr, data)) + ptr= data; + else + my_free(alloc, MYF(0)); + } + return ((uchar*)ptr) + array->size_of_element * idx; +} + +/* + Returns a pointer to the element number 'idx' + or NULL if an element does not exists +*/ +void *_lf_dynarray_value(LF_DYNARRAY *array, uint idx) +{ + void * ptr, * volatile * ptr_ptr= 0; + int i; + + for (i= LF_DYNARRAY_LEVELS-1; idx < dynarray_idxes_in_prev_levels[i]; i--) + /* no-op */; + ptr_ptr= &array->level[i]; + idx-= dynarray_idxes_in_prev_levels[i]; + for (; i > 0; i--) + { + if (!(ptr= *ptr_ptr)) + return(NULL); + ptr_ptr= ((void **)ptr) + idx / dynarray_idxes_in_prev_level[i]; + idx %= dynarray_idxes_in_prev_level[i]; + } + if (!(ptr= *ptr_ptr)) + return(NULL); + return ((uchar*)ptr) + array->size_of_element * idx; +} + +static int recursive_iterate(LF_DYNARRAY *array, void *ptr, int level, + lf_dynarray_func func, void *arg) +{ + int res, i; + if (!ptr) + return 0; + if (!level) + return func(ptr, arg); + for (i= 0; i < LF_DYNARRAY_LEVEL_LENGTH; i++) + if ((res= recursive_iterate(array, ((void **)ptr)[i], level-1, func, arg))) + return res; + return 0; +} + +/* + Calls func(array, arg) on every array of LF_DYNARRAY_LEVEL_LENGTH elements + in lf_dynarray. + + DESCRIPTION + lf_dynarray consists of a set of arrays, LF_DYNARRAY_LEVEL_LENGTH elements + each. _lf_dynarray_iterate() calls user-supplied function on every array + from the set. It is the fastest way to scan the array, faster than + for (i=0; i < N; i++) { func(_lf_dynarray_value(dynarray, i)); } + + NOTE + if func() returns non-zero, the scan is aborted +*/ +int _lf_dynarray_iterate(LF_DYNARRAY *array, lf_dynarray_func func, void *arg) +{ + int i, res; + for (i= 0; i < LF_DYNARRAY_LEVELS; i++) + if ((res= recursive_iterate(array, array->level[i], i, func, arg))) + return res; + return 0; +} + diff --git a/mysys/lf_hash.c b/mysys/lf_hash.c new file mode 100644 index 00000000000..f478196c7c8 --- /dev/null +++ b/mysys/lf_hash.c @@ -0,0 +1,505 @@ +/* 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 */ + +/* + extensible hash + + TODO + try to get rid of dummy nodes ? + for non-unique hash, count only _distinct_ values + (but how to do it in lf_hash_delete ?) +*/ +#include +#include +#include +#include +#include + +LF_REQUIRE_PINS(3) + +/* An element of the list */ +typedef struct { + intptr volatile link; /* a pointer to the next element in a listand a flag */ + uint32 hashnr; /* reversed hash number, for sorting */ + const uchar *key; + size_t keylen; + /* + data is stored here, directly after the keylen. + thus the pointer to data is (void*)(slist_element_ptr+1) + */ +} LF_SLIST; + +const int LF_HASH_OVERHEAD= sizeof(LF_SLIST); + +/* + a structure to pass the context (pointers two the three successive elements + in a list) from lfind to linsert/ldelete +*/ +typedef struct { + intptr volatile *prev; + LF_SLIST *curr, *next; +} CURSOR; + +/* + the last bit in LF_SLIST::link is a "deleted" flag. + the helper macros below convert it to a pure pointer or a pure flag +*/ +#define PTR(V) (LF_SLIST *)((V) & (~(intptr)1)) +#define DELETED(V) ((V) & 1) + +/* + DESCRIPTION + Search for hashnr/key/keylen in the list starting from 'head' and + position the cursor. The list is ORDER BY hashnr, key + + RETURN + 0 - not found + 1 - found + + NOTE + cursor is positioned in either case + pins[0..2] are used, they are NOT removed on return +*/ +static int lfind(LF_SLIST * volatile *head, CHARSET_INFO *cs, uint32 hashnr, + const uchar *key, uint keylen, CURSOR *cursor, LF_PINS *pins) +{ + uint32 cur_hashnr; + const uchar *cur_key; + uint cur_keylen; + intptr link; + +retry: + cursor->prev= (intptr *)head; + do { /* PTR() isn't necessary below, head is a dummy node */ + cursor->curr= (LF_SLIST *)(*cursor->prev); + _lf_pin(pins, 1, cursor->curr); + } while (*cursor->prev != (intptr)cursor->curr && LF_BACKOFF); + for (;;) + { + if (unlikely(!cursor->curr)) + return 0; /* end of the list */ + do { + /* QQ: XXX or goto retry ? */ + link= cursor->curr->link; + cursor->next= PTR(link); + _lf_pin(pins, 0, cursor->next); + } while (link != cursor->curr->link && LF_BACKOFF); + cur_hashnr= cursor->curr->hashnr; + cur_key= cursor->curr->key; + cur_keylen= cursor->curr->keylen; + if (*cursor->prev != (intptr)cursor->curr) + { + (void)LF_BACKOFF; + goto retry; + } + if (!DELETED(link)) + { + if (cur_hashnr >= hashnr) + { + int r= 1; + if (cur_hashnr > hashnr || + (r= my_strnncoll(cs, (uchar*) cur_key, cur_keylen, (uchar*) key, + keylen)) >= 0) + return !r; + } + cursor->prev= &(cursor->curr->link); + _lf_pin(pins, 2, cursor->curr); + } + else + { + /* + we found a deleted node - be nice, help the other thread + and remove this deleted node + */ + if (my_atomic_casptr((void **)cursor->prev, + (void **)&cursor->curr, cursor->next)) + _lf_alloc_free(pins, cursor->curr); + else + { + (void)LF_BACKOFF; + goto retry; + } + } + cursor->curr= cursor->next; + _lf_pin(pins, 1, cursor->curr); + } +} + +/* + DESCRIPTION + insert a 'node' in the list that starts from 'head' in the correct + position (as found by lfind) + + RETURN + 0 - inserted + not 0 - a pointer to a duplicate (not pinned and thus unusable) + + NOTE + it uses pins[0..2], on return all pins are removed. + if there're nodes with the same key value, a new node is added before them. +*/ +static LF_SLIST *linsert(LF_SLIST * volatile *head, CHARSET_INFO *cs, + LF_SLIST *node, LF_PINS *pins, uint flags) +{ + CURSOR cursor; + int res; + + for (;;) + { + if (lfind(head, cs, node->hashnr, node->key, node->keylen, + &cursor, pins) && + (flags & LF_HASH_UNIQUE)) + { + res= 0; /* duplicate found */ + break; + } + else + { + node->link= (intptr)cursor.curr; + DBUG_ASSERT(node->link != (intptr)node); /* no circular references */ + DBUG_ASSERT(cursor.prev != &node->link); /* no circular references */ + if (my_atomic_casptr((void **)cursor.prev, (void **)&cursor.curr, node)) + { + res= 1; /* inserted ok */ + break; + } + } + } + _lf_unpin(pins, 0); + _lf_unpin(pins, 1); + _lf_unpin(pins, 2); + /* + Note that cursor.curr is not pinned here and the pointer is unreliable, + the object may dissapear anytime. But if it points to a dummy node, the + pointer is safe, because dummy nodes are never freed - initialize_bucket() + uses this fact. + */ + return res ? 0 : cursor.curr; +} + +/* + DESCRIPTION + deletes a node as identified by hashnr/keey/keylen from the list + that starts from 'head' + + RETURN + 0 - ok + 1 - not found + + NOTE + it uses pins[0..2], on return all pins are removed. +*/ +static int ldelete(LF_SLIST * volatile *head, CHARSET_INFO *cs, uint32 hashnr, + const uchar *key, uint keylen, LF_PINS *pins) +{ + CURSOR cursor; + int res; + + for (;;) + { + if (!lfind(head, cs, hashnr, key, keylen, &cursor, pins)) + { + res= 1; /* not found */ + break; + } + else + { + /* mark the node deleted */ + if (my_atomic_casptr((void **)&(cursor.curr->link), + (void **)&cursor.next, + (void *)(((intptr)cursor.next) | 1))) + { + /* and remove it from the list */ + if (my_atomic_casptr((void **)cursor.prev, + (void **)&cursor.curr, cursor.next)) + _lf_alloc_free(pins, cursor.curr); + else + { + /* + somebody already "helped" us and removed the node ? + Let's check if we need to help that someone too! + (to ensure the number of "set DELETED flag" actions + is equal to the number of "remove from the list" actions) + */ + lfind(head, cs, hashnr, key, keylen, &cursor, pins); + } + res= 0; + break; + } + } + } + _lf_unpin(pins, 0); + _lf_unpin(pins, 1); + _lf_unpin(pins, 2); + return res; +} + +/* + DESCRIPTION + searches for a node as identified by hashnr/keey/keylen in the list + that starts from 'head' + + RETURN + 0 - not found + node - found + + NOTE + it uses pins[0..2], on return the pin[2] keeps the node found + all other pins are removed. +*/ +static LF_SLIST *lsearch(LF_SLIST * volatile *head, CHARSET_INFO *cs, + uint32 hashnr, const uchar *key, uint keylen, + LF_PINS *pins) +{ + CURSOR cursor; + int res= lfind(head, cs, hashnr, key, keylen, &cursor, pins); + if (res) + _lf_pin(pins, 2, cursor.curr); + _lf_unpin(pins, 0); + _lf_unpin(pins, 1); + return res ? cursor.curr : 0; +} + +static inline const uchar* hash_key(const LF_HASH *hash, + const uchar *record, size_t *length) +{ + if (hash->get_key) + return (*hash->get_key)(record, length, 0); + *length= hash->key_length; + return record + hash->key_offset; +} + +/* + Compute the hash key value from the raw key. + + @note, that the hash value is limited to 2^31, because we need one + bit to distinguish between normal and dummy nodes. +*/ +static inline uint calc_hash(LF_HASH *hash, const uchar *key, uint keylen) +{ + ulong nr1= 1, nr2= 4; + hash->charset->coll->hash_sort(hash->charset, (uchar*) key, keylen, + &nr1, &nr2); + return nr1 & INT_MAX32; +} + +#define MAX_LOAD 1.0 /* average number of elements in a bucket */ + +static int initialize_bucket(LF_HASH *, LF_SLIST * volatile*, uint, LF_PINS *); + +/* + Initializes lf_hash, the arguments are compatible with hash_init + + @note element_size sets both the size of allocated memory block for + lf_alloc and a size of memcpy'ed block size in lf_hash_insert. Typically + they are the same, indeed. But LF_HASH::element_size can be decreased + after lf_hash_init, and then lf_alloc will allocate larger block that + lf_hash_insert will copy over. It is desireable if part of the element + is expensive to initialize - for example if there is a mutex or + DYNAMIC_ARRAY. In this case they should be initialize in the + LF_ALLOCATOR::constructor, and lf_hash_insert should not overwrite them. + See wt_init() for example. +*/ +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) +{ + lf_alloc_init(&hash->alloc, sizeof(LF_SLIST)+element_size, + offsetof(LF_SLIST, key)); + lf_dynarray_init(&hash->array, sizeof(LF_SLIST *)); + hash->size= 1; + hash->count= 0; + hash->element_size= element_size; + hash->flags= flags; + hash->charset= charset ? charset : &my_charset_bin; + hash->key_offset= key_offset; + hash->key_length= key_length; + hash->get_key= get_key; + DBUG_ASSERT(get_key ? !key_offset && !key_length : key_length); +} + +void lf_hash_destroy(LF_HASH *hash) +{ + LF_SLIST *el, **head= (LF_SLIST **)_lf_dynarray_value(&hash->array, 0); + + if (unlikely(!head)) + return; + el= *head; + + while (el) + { + intptr next= el->link; + if (el->hashnr & 1) + lf_alloc_direct_free(&hash->alloc, el); /* normal node */ + else + my_free((void *)el, MYF(0)); /* dummy node */ + el= (LF_SLIST *)next; + } + lf_alloc_destroy(&hash->alloc); + lf_dynarray_destroy(&hash->array); +} + +/* + DESCRIPTION + inserts a new element to a hash. it will have a _copy_ of + data, not a pointer to it. + + RETURN + 0 - inserted + 1 - didn't (unique key conflict) + -1 - out of memory + + NOTE + see linsert() for pin usage notes +*/ +int lf_hash_insert(LF_HASH *hash, LF_PINS *pins, const void *data) +{ + int csize, bucket, hashnr; + LF_SLIST *node, * volatile *el; + + lf_rwlock_by_pins(pins); + node= (LF_SLIST *)_lf_alloc_new(pins); + if (unlikely(!node)) + return -1; + memcpy(node+1, data, hash->element_size); + node->key= hash_key(hash, (uchar *)(node+1), &node->keylen); + hashnr= calc_hash(hash, node->key, node->keylen); + bucket= hashnr % hash->size; + el= _lf_dynarray_lvalue(&hash->array, bucket); + if (unlikely(!el)) + return -1; + if (*el == NULL && unlikely(initialize_bucket(hash, el, bucket, pins))) + return -1; + node->hashnr= my_reverse_bits(hashnr) | 1; /* normal node */ + if (linsert(el, hash->charset, node, pins, hash->flags)) + { + _lf_alloc_free(pins, node); + lf_rwunlock_by_pins(pins); + return 1; + } + csize= hash->size; + if ((my_atomic_add32(&hash->count, 1)+1.0) / csize > MAX_LOAD) + my_atomic_cas32(&hash->size, &csize, csize*2); + lf_rwunlock_by_pins(pins); + return 0; +} + +/* + DESCRIPTION + deletes an element with the given key from the hash (if a hash is + not unique and there're many elements with this key - the "first" + matching element is deleted) + RETURN + 0 - deleted + 1 - didn't (not found) + -1 - out of memory + NOTE + see ldelete() for pin usage notes +*/ +int lf_hash_delete(LF_HASH *hash, LF_PINS *pins, const void *key, uint keylen) +{ + LF_SLIST * volatile *el; + uint bucket, hashnr= calc_hash(hash, (uchar *)key, keylen); + + bucket= hashnr % hash->size; + lf_rwlock_by_pins(pins); + el= _lf_dynarray_lvalue(&hash->array, bucket); + if (unlikely(!el)) + return -1; + /* + note that we still need to initialize_bucket here, + we cannot return "node not found", because an old bucket of that + node may've been split and the node was assigned to a new bucket + that was never accessed before and thus is not initialized. + */ + if (*el == NULL && unlikely(initialize_bucket(hash, el, bucket, pins))) + return -1; + if (ldelete(el, hash->charset, my_reverse_bits(hashnr) | 1, + (uchar *)key, keylen, pins)) + { + lf_rwunlock_by_pins(pins); + return 1; + } + my_atomic_add32(&hash->count, -1); + lf_rwunlock_by_pins(pins); + return 0; +} + +/* + RETURN + a pointer to an element with the given key (if a hash is not unique and + there're many elements with this key - the "first" matching element) + NULL if nothing is found + MY_ERRPTR if OOM + + NOTE + see lsearch() for pin usage notes +*/ +void *lf_hash_search(LF_HASH *hash, LF_PINS *pins, const void *key, uint keylen) +{ + LF_SLIST * volatile *el, *found; + uint bucket, hashnr= calc_hash(hash, (uchar *)key, keylen); + + bucket= hashnr % hash->size; + lf_rwlock_by_pins(pins); + el= _lf_dynarray_lvalue(&hash->array, bucket); + if (unlikely(!el)) + return MY_ERRPTR; + if (*el == NULL && unlikely(initialize_bucket(hash, el, bucket, pins))) + return MY_ERRPTR; + found= lsearch(el, hash->charset, my_reverse_bits(hashnr) | 1, + (uchar *)key, keylen, pins); + lf_rwunlock_by_pins(pins); + return found ? found+1 : 0; +} + +static const uchar *dummy_key= (uchar*)""; + +/* + RETURN + 0 - ok + -1 - out of memory +*/ +static int initialize_bucket(LF_HASH *hash, LF_SLIST * volatile *node, + uint bucket, LF_PINS *pins) +{ + uint parent= my_clear_highest_bit(bucket); + LF_SLIST *dummy= (LF_SLIST *)my_malloc(sizeof(LF_SLIST), MYF(MY_WME)); + LF_SLIST **tmp= 0, *cur; + LF_SLIST * volatile *el= _lf_dynarray_lvalue(&hash->array, parent); + if (unlikely(!el || !dummy)) + return -1; + if (*el == NULL && bucket && + unlikely(initialize_bucket(hash, el, parent, pins))) + return -1; + dummy->hashnr= my_reverse_bits(bucket) | 0; /* dummy node */ + dummy->key= dummy_key; + dummy->keylen= 0; + if ((cur= linsert(el, hash->charset, dummy, pins, LF_HASH_UNIQUE))) + { + my_free((void *)dummy, MYF(0)); + dummy= cur; + } + my_atomic_casptr((void **)node, (void **)&tmp, dummy); + /* + note that if the CAS above failed (after linsert() succeeded), + it would mean that some other thread has executed linsert() for + the same dummy node, its linsert() failed, it picked up our + dummy node (in "dummy= cur") and executed the same CAS as above. + Which means that even if CAS above failed we don't need to retry, + and we should not free(dummy) - there's no memory leak here + */ + return 0; +} diff --git a/mysys/my_thr_init.c b/mysys/my_thr_init.c index b2972faf0f8..ba59c483012 100644 --- a/mysys/my_thr_init.c +++ b/mysys/my_thr_init.c @@ -284,6 +284,9 @@ my_bool my_thread_init(void) pthread_cond_init(&tmp->suspend, NULL); tmp->init= 1; + tmp->stack_ends_here= (char*)&tmp + + STACK_DIRECTION * (long)my_thread_stack_size; + pthread_mutex_lock(&THR_LOCK_threads); tmp->id= ++thread_id; ++THR_thread_count; diff --git a/unittest/mysys/Makefile.am b/unittest/mysys/Makefile.am index 6e8058c4d9b..d83b2909048 100644 --- a/unittest/mysys/Makefile.am +++ b/unittest/mysys/Makefile.am @@ -23,7 +23,7 @@ LDADD = $(top_builddir)/unittest/mytap/libmytap.a \ $(top_builddir)/dbug/libdbug.a \ $(top_builddir)/strings/libmystrings.a -noinst_PROGRAMS = bitmap-t base64-t my_vsnprintf-t +noinst_PROGRAMS = bitmap-t base64-t lf-t my_vsnprintf-t if NEED_THREAD # my_atomic-t is used to check thread functions, so it is safe to diff --git a/unittest/mysys/lf-t.c b/unittest/mysys/lf-t.c new file mode 100644 index 00000000000..61b7ae08cf5 --- /dev/null +++ b/unittest/mysys/lf-t.c @@ -0,0 +1,178 @@ +/* Copyright (C) 2008-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 */ + +/** + @file + + Unit tests for lock-free algorithms of mysys +*/ + +#include "thr_template.c" + +#include + +int32 inserts= 0, N; +LF_ALLOCATOR lf_allocator; +LF_HASH lf_hash; + +/* + pin allocator - alloc and release an element in a loop +*/ +pthread_handler_t test_lf_pinbox(void *arg) +{ + int m= *(int *)arg; + int32 x= 0; + LF_PINS *pins; + + my_thread_init(); + + pins= lf_pinbox_get_pins(&lf_allocator.pinbox); + + for (x= ((int)(intptr)(&m)); m ; m--) + { + lf_pinbox_put_pins(pins); + pins= lf_pinbox_get_pins(&lf_allocator.pinbox); + } + lf_pinbox_put_pins(pins); + pthread_mutex_lock(&mutex); + if (!--running_threads) pthread_cond_signal(&cond); + pthread_mutex_unlock(&mutex); + my_thread_end(); + return 0; +} + +/* + thread local data area, allocated using lf_alloc. + union is required to enforce the minimum required element size (sizeof(ptr)) +*/ +typedef union { + int32 data; + void *not_used; +} TLA; + +pthread_handler_t test_lf_alloc(void *arg) +{ + int m= (*(int *)arg)/2; + int32 x,y= 0; + LF_PINS *pins; + + my_thread_init(); + + pins= lf_alloc_get_pins(&lf_allocator); + + for (x= ((int)(intptr)(&m)); m ; m--) + { + TLA *node1, *node2; + x= (x*m+0x87654321) & INT_MAX32; + node1= (TLA *)lf_alloc_new(pins); + node1->data= x; + y+= node1->data; + node1->data= 0; + node2= (TLA *)lf_alloc_new(pins); + node2->data= x; + y-= node2->data; + node2->data= 0; + lf_alloc_free(pins, node1); + lf_alloc_free(pins, node2); + } + lf_alloc_put_pins(pins); + pthread_mutex_lock(&mutex); + bad+= y; + + if (--N == 0) + { + diag("%d mallocs, %d pins in stack", + lf_allocator.mallocs, lf_allocator.pinbox.pins_in_array); +#ifdef MY_LF_EXTRA_DEBUG + bad|= lf_allocator.mallocs - lf_alloc_pool_count(&lf_allocator); +#endif + } + if (!--running_threads) pthread_cond_signal(&cond); + pthread_mutex_unlock(&mutex); + my_thread_end(); + return 0; +} + +#define N_TLH 1000 +pthread_handler_t test_lf_hash(void *arg) +{ + int m= (*(int *)arg)/(2*N_TLH); + int32 x,y,z,sum= 0, ins= 0; + LF_PINS *pins; + + my_thread_init(); + + pins= lf_hash_get_pins(&lf_hash); + + for (x= ((int)(intptr)(&m)); m ; m--) + { + int i; + y= x; + for (i= 0; i < N_TLH; i++) + { + x= (x*(m+i)+0x87654321) & INT_MAX32; + z= (x<0) ? -x : x; + if (lf_hash_insert(&lf_hash, pins, &z)) + { + sum+= z; + ins++; + } + } + for (i= 0; i < N_TLH; i++) + { + y= (y*(m+i)+0x87654321) & INT_MAX32; + z= (y<0) ? -y : y; + if (lf_hash_delete(&lf_hash, pins, (uchar *)&z, sizeof(z))) + sum-= z; + } + } + lf_hash_put_pins(pins); + pthread_mutex_lock(&mutex); + bad+= sum; + inserts+= ins; + + if (--N == 0) + { + diag("%d mallocs, %d pins in stack, %d hash size, %d inserts", + lf_hash.alloc.mallocs, lf_hash.alloc.pinbox.pins_in_array, + lf_hash.size, inserts); + bad|= lf_hash.count; + } + if (!--running_threads) pthread_cond_signal(&cond); + pthread_mutex_unlock(&mutex); + my_thread_end(); + return 0; +} + + +void do_tests() +{ + plan(4); + + lf_alloc_init(&lf_allocator, sizeof(TLA), offsetof(TLA, not_used)); + lf_hash_init(&lf_hash, sizeof(int), LF_HASH_UNIQUE, 0, sizeof(int), 0, + &my_charset_bin); + + bad= my_atomic_initialize(); + ok(!bad, "my_atomic_initialize() returned %d", bad); + + test_concurrently("lf_pinbox", test_lf_pinbox, N= THREADS, CYCLES); + test_concurrently("lf_alloc", test_lf_alloc, N= THREADS, CYCLES); + test_concurrently("lf_hash", test_lf_hash, N= THREADS, CYCLES/10); + + lf_hash_destroy(&lf_hash); + lf_alloc_destroy(&lf_allocator); +} + From 1848b862e14d30ca4bd9ce5b7ff5352969d604f2 Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Tue, 17 Nov 2009 21:29:26 -0700 Subject: [PATCH 05/23] Port the unit test framework to windows Backport from 6.0.14 to 5.6.0 Original code from Guilhem Bichot --- CMakeLists.txt | 11 ++++++- mysys/CMakeLists.txt | 4 ++- unittest/examples/CMakeLists.txt | 38 +++++++++++++++++++++++++ unittest/examples/core-t.c | 2 +- unittest/examples/no_plan-t.c | 2 +- unittest/examples/skip_all-t.c | 2 +- unittest/examples/todo-t.c | 2 +- unittest/mytap/CMakeLists.txt | 21 ++++++++++++++ unittest/mytap/Makefile.am | 7 ++--- unittest/mytap/tap.c | 29 ++++++++++++++++--- unittest/mytap/tap.h | 49 +++++++++++++++++++++++++++++--- unittest/unit.pl | 18 +++++++++--- 12 files changed, 163 insertions(+), 22 deletions(-) create mode 100644 unittest/examples/CMakeLists.txt create mode 100644 unittest/mytap/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 6e53ff30159..7a5ee9223bc 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (C) 2006 MySQL AB +# 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 @@ -284,10 +284,16 @@ CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/sql/sql_builtin.cc.in SET (ENGINE_BUILD_TYPE "STATIC") FOREACH(DIR ${STATIC_ENGINE_DIRECTORIES}) ADD_SUBDIRECTORY(${DIR}) + IF(EXISTS ${DIR}/unittest) + ADD_SUBDIRECTORY(${DIR}/unittest) + ENDIF(EXISTS ${DIR}/unittest) ENDFOREACH(DIR ${STATIC_ENGINE_DIRECTORIES}) SET (ENGINE_BUILD_TYPE "DYNAMIC") FOREACH(DIR ${DYNAMIC_ENGINE_DIRECTORIES}) + IF(EXISTS ${DIR}/unittest) + ADD_SUBDIRECTORY(${DIR}/unittest) + ENDIF(EXISTS ${DIR}/unittest) ADD_SUBDIRECTORY(${DIR}) ENDFOREACH(DIR ${DYNAMIC_ENGINE_DIRECTORIES}) @@ -313,6 +319,9 @@ ADD_SUBDIRECTORY(sql) ADD_SUBDIRECTORY(libmysql) ADD_SUBDIRECTORY(libservices) ADD_SUBDIRECTORY(tests) +ADD_SUBDIRECTORY(unittest/mytap) +ADD_SUBDIRECTORY(unittest/examples) +ADD_SUBDIRECTORY(unittest/mysys) IF(WITH_EMBEDDED_SERVER) ADD_SUBDIRECTORY(libmysqld) ADD_SUBDIRECTORY(libmysqld/examples) diff --git a/mysys/CMakeLists.txt b/mysys/CMakeLists.txt index 21b04e7c968..757e37aa0a9 100755 --- a/mysys/CMakeLists.txt +++ b/mysys/CMakeLists.txt @@ -39,7 +39,9 @@ SET(MYSYS_SOURCES array.c charset-def.c charset.c checksum.c default.c default_ my_static.c my_symlink.c my_symlink2.c my_sync.c my_thr_init.c my_wincond.c my_winerr.c my_winfile.c my_windac.c my_winthread.c my_write.c ptr_cmp.c queues.c stacktrace.c rijndael.c safemalloc.c sha1.c string.c thr_alarm.c thr_lock.c thr_mutex.c - thr_rwlock.c tree.c typelib.c my_vle.c base64.c my_memmem.c my_getpagesize.c) + thr_rwlock.c tree.c typelib.c my_vle.c base64.c my_memmem.c my_getpagesize.c + lf_alloc-pin.c lf_dynarray.c lf_hash.c + my_atomic.c my_getncpus.c) IF(NOT SOURCE_SUBLIBS) ADD_LIBRARY(mysys ${MYSYS_SOURCES}) diff --git a/unittest/examples/CMakeLists.txt b/unittest/examples/CMakeLists.txt new file mode 100644 index 00000000000..a5aa5a93985 --- /dev/null +++ b/unittest/examples/CMakeLists.txt @@ -0,0 +1,38 @@ +# 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + +INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/zlib + ${CMAKE_SOURCE_DIR}/sql + ${CMAKE_SOURCE_DIR}/regex + ${CMAKE_SOURCE_DIR}/extra/yassl/include + ${CMAKE_SOURCE_DIR}/unittest/mytap) +ADD_EXECUTABLE(simple-t simple-t.c) +TARGET_LINK_LIBRARIES(simple-t mytap) + +ADD_EXECUTABLE(skip-t skip-t.c) +TARGET_LINK_LIBRARIES(skip-t mytap) + +ADD_EXECUTABLE(todo-t todo-t.c) +TARGET_LINK_LIBRARIES(todo-t mytap) + +ADD_EXECUTABLE(skip_all-t skip_all-t.c) +TARGET_LINK_LIBRARIES(skip_all-t mytap) + +ADD_EXECUTABLE(no_plan-t no_plan-t.c) +TARGET_LINK_LIBRARIES(no_plan-t mytap) + +ADD_EXECUTABLE(core-t core-t.c) +TARGET_LINK_LIBRARIES(core-t mytap) diff --git a/unittest/examples/core-t.c b/unittest/examples/core-t.c index cafe2df9954..a9b798d3064 100644 --- a/unittest/examples/core-t.c +++ b/unittest/examples/core-t.c @@ -13,7 +13,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "my_config.h" +#include #include #include diff --git a/unittest/examples/no_plan-t.c b/unittest/examples/no_plan-t.c index 56aabd6d752..06378e81218 100644 --- a/unittest/examples/no_plan-t.c +++ b/unittest/examples/no_plan-t.c @@ -13,7 +13,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "my_config.h" +#include #include #include diff --git a/unittest/examples/skip_all-t.c b/unittest/examples/skip_all-t.c index a4c8648fbe4..11c1ef13276 100644 --- a/unittest/examples/skip_all-t.c +++ b/unittest/examples/skip_all-t.c @@ -13,7 +13,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "my_config.h" +#include #include #include diff --git a/unittest/examples/todo-t.c b/unittest/examples/todo-t.c index 2de409447ba..027d6d6b65e 100644 --- a/unittest/examples/todo-t.c +++ b/unittest/examples/todo-t.c @@ -13,7 +13,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "my_config.h" +#include #include #include diff --git a/unittest/mytap/CMakeLists.txt b/unittest/mytap/CMakeLists.txt new file mode 100644 index 00000000000..9875f46697d --- /dev/null +++ b/unittest/mytap/CMakeLists.txt @@ -0,0 +1,21 @@ +# 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + +INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/zlib + ${CMAKE_SOURCE_DIR}/sql + ${CMAKE_SOURCE_DIR}/regex + ${CMAKE_SOURCE_DIR}/extra/yassl/include) +ADD_LIBRARY(mytap tap.c) diff --git a/unittest/mytap/Makefile.am b/unittest/mytap/Makefile.am index c02bcd3b49d..d36dc25d0b5 100644 --- a/unittest/mytap/Makefile.am +++ b/unittest/mytap/Makefile.am @@ -13,14 +13,13 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -AM_CPPFLAGS = -I$(top_builddir)/include -I$(top_srcdir)/include -I$(srcdir) +AM_CPPFLAGS = -I$(top_srcdir)/include noinst_LIBRARIES = libmytap.a noinst_HEADERS = tap.h libmytap_a_SOURCES = tap.c -SUBDIRS = . t +EXTRA_DIST = CMakeLists.txt -# Don't update the files from bitkeeper -%::SCCS/s.% +SUBDIRS = . t diff --git a/unittest/mytap/tap.c b/unittest/mytap/tap.c index 4e053e3e745..5cdbfeb428c 100644 --- a/unittest/mytap/tap.c +++ b/unittest/mytap/tap.c @@ -19,7 +19,7 @@ #include "tap.h" -#include "my_config.h" +#include "my_global.h" #include #include @@ -27,6 +27,16 @@ #include #include +/* + Visual Studio 2003 does not know vsnprintf but knows _vsnprintf. + We don't put this #define in config-win.h because we prefer + my_vsnprintf everywhere instead, except when linking with libmysys + is not desirable - the case here. +*/ +#if defined(_MSC_VER) && ( _MSC_VER == 1310 ) +#define vsnprintf _vsnprintf +#endif + /** @defgroup MyTAP_Internal MyTAP Internals @@ -150,8 +160,10 @@ static signal_entry install_signal[]= { { SIGILL, handle_core_signal }, { SIGABRT, handle_core_signal }, { SIGFPE, handle_core_signal }, - { SIGSEGV, handle_core_signal }, - { SIGBUS, handle_core_signal } + { SIGSEGV, handle_core_signal } +#ifdef SIGBUS + , { SIGBUS, handle_core_signal } +#endif #ifdef SIGXCPU , { SIGXCPU, handle_core_signal } #endif @@ -166,13 +178,22 @@ static signal_entry install_signal[]= { #endif }; +int skip_big_tests= 1; + void plan(int const count) { + char *config= getenv("MYTAP_CONFIG"); + size_t i; + + if (config) + skip_big_tests= strcmp(config, "big"); + + setvbuf(tapout, 0, _IONBF, 0); /* provide output at once */ /* Install signal handler */ - size_t i; + for (i= 0; i < sizeof(install_signal)/sizeof(*install_signal); ++i) signal(install_signal[i].signo, install_signal[i].handler); diff --git a/unittest/mytap/tap.h b/unittest/mytap/tap.h index 31ec47d1ef2..d8f617c88fb 100644 --- a/unittest/mytap/tap.h +++ b/unittest/mytap/tap.h @@ -61,6 +61,24 @@ typedef struct TEST_DATA { extern "C" { #endif +/** + Defines whether "big" tests should be skipped. + + This variable is set by plan() function unless MYTAP_CONFIG environment + variable is set to the string "big". It is supposed to be used as + + @code + if (skip_big_tests) { + skip(1, "Big test skipped"); + } else { + ok(life_universe_and_everything() == 42, "The answer is CORRECT"); + } + @endcode + + @see SKIP_BIG_TESTS +*/ +extern int skip_big_tests; + /** @defgroup MyTAP_API MyTAP API @@ -81,10 +99,15 @@ extern "C" { that generate a core, so if you want to override these signals, do it after you have called the plan() function. - @param count The planned number of tests to run. + It will also set skip_big_tests variable if MYTAP_CONFIG environment + variable is defined. + + @see skip_big_tests + + @param count The planned number of tests to run. */ -void plan(int count); +void plan(int const count); /** @@ -103,7 +126,7 @@ void plan(int count); which case nothing is printed. */ -void ok(int pass, char const *fmt, ...) +void ok(int const pass, char const *fmt, ...) __attribute__((format(printf,2,3))); @@ -135,7 +158,7 @@ void ok(int pass, char const *fmt, ...) @param reason A reason for skipping the tests */ -void skip(int how_many, char const *reason, ...) +void skip(int how_many, char const *const reason, ...) __attribute__((format(printf,2,3))); @@ -160,6 +183,24 @@ void skip(int how_many, char const *reason, ...) if (SKIP_IF_TRUE) skip((COUNT),(REASON)); else +/** + Helper macro to skip a group of "big" tests. It is used in the following + manner: + + @code + SKIP_BIG_TESTS(1) + { + ok(life_universe_and_everything() == 42, "The answer is CORRECT"); + } + @endcode + + @see skip_big_tests + */ + +#define SKIP_BIG_TESTS(COUNT) \ + if (skip_big_tests) skip((COUNT), "big test"); else + + /** Print a diagnostics message. diff --git a/unittest/unit.pl b/unittest/unit.pl index 9d328985012..a1aab376fdf 100644 --- a/unittest/unit.pl +++ b/unittest/unit.pl @@ -14,8 +14,9 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -use Test::Harness qw(&runtests $verbose); +use Test::Harness; use File::Find; +use Getopt::Long; use strict; @@ -31,10 +32,19 @@ unit - Run unit tests in directory =head1 SYNOPSIS - unit run + unit [--[no]big] [--[no]verbose] run [tests to run] =cut +my $big= $ENV{'MYTAP_CONFIG'} eq 'big'; + +my $result = GetOptions ( + "big!" => \$big, + "verbose!" => \$Test::Harness::verbose, +); + +$ENV{'MYTAP_CONFIG'} = $big ? 'big' : ''; + my $cmd = shift; if (defined $cmd && exists $dispatch{$cmd}) { @@ -56,7 +66,7 @@ sub _find_test_files (@) { my @files; find sub { $File::Find::prune = 1 if /^SCCS$/; - push(@files, $File::Find::name) if -x _ && /-t\z/; + push(@files, $File::Find::name) if -x _ && (/-t\z/ || /-t\.exe\z/); }, @dirs; return @files; } @@ -92,7 +102,7 @@ sub run_cmd (@) { if (@files > 0) { # Removing the first './' from the file names foreach (@files) { s!^\./!! } - $ENV{'HARNESS_PERL_SWITCHES'} .= q" -e 'exec @ARGV'"; + $ENV{'HARNESS_PERL_SWITCHES'} .= ' -e "exec @ARGV"'; runtests @files; } } From 2564b5046d7b65afb03e3b719e38c6e76f966f6e Mon Sep 17 00:00:00 2001 From: Magne Mahre Date: Fri, 20 Nov 2009 14:10:20 +0100 Subject: [PATCH 06/23] Enable test cases for Bug#6063 and Bug#7088. --- mysql-test/r/sp.result | 34 ++++++++++++++++++++++++++++++++++ mysql-test/t/sp.test | 21 ++++++++++++++------- 2 files changed, 48 insertions(+), 7 deletions(-) diff --git a/mysql-test/r/sp.result b/mysql-test/r/sp.result index 26ba2af8f68..a73abf787d8 100644 --- a/mysql-test/r/sp.result +++ b/mysql-test/r/sp.result @@ -3321,9 +3321,43 @@ call bug11529()| call bug11529()| delete from t1| drop procedure bug11529| +set character set utf8| drop procedure if exists bug6063| drop procedure if exists bug7088_1| drop procedure if exists bug7088_2| +create procedure bug6063() +begin +lâbel: begin end; +label: begin end; +label1: begin end; +end| +create procedure bug7088_1() +label1: begin end label1| +create procedure bug7088_2() +läbel1: begin end| +call bug6063()| +call bug7088_1()| +call bug7088_2()| +set character set default| +show create procedure bug6063| +Procedure sql_mode Create Procedure character_set_client collation_connection Database Collation +bug6063 CREATE DEFINER=`root`@`localhost` PROCEDURE `bug6063`() +begin +lâbel: begin end; +label: begin end; +label1: begin end; +end utf8 latin1_swedish_ci latin1_swedish_ci +show create procedure bug7088_1| +Procedure sql_mode Create Procedure character_set_client collation_connection Database Collation +bug7088_1 CREATE DEFINER=`root`@`localhost` PROCEDURE `bug7088_1`() +label1: begin end label1 utf8 latin1_swedish_ci latin1_swedish_ci +show create procedure bug7088_2| +Procedure sql_mode Create Procedure character_set_client collation_connection Database Collation +bug7088_2 CREATE DEFINER=`root`@`localhost` PROCEDURE `bug7088_2`() +läbel1: begin end utf8 latin1_swedish_ci latin1_swedish_ci +drop procedure bug6063| +drop procedure bug7088_1| +drop procedure bug7088_2| drop procedure if exists bug9565_sub| drop procedure if exists bug9565| create procedure bug9565_sub() diff --git a/mysql-test/t/sp.test b/mysql-test/t/sp.test index a9825d13f66..b0342491a34 100644 --- a/mysql-test/t/sp.test +++ b/mysql-test/t/sp.test @@ -4061,34 +4061,41 @@ drop procedure bug11529| # BUG#6063: Stored procedure labels are subject to restrictions (partial) # BUG#7088: Stored procedures: labels won't work if character set is utf8 # + +set character set utf8| + --disable_warnings drop procedure if exists bug6063| drop procedure if exists bug7088_1| drop procedure if exists bug7088_2| --enable_warnings ---disable_parsing # temporarily disabled until Bar fixes BUG#11986 create procedure bug6063() - lâbel: begin end| -call bug6063()| -# QQ Known bug: this will not show the label correctly. -show create procedure bug6063| +begin + lâbel: begin end; + label: begin end; + label1: begin end; +end| -set character set utf8| create procedure bug7088_1() label1: begin end label1| + create procedure bug7088_2() läbel1: begin end| + +call bug6063()| call bug7088_1()| call bug7088_2()| + set character set default| + +show create procedure bug6063| show create procedure bug7088_1| show create procedure bug7088_2| drop procedure bug6063| drop procedure bug7088_1| drop procedure bug7088_2| ---enable_parsing # # BUG#9565: "Wrong locking in stored procedure if a sub-sequent procedure From 948ee7e5d9aa45970a3ba7208860982d093f540f Mon Sep 17 00:00:00 2001 From: Konstantin Osipov Date: Fri, 20 Nov 2009 22:15:50 +0300 Subject: [PATCH 07/23] Backport of: revno: 2476.784.2 committer: davi@moksha.local timestamp: Thu 2007-09-27 16:56:27 -0300 message: Bug#28870 check that table locks are released/reset The problem is that some mysql_lock_tables error paths are not resetting the tables lock type back to TL_UNLOCK. If the lock types are not reset properly, a table might be returned to the table cache with wrong lock_type. The proposed fix is to ensure that the tables lock type is always properly reset when mysql_lock_tables fails. This is a incompatible change with respect to the process state information. --- sql/lock.cc | 142 +++++++++++++++++++++++++---------------------- sql/sql_class.cc | 2 +- sql/sql_class.h | 2 +- sql/sql_show.cc | 2 - 4 files changed, 77 insertions(+), 71 deletions(-) diff --git a/sql/lock.cc b/sql/lock.cc index c0cda1dbf03..112d3dc4a2b 100644 --- a/sql/lock.cc +++ b/sql/lock.cc @@ -90,7 +90,6 @@ extern HASH open_cache; static MYSQL_LOCK *get_lock_data(THD *thd, TABLE **table,uint count, uint flags, TABLE **write_locked); -static void reset_lock_data(MYSQL_LOCK *sql_lock); static int lock_external(THD *thd, TABLE **table,uint count); static int unlock_external(THD *thd, TABLE **table,uint count); static void print_lock_error(int error, const char *); @@ -194,6 +193,60 @@ int mysql_lock_tables_check(THD *thd, TABLE **tables, uint count, uint flags) DBUG_RETURN(0); } + +/** + Reset lock type in lock data and free. + + @param mysql_lock Lock structures to reset. + + @note After a locking error we want to quit the locking of the table(s). + The test case in the bug report for Bug #18544 has the following + cases: 1. Locking error in lock_external() due to InnoDB timeout. + 2. Locking error in get_lock_data() due to missing write permission. + 3. Locking error in wait_if_global_read_lock() due to lock conflict. + + @note In all these cases we have already set the lock type into the lock + data of the open table(s). If the table(s) are in the open table + cache, they could be reused with the non-zero lock type set. This + could lead to ignoring a different lock type with the next lock. + + @note Clear the lock type of all lock data. This ensures that the next + lock request will set its lock type properly. +*/ + + +static void reset_lock_data(MYSQL_LOCK *sql_lock) +{ + THR_LOCK_DATA **ldata, **ldata_end; + DBUG_ENTER("reset_lock_data"); + + /* Clear the lock type of all lock data to avoid reusage. */ + for (ldata= sql_lock->locks, ldata_end= ldata + sql_lock->lock_count; + ldata < ldata_end; + ldata++) + { + /* Reset lock type. */ + (*ldata)->type= TL_UNLOCK; + } + DBUG_VOID_RETURN; +} + + +/** + Reset lock type in lock data and free. + + @param mysql_lock Lock structures to reset. + +*/ + +static void reset_lock_data_and_free(MYSQL_LOCK **mysql_lock) +{ + reset_lock_data(*mysql_lock); + my_free(*mysql_lock, MYF(0)); + *mysql_lock= 0; +} + + MYSQL_LOCK *mysql_lock_tables(THD *thd, TABLE **tables, uint count, uint flags, bool *need_reopen) { @@ -224,16 +277,13 @@ MYSQL_LOCK *mysql_lock_tables(THD *thd, TABLE **tables, uint count, if (wait_if_global_read_lock(thd, 1, 1)) { /* Clear the lock type of all lock data to avoid reusage. */ - reset_lock_data(sql_lock); - my_free((uchar*) sql_lock,MYF(0)); - sql_lock=0; + reset_lock_data_and_free(&sql_lock); break; } if (thd->version != refresh_version) { /* Clear the lock type of all lock data to avoid reusage. */ - reset_lock_data(sql_lock); - my_free((uchar*) sql_lock,MYF(0)); + reset_lock_data_and_free(&sql_lock); goto retry; } } @@ -248,9 +298,7 @@ MYSQL_LOCK *mysql_lock_tables(THD *thd, TABLE **tables, uint count, Someone has issued SET GLOBAL READ_ONLY=1 and we want a write lock. We do not wait for READ_ONLY=0, and fail. */ - reset_lock_data(sql_lock); - my_free((uchar*) sql_lock, MYF(0)); - sql_lock=0; + reset_lock_data_and_free(&sql_lock); my_error(ER_OPTION_PREVENTS_STATEMENT, MYF(0), "--read-only"); break; } @@ -261,14 +309,11 @@ MYSQL_LOCK *mysql_lock_tables(THD *thd, TABLE **tables, uint count, sql_lock->table_count)) { /* Clear the lock type of all lock data to avoid reusage. */ - reset_lock_data(sql_lock); - my_free((uchar*) sql_lock,MYF(0)); - sql_lock=0; + reset_lock_data_and_free(&sql_lock); break; } - thd_proc_info(thd, "Table lock"); DBUG_PRINT("info", ("thd->proc_info %s", thd->proc_info)); - thd->locked=1; + thd_proc_info(thd, "Locked"); /* Copy the lock data array. thr_multi_lock() reorders its contens. */ memcpy(sql_lock->locks + sql_lock->lock_count, sql_lock->locks, sql_lock->lock_count * sizeof(*sql_lock->locks)); @@ -281,22 +326,15 @@ MYSQL_LOCK *mysql_lock_tables(THD *thd, TABLE **tables, uint count, { if (sql_lock->table_count) VOID(unlock_external(thd, sql_lock->table, sql_lock->table_count)); + reset_lock_data_and_free(&sql_lock); my_error(rc, MYF(0)); - my_free((uchar*) sql_lock,MYF(0)); - sql_lock= 0; break; } else if (rc == 1) /* aborted */ { - /* - reset_lock_data is required here. If thr_multi_lock fails it - resets lock type for tables, which were locked before (and - including) one that caused error. Lock type for other tables - preserved. - */ - reset_lock_data(sql_lock); thd->some_tables_deleted=1; // Try again sql_lock->lock_count= 0; // Locks are already freed + // Fall through: unlock, reset lock data, free and retry } else if (!thd->some_tables_deleted || (flags & MYSQL_LOCK_IGNORE_FLUSH)) { @@ -304,23 +342,30 @@ MYSQL_LOCK *mysql_lock_tables(THD *thd, TABLE **tables, uint count, Thread was killed or lock aborted. Let upper level close all used tables and retry or give error. */ - thd->locked=0; break; } else if (!thd->open_tables) { // Only using temporary tables, no need to unlock thd->some_tables_deleted=0; - thd->locked=0; break; } thd_proc_info(thd, 0); - /* some table was altered or deleted. reopen tables marked deleted */ - mysql_unlock_tables(thd,sql_lock); - thd->locked=0; + /* going to retry, unlock all tables */ + if (sql_lock->lock_count) + thr_multi_unlock(sql_lock->locks, sql_lock->lock_count); + + if (sql_lock->table_count) + VOID(unlock_external(thd, sql_lock->table, sql_lock->table_count)); + + /* + If thr_multi_lock fails it resets lock type for tables, which + were locked before (and including) one that caused error. Lock + type for other tables preserved. + */ + reset_lock_data_and_free(&sql_lock); retry: - sql_lock=0; if (flags & MYSQL_LOCK_NOTIFY_IF_NEED_REOPEN) { *need_reopen= TRUE; @@ -863,8 +908,7 @@ static MYSQL_LOCK *get_lock_data(THD *thd, TABLE **table_ptr, uint count, my_error(ER_OPEN_AS_READONLY,MYF(0),table->alias); /* Clear the lock type of the lock data that are stored already. */ sql_lock->lock_count= (uint) (locks - sql_lock->locks); - reset_lock_data(sql_lock); - my_free((uchar*) sql_lock,MYF(0)); + reset_lock_data_and_free(&sql_lock); DBUG_RETURN(0); } } @@ -905,42 +949,6 @@ static MYSQL_LOCK *get_lock_data(THD *thd, TABLE **table_ptr, uint count, } -/** - Reset lock type in lock data. - - After a locking error we want to quit the locking of the table(s). - The test case in the bug report for Bug #18544 has the following - cases: - -# Locking error in lock_external() due to InnoDB timeout. - -# Locking error in get_lock_data() due to missing write permission. - -# Locking error in wait_if_global_read_lock() due to lock conflict. - - In all these cases we have already set the lock type into the lock - data of the open table(s). If the table(s) are in the open table - cache, they could be reused with the non-zero lock type set. This - could lead to ignoring a different lock type with the next lock. - - Clear the lock type of all lock data. This ensures that the next - lock request will set its lock type properly. - - @param sql_lock The MySQL lock. -*/ - -static void reset_lock_data(MYSQL_LOCK *sql_lock) -{ - THR_LOCK_DATA **ldata; - THR_LOCK_DATA **ldata_end; - - for (ldata= sql_lock->locks, ldata_end= ldata + sql_lock->lock_count; - ldata < ldata_end; - ldata++) - { - /* Reset lock type. */ - (*ldata)->type= TL_UNLOCK; - } -} - - /***************************************************************************** Lock table based on the name. This is used when we need total access to a closed, not open table diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 60aed4ce53b..441a3037317 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -483,7 +483,7 @@ THD::THD() catalog= (char*)"std"; // the only catalog we have for now main_security_ctx.init(); security_ctx= &main_security_ctx; - locked=some_tables_deleted=no_errors=password= 0; + some_tables_deleted=no_errors=password= 0; query_start_used= 0; count_cuted_fields= CHECK_FIELD_IGNORE; killed= NOT_KILLED; diff --git a/sql/sql_class.h b/sql/sql_class.h index 2dd45997ee1..a968258dd1b 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -1696,7 +1696,7 @@ public: bool slave_thread, one_shot_set; /* tells if current statement should binlog row-based(1) or stmt-based(0) */ bool current_stmt_binlog_row_based; - bool locked, some_tables_deleted; + bool some_tables_deleted; bool last_cuted_field; bool no_errors, password; /** diff --git a/sql/sql_show.cc b/sql/sql_show.cc index 3af0df73079..7b7f5741d5a 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -1707,8 +1707,6 @@ template class I_List; static const char *thread_state_info(THD *tmp) { - if (tmp->locked) - return "Locked"; #ifndef EMBEDDED_LIBRARY if (tmp->net.reading_or_writing) { From 1ee8a58882daa8f5ba93bbc6032f0201ed4004d9 Mon Sep 17 00:00:00 2001 From: Konstantin Osipov Date: Fri, 20 Nov 2009 22:51:12 +0300 Subject: [PATCH 08/23] Backport of: ------------------------------------------------------------ revno: 2476.784.3 committer: davi@moksha.local timestamp: Tue 2007-10-02 21:27:31 -0300 message: Bug#25858 Some DROP TABLE under LOCK TABLES can cause deadlocks When a client (connection) holds a lock on a table and attempts to drop (obtain a exclusive lock) on a second table that is already held by a second client and the second client then attempts to drop the table that is held by the first client, leads to a circular wait deadlock. This scenario is very similar to trying to drop (or rename) a table while holding read locks and are correctly forbidden. The solution is to allow a drop table operation to continue only if the table being dropped is write (exclusively) locked, or if the table is temporary, or if the client is not holding any locks. Using this scheme prevents the creation of a circular chain in which each client is waiting for one table that the next client in the chain is holding. This is incompatible change, as can be seen by number of tests cases that needed to be fixed, but is consistent with respect to behavior of the different scenarios in which the circular wait might happen. --- mysql-test/r/drop.result | 20 +++++++++++++ mysql-test/r/group_by.result | 3 +- mysql-test/r/insert_notembedded.result | 1 + mysql-test/r/lock.result | 6 ++++ mysql-test/r/lock_multi.result | 1 + mysql-test/r/myisam.result | 2 ++ mysql-test/r/query_cache_notembedded.result | 1 + mysql-test/r/view.result | 3 ++ mysql-test/t/drop.test | 33 +++++++++++++++++++++ mysql-test/t/group_by.test | 3 +- mysql-test/t/insert_notembedded.test | 1 + mysql-test/t/lock.test | 6 ++++ mysql-test/t/lock_multi.test | 1 + mysql-test/t/myisam.test | 2 ++ mysql-test/t/query_cache_notembedded.test | 1 + mysql-test/t/view.test | 3 ++ sql/lock.cc | 19 ++++++++++++ 17 files changed, 104 insertions(+), 2 deletions(-) diff --git a/mysql-test/r/drop.result b/mysql-test/r/drop.result index 42739b10d50..54bd05e526f 100644 --- a/mysql-test/r/drop.result +++ b/mysql-test/r/drop.result @@ -86,6 +86,26 @@ select 1; 1 1 unlock tables; +drop table if exists t1,t2; +create table t1 (a int); +create table t2 (a int); +lock table t1 read; +drop table t2; +ERROR HY000: Table 't2' was not locked with LOCK TABLES +drop table t1; +ERROR HY000: Table 't1' was locked with a READ lock and can't be updated +unlock tables; +drop table t1,t2; +create table t1 (i int); +create table t2 (i int); +lock tables t1 read; +lock tables t2 read; +drop table t1; +ERROR HY000: Table 't1' was not locked with LOCK TABLES +drop table t1,t2; +ERROR HY000: Table 't1' was locked with a READ lock and can't be updated +unlock tables; +drop table t1,t2; End of 5.0 tests create database mysql_test; create table mysql_test.t1(f1 int); diff --git a/mysql-test/r/group_by.result b/mysql-test/r/group_by.result index 742d4b90807..e6063047ba4 100644 --- a/mysql-test/r/group_by.result +++ b/mysql-test/r/group_by.result @@ -107,8 +107,9 @@ SELECT cid, CONCAT(firstname, ' ', surname), COUNT(call_id) FROM t1 LEFT JOIN t2 cid CONCAT(firstname, ' ', surname) COUNT(call_id) SELECT HIGH_PRIORITY cid, CONCAT(firstname, ' ', surname), COUNT(call_id) FROM t1 LEFT JOIN t2 ON cid=contact_id WHERE firstname like '%foo%' GROUP BY cid ORDER BY surname, firstname; cid CONCAT(firstname, ' ', surname) COUNT(call_id) -drop table t1,t2; +drop table t2; unlock tables; +drop table t1; CREATE TABLE t1 ( bug_id mediumint(9) NOT NULL auto_increment, groupset bigint(20) DEFAULT '0' NOT NULL, diff --git a/mysql-test/r/insert_notembedded.result b/mysql-test/r/insert_notembedded.result index ac69cb65972..2315d695abe 100644 --- a/mysql-test/r/insert_notembedded.result +++ b/mysql-test/r/insert_notembedded.result @@ -122,5 +122,6 @@ a b connection: default select * from t1; a b +unlock tables; drop table t1; set low_priority_updates=default; diff --git a/mysql-test/r/lock.result b/mysql-test/r/lock.result index 7ec07fb5273..1f8f6aa04ae 100644 --- a/mysql-test/r/lock.result +++ b/mysql-test/r/lock.result @@ -48,6 +48,9 @@ unlock tables; lock tables t1 write, t1 as t1_alias read; insert into t1 select index1,nr from t1 as t1_alias; drop table t1,t2; +ERROR HY000: Table 't2' was not locked with LOCK TABLES +unlock tables; +drop table t1,t2; create table t1 (c1 int); create table t2 (c1 int); create table t3 (c1 int); @@ -69,6 +72,9 @@ ERROR HY000: Table 't2' was locked with a READ lock and can't be updated delete t2 from t1,t2 where t1.a=t2.a; ERROR HY000: Table 't2' was locked with a READ lock and can't be updated drop table t1,t2; +ERROR HY000: Table 't2' was locked with a READ lock and can't be updated +unlock tables; +drop table t2,t1; End of 4.1 tests. drop table if exists t1; create table t1 (a int); diff --git a/mysql-test/r/lock_multi.result b/mysql-test/r/lock_multi.result index d8768e802ea..49e51631b91 100644 --- a/mysql-test/r/lock_multi.result +++ b/mysql-test/r/lock_multi.result @@ -27,6 +27,7 @@ update t1,t2 set c=a where b=d; select c from t2; c 2 +unlock tables; drop table t1; drop table t2; create table t1 (a int); diff --git a/mysql-test/r/myisam.result b/mysql-test/r/myisam.result index 95fdc4fb93d..16e8a8e5ad1 100644 --- a/mysql-test/r/myisam.result +++ b/mysql-test/r/myisam.result @@ -529,6 +529,7 @@ select straight_join * from t1,t2 force index (primary) where t1.a=t2.a; a a b 1 1 1 2 2 1 +unlock tables; drop table t1,t2; CREATE TABLE t1 (c1 varchar(250) NOT NULL); CREATE TABLE t2 (c1 varchar(250) NOT NULL, PRIMARY KEY (c1)); @@ -542,6 +543,7 @@ INSERT INTO t2 VALUES ('test000001'), ('test000005'); SELECT t1.c1 AS t1c1, t2.c1 AS t2c1 FROM t1, t2 WHERE t1.c1 = t2.c1 HAVING t1c1 != t2c1; t1c1 t2c1 +UNLOCK TABLES; DROP TABLE t1,t2; CREATE TABLE t1 (`a` int(11) NOT NULL default '0', `b` int(11) NOT NULL default '0', UNIQUE KEY `a` USING RTREE (`a`,`b`)) ENGINE=MyISAM; Got one of the listed errors diff --git a/mysql-test/r/query_cache_notembedded.result b/mysql-test/r/query_cache_notembedded.result index d9bf7a6d814..25894634bf3 100644 --- a/mysql-test/r/query_cache_notembedded.result +++ b/mysql-test/r/query_cache_notembedded.result @@ -93,6 +93,7 @@ a 3 SELECT * FROM t1; a +UNLOCK TABLES; drop table t1; flush query cache; reset query cache; diff --git a/mysql-test/r/view.result b/mysql-test/r/view.result index 69bcf349f51..2df2b0bafa6 100644 --- a/mysql-test/r/view.result +++ b/mysql-test/r/view.result @@ -1104,6 +1104,9 @@ select * from t2; ERROR HY000: Table 't2' was not locked with LOCK TABLES drop view v1; drop table t1, t2; +ERROR HY000: Table 't1' was locked with a READ lock and can't be updated +unlock tables; +drop table t1, t2; create table t1 (a int); create view v1 as select * from t1 where a < 2 with check option; insert into v1 values(1); diff --git a/mysql-test/t/drop.test b/mysql-test/t/drop.test index 6be4ea25007..4aeb7165bcb 100644 --- a/mysql-test/t/drop.test +++ b/mysql-test/t/drop.test @@ -124,6 +124,39 @@ disconnect addconroot1; --source include/wait_until_disconnected.inc connection default; +# +# Bug#25858 Some DROP TABLE under LOCK TABLES can cause deadlocks +# + +--disable_warnings +drop table if exists t1,t2; +--enable_warnings +create table t1 (a int); +create table t2 (a int); +lock table t1 read; +--error ER_TABLE_NOT_LOCKED +drop table t2; +--error ER_TABLE_NOT_LOCKED_FOR_WRITE +drop table t1; +unlock tables; +drop table t1,t2; +connect (addconroot, localhost, root,,); +connection default; +create table t1 (i int); +create table t2 (i int); +lock tables t1 read; +connection addconroot; +lock tables t2 read; +--error ER_TABLE_NOT_LOCKED +drop table t1; +connection default; +--error ER_TABLE_NOT_LOCKED_FOR_WRITE +drop table t1,t2; +disconnect addconroot; +connection default; +unlock tables; +drop table t1,t2; + --echo End of 5.0 tests # diff --git a/mysql-test/t/group_by.test b/mysql-test/t/group_by.test index 5b96213034a..7ed8dfe5784 100644 --- a/mysql-test/t/group_by.test +++ b/mysql-test/t/group_by.test @@ -120,8 +120,9 @@ SELECT cid, CONCAT(firstname, ' ', surname), COUNT(call_id) FROM t1 LEFT JOIN t2 SELECT cid, CONCAT(firstname, ' ', surname), COUNT(call_id) FROM t1 LEFT JOIN t2 ON cid=contact_id WHERE firstname like '%foo%' GROUP BY cid ORDER BY NULL; SELECT HIGH_PRIORITY cid, CONCAT(firstname, ' ', surname), COUNT(call_id) FROM t1 LEFT JOIN t2 ON cid=contact_id WHERE firstname like '%foo%' GROUP BY cid ORDER BY surname, firstname; -drop table t1,t2; +drop table t2; unlock tables; +drop table t1; # # Test of group by bug in bugzilla diff --git a/mysql-test/t/insert_notembedded.test b/mysql-test/t/insert_notembedded.test index 24040f9c310..2950acff3cc 100644 --- a/mysql-test/t/insert_notembedded.test +++ b/mysql-test/t/insert_notembedded.test @@ -185,5 +185,6 @@ select * from t1; connection default; disconnect update; disconnect select; +unlock tables; drop table t1; set low_priority_updates=default; diff --git a/mysql-test/t/lock.test b/mysql-test/t/lock.test index 30f4d4d6c61..04994e3e48f 100644 --- a/mysql-test/t/lock.test +++ b/mysql-test/t/lock.test @@ -58,6 +58,9 @@ insert into t1 select index1,nr from t1; unlock tables; lock tables t1 write, t1 as t1_alias read; insert into t1 select index1,nr from t1 as t1_alias; +--error ER_TABLE_NOT_LOCKED +drop table t1,t2; +unlock tables; drop table t1,t2; # @@ -90,7 +93,10 @@ delete t1 from t1,t2 where t1.a=t2.a; delete from t2 using t1,t2 where t1.a=t2.a; --error 1099 delete t2 from t1,t2 where t1.a=t2.a; +--error ER_TABLE_NOT_LOCKED_FOR_WRITE drop table t1,t2; +unlock tables; +drop table t2,t1; --echo End of 4.1 tests. diff --git a/mysql-test/t/lock_multi.test b/mysql-test/t/lock_multi.test index dbaa96b0374..cd4d70bd99e 100644 --- a/mysql-test/t/lock_multi.test +++ b/mysql-test/t/lock_multi.test @@ -76,6 +76,7 @@ update t1,t2 set c=a where b=d; connection reader; select c from t2; connection locker; +unlock tables; drop table t1; drop table t2; diff --git a/mysql-test/t/myisam.test b/mysql-test/t/myisam.test index 56fe103adc9..3ee61dcbc1f 100644 --- a/mysql-test/t/myisam.test +++ b/mysql-test/t/myisam.test @@ -503,6 +503,7 @@ insert into t2 values(2,0); disconnect root; connection default; select straight_join * from t1,t2 force index (primary) where t1.a=t2.a; +unlock tables; drop table t1,t2; # # Full key. @@ -520,6 +521,7 @@ disconnect con1; connection default; SELECT t1.c1 AS t1c1, t2.c1 AS t2c1 FROM t1, t2 WHERE t1.c1 = t2.c1 HAVING t1c1 != t2c1; +UNLOCK TABLES; DROP TABLE t1,t2; # End of 4.0 tests diff --git a/mysql-test/t/query_cache_notembedded.test b/mysql-test/t/query_cache_notembedded.test index 095d47f5bdf..77033ced564 100644 --- a/mysql-test/t/query_cache_notembedded.test +++ b/mysql-test/t/query_cache_notembedded.test @@ -99,6 +99,7 @@ connection root2; SELECT * FROM t1; connection root; SELECT * FROM t1; +UNLOCK TABLES; drop table t1; connection default; disconnect root; diff --git a/mysql-test/t/view.test b/mysql-test/t/view.test index b2490847dbc..abf8dac2870 100644 --- a/mysql-test/t/view.test +++ b/mysql-test/t/view.test @@ -1017,6 +1017,9 @@ select * from v1; -- error ER_TABLE_NOT_LOCKED select * from t2; drop view v1; +--error ER_TABLE_NOT_LOCKED_FOR_WRITE +drop table t1, t2; +unlock tables; drop table t1, t2; # diff --git a/sql/lock.cc b/sql/lock.cc index 112d3dc4a2b..6cdd654fb92 100644 --- a/sql/lock.cc +++ b/sql/lock.cc @@ -1028,6 +1028,7 @@ int lock_table_name(THD *thd, TABLE_LIST *table_list, bool check_in_use) char key[MAX_DBKEY_LENGTH]; char *db= table_list->db; uint key_length; + bool found_locked_table= FALSE; HASH_SEARCH_STATE state; DBUG_ENTER("lock_table_name"); DBUG_PRINT("enter",("db: %s name: %s", db, table_list->table_name)); @@ -1043,6 +1044,13 @@ int lock_table_name(THD *thd, TABLE_LIST *table_list, bool check_in_use) table = (TABLE*) my_hash_next(&open_cache,(uchar*) key, key_length, &state)) { + if (table->reginfo.lock_type < TL_WRITE) + { + if (table->in_use == thd) + found_locked_table= TRUE; + continue; + } + if (table->in_use == thd) { DBUG_PRINT("info", ("Table is in use")); @@ -1053,6 +1061,17 @@ int lock_table_name(THD *thd, TABLE_LIST *table_list, bool check_in_use) } } + if (thd->locked_tables && thd->locked_tables->table_count && + ! find_temporary_table(thd, table_list->db, table_list->table_name)) + { + if (found_locked_table) + my_error(ER_TABLE_NOT_LOCKED_FOR_WRITE, MYF(0), table_list->alias); + else + my_error(ER_TABLE_NOT_LOCKED, MYF(0), table_list->alias); + + DBUG_RETURN(-1); + } + if (!(table= table_cache_insert_placeholder(thd, key, key_length))) DBUG_RETURN(-1); From 36ab5d7989987a161ac820a1fbc2cdba19a627da Mon Sep 17 00:00:00 2001 From: Konstantin Osipov Date: Fri, 20 Nov 2009 23:12:57 +0300 Subject: [PATCH 09/23] Backport of: ------------------------------------------------------------ revno: 2476.1116.1 committer: davi@mysql.com/endora.local timestamp: Fri 2007-12-14 10:10:19 -0200 message: DROP TABLE under LOCK TABLES simultaneous to a FLUSH TABLES WITH READ LOCK (global read lock) can lead to a deadlock. The solution is to not wait for the global read lock if the thread is holding any locked tables. Related to bugs 23713 and 32395. This issues is being fixed only on 6.0 because it depends on the fix for bug 25858 -- which was fixed only on 6.0. --- mysql-test/r/lock_multi.result | 9 +++++++++ mysql-test/t/lock_multi.test | 37 +++++++++++++++++++++++++++++++++- sql/sql_table.cc | 15 ++++++-------- 3 files changed, 51 insertions(+), 10 deletions(-) diff --git a/mysql-test/r/lock_multi.result b/mysql-test/r/lock_multi.result index 49e51631b91..3f1165fd069 100644 --- a/mysql-test/r/lock_multi.result +++ b/mysql-test/r/lock_multi.result @@ -210,3 +210,12 @@ select @tlwa < @tlwb; @tlwa < @tlwb 1 End of 5.1 tests +drop table if exists t1; +create table t1 (i int); +connection: default +lock tables t1 write; +connection: flush +flush tables with read lock;; +connection: default +flush tables; +drop table t1; diff --git a/mysql-test/t/lock_multi.test b/mysql-test/t/lock_multi.test index cd4d70bd99e..75ee6d07723 100644 --- a/mysql-test/t/lock_multi.test +++ b/mysql-test/t/lock_multi.test @@ -636,6 +636,41 @@ select @tlwa < @tlwb; --echo End of 5.1 tests +# +# Test that DROP TABLES does not wait for a impending FLUSH TABLES +# WITH READ LOCK +# + +--disable_warnings +drop table if exists t1; +--enable_warnings +create table t1 (i int); +connect (flush,localhost,root,,test,,); +connection default; +--echo connection: default +lock tables t1 write; +connection flush; +--echo connection: flush +--send flush tables with read lock; +connection default; +--echo connection: default +let $wait_condition= + select count(*) = 1 from information_schema.processlist + where state = "Flushing tables"; +--source include/wait_condition.inc +flush tables; +let $wait_condition= + select count(*) = 1 from information_schema.processlist + where state = "Flushing tables"; +--source include/wait_condition.inc +drop table t1; +let $wait_condition= + select count(*) = 0 from information_schema.processlist + where state = "Flushing tables"; +--source include/wait_condition.inc +connection flush; +--reap +connection default; +disconnect flush; # Wait till all disconnects are completed --source include/wait_until_count_sessions.inc - diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 63dc4e68fdf..150a896103c 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -1766,7 +1766,8 @@ void write_bin_log(THD *thd, bool clear_error, If a table is in use, we will wait for all users to free the table before dropping it - Wait if global_read_lock (FLUSH TABLES WITH READ LOCK) is set. + Wait if global_read_lock (FLUSH TABLES WITH READ LOCK) is set, but + not if under LOCK TABLES. RETURN FALSE OK. In this case ok packet is sent to user @@ -1777,7 +1778,7 @@ void write_bin_log(THD *thd, bool clear_error, bool mysql_rm_table(THD *thd,TABLE_LIST *tables, my_bool if_exists, my_bool drop_temporary) { - bool error= FALSE, need_start_waiters= FALSE; + bool error= FALSE, need_start_waiting= FALSE; Drop_table_error_handler err_handler(thd->get_internal_handler()); DBUG_ENTER("mysql_rm_table"); @@ -1785,13 +1786,9 @@ bool mysql_rm_table(THD *thd,TABLE_LIST *tables, my_bool if_exists, if (!drop_temporary) { - if ((error= wait_if_global_read_lock(thd, 0, 1))) - { - my_error(ER_TABLE_NOT_LOCKED_FOR_WRITE, MYF(0), tables->table_name); + if (!thd->locked_tables && + !(need_start_waiting= !wait_if_global_read_lock(thd, 0, 1))) DBUG_RETURN(TRUE); - } - else - need_start_waiters= TRUE; } /* @@ -1804,7 +1801,7 @@ bool mysql_rm_table(THD *thd,TABLE_LIST *tables, my_bool if_exists, thd->pop_internal_handler(); - if (need_start_waiters) + if (need_start_waiting) start_waiting_global_read_lock(thd); if (error) From 5a78d2a7d5a0643dca5e25df5d2cb95cbc1b7ccb Mon Sep 17 00:00:00 2001 From: Konstantin Osipov Date: Fri, 20 Nov 2009 23:30:00 +0300 Subject: [PATCH 10/23] Backport of: ------------------------------------------------------------ revno: 2572.23.1 committer: davi@mysql.com/endora.local timestamp: Wed 2008-03-19 09:03:08 -0300 message: Bug#17954 Threads_connected > Threads_created The problem is that insert delayed threads are counted as connected but not as created, leading to a Threads_connected value greater then the Threads_created value. The solution is to enforce the documented behavior that the Threads_connected value shall be the number of currently open connections and that Threads_created shall be the number of threads created to handle connections. --- mysql-test/r/status.result | 6 ++++++ mysql-test/t/status.test | 15 +++++++++++++++ sql/mysqld.cc | 5 +++-- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/mysql-test/r/status.result b/mysql-test/r/status.result index ce3acba9b8a..c0cd0f7bc1a 100644 --- a/mysql-test/r/status.result +++ b/mysql-test/r/status.result @@ -238,5 +238,11 @@ SELECT 9; 9 DROP PROCEDURE p1; DROP FUNCTION f1; +DROP VIEW IF EXISTS v1; +CREATE VIEW v1 AS SELECT VARIABLE_NAME AS NAME, CONVERT(VARIABLE_VALUE, UNSIGNED) AS VALUE FROM INFORMATION_SCHEMA.GLOBAL_STATUS; +SELECT VALUE INTO @tc FROM v1 WHERE NAME = 'Threads_connected'; +SELECT NAME FROM v1 WHERE NAME = 'Threads_created' AND VALUE < @tc; +NAME +DROP VIEW v1; set @@global.concurrent_insert= @old_concurrent_insert; SET GLOBAL log_output = @old_log_output; diff --git a/mysql-test/t/status.test b/mysql-test/t/status.test index 5da210f5a69..f951218f5c8 100644 --- a/mysql-test/t/status.test +++ b/mysql-test/t/status.test @@ -353,6 +353,21 @@ DROP FUNCTION f1; # End of 5.1 tests +# +# Bug#17954 Threads_connected > Threads_created +# + +--disable_warnings +DROP VIEW IF EXISTS v1; +--enable_warnings + +CREATE VIEW v1 AS SELECT VARIABLE_NAME AS NAME, CONVERT(VARIABLE_VALUE, UNSIGNED) AS VALUE FROM INFORMATION_SCHEMA.GLOBAL_STATUS; + +SELECT VALUE INTO @tc FROM v1 WHERE NAME = 'Threads_connected'; +SELECT NAME FROM v1 WHERE NAME = 'Threads_created' AND VALUE < @tc; + +DROP VIEW v1; + # Restore global concurrent_insert value. Keep in the end of the test file. --connection default set @@global.concurrent_insert= @old_concurrent_insert; diff --git a/sql/mysqld.cc b/sql/mysqld.cc index c1b8b62c470..ac575865841 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -2471,7 +2471,8 @@ and this may fail.\n\n"); fprintf(stderr, "read_buffer_size=%ld\n", (long) global_system_variables.read_buff_size); fprintf(stderr, "max_used_connections=%lu\n", max_used_connections); fprintf(stderr, "max_threads=%u\n", thread_scheduler.max_threads); - fprintf(stderr, "threads_connected=%u\n", thread_count); + fprintf(stderr, "thread_count=%u\n", thread_count); + fprintf(stderr, "connection_count=%u\n", connection_count); fprintf(stderr, "It is possible that mysqld could use up to \n\ key_buffer_size + (read_buffer_size + sort_buffer_size)*max_threads = %lu K\n\ bytes of memory\n", ((ulong) dflt_key_cache->key_cache_mem_size + @@ -7624,7 +7625,7 @@ SHOW_VAR status_vars[]= { {"Tc_log_page_waits", (char*) &tc_log_page_waits, SHOW_LONG}, #endif {"Threads_cached", (char*) &cached_thread_count, SHOW_LONG_NOFLUSH}, - {"Threads_connected", (char*) &thread_count, SHOW_INT}, + {"Threads_connected", (char*) &connection_count, SHOW_INT}, {"Threads_created", (char*) &thread_created, SHOW_LONG_NOFLUSH}, {"Threads_running", (char*) &thread_running, SHOW_INT}, {"Uptime", (char*) &show_starttime, SHOW_FUNC}, From a4b2b2b9f036dbda6fa22b36d59febc7e008fd39 Mon Sep 17 00:00:00 2001 From: Konstantin Osipov Date: Sat, 21 Nov 2009 01:42:57 +0300 Subject: [PATCH 11/23] Backport the test caes for Bug#36510 from 6.0-codebase. --- mysql-test/r/sp-error.result | 23 ++++++++++++++++++++++ mysql-test/t/sp-error.test | 37 ++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/mysql-test/r/sp-error.result b/mysql-test/r/sp-error.result index 499506957fa..7a3cb55858b 100644 --- a/mysql-test/r/sp-error.result +++ b/mysql-test/r/sp-error.result @@ -1659,6 +1659,29 @@ begin declare continue handler for sqlstate '00000' set @x=0; end$$ ERROR 42000: Bad SQLSTATE: '00000' +drop procedure if exists proc_36510; +create procedure proc_36510() +begin +declare should_be_illegal condition for sqlstate '00123'; +declare continue handler for should_be_illegal set @x=0; +end$$ +ERROR 42000: Bad SQLSTATE: '00123' +create procedure proc_36510() +begin +declare continue handler for sqlstate '00123' set @x=0; +end$$ +ERROR 42000: Bad SQLSTATE: '00123' +create procedure proc_36510() +begin +declare should_be_illegal condition for 0; +declare continue handler for should_be_illegal set @x=0; +end$$ +ERROR HY000: Incorrect CONDITION value: '0' +create procedure proc_36510() +begin +declare continue handler for 0 set @x=0; +end$$ +ERROR HY000: Incorrect CONDITION value: '0' drop procedure if exists p1; set @old_recursion_depth = @@max_sp_recursion_depth; set @@max_sp_recursion_depth = 255; diff --git a/mysql-test/t/sp-error.test b/mysql-test/t/sp-error.test index b022ca4b0e1..a9bb80647bc 100644 --- a/mysql-test/t/sp-error.test +++ b/mysql-test/t/sp-error.test @@ -2419,6 +2419,43 @@ end$$ delimiter ;$$ +# +# Bug#36510 (Stored Procedures: mysql_error_code 0 should be illegal) +# + +--disable_warnings +drop procedure if exists proc_36510; +--enable_warnings + +delimiter $$; + +--error ER_SP_BAD_SQLSTATE +create procedure proc_36510() +begin + declare should_be_illegal condition for sqlstate '00123'; + declare continue handler for should_be_illegal set @x=0; +end$$ + +--error ER_SP_BAD_SQLSTATE +create procedure proc_36510() +begin + declare continue handler for sqlstate '00123' set @x=0; +end$$ + +--error ER_WRONG_VALUE +create procedure proc_36510() +begin + declare should_be_illegal condition for 0; + declare continue handler for should_be_illegal set @x=0; +end$$ + +--error ER_WRONG_VALUE +create procedure proc_36510() +begin + declare continue handler for 0 set @x=0; +end$$ +delimiter ;$$ + # # Bug#15192: "fatal errors" are caught by handlers in stored procedures # From ef4bd9796f7105635c16191adda6faa06494f9c4 Mon Sep 17 00:00:00 2001 From: Konstantin Osipov Date: Sat, 21 Nov 2009 01:53:50 +0300 Subject: [PATCH 12/23] Backport of: ------------------------------------------------------------ revno: 2597.42.4 committer: davi@mysql.com/endora.local timestamp: Tue 2008-04-15 17:29:42 -0300 message: Bug#36004 mysql_stmt_prepare resets the list of warnings Although the manual says that "the list of messages is reset for each new statement that uses a table", the list of messages is being unconditionally reset for prepare commands. The solution is to enforce that the prepare command will only reset the message list if the statement being prepared uses a table or a warning is pushed. --- tests/mysql_client_test.c | 45 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/tests/mysql_client_test.c b/tests/mysql_client_test.c index cfe401c75f3..86906660d4c 100644 --- a/tests/mysql_client_test.c +++ b/tests/mysql_client_test.c @@ -18392,9 +18392,51 @@ static void test_wl4166_4() } /** - Bug#38486 Crash when using cursor protocol + Bug#36004 mysql_stmt_prepare resets the list of warnings */ +static void test_bug36004() +{ + int rc, warning_count= 0; + MYSQL_STMT *stmt; + + DBUG_ENTER("test_bug36004"); + myheader("test_bug36004"); + + rc= mysql_query(mysql, "drop table if exists inexistant"); + myquery(rc); + + DIE_UNLESS(mysql_warning_count(mysql) == 1); + query_int_variable(mysql, "@@warning_count", &warning_count); + DIE_UNLESS(warning_count); + + stmt= mysql_simple_prepare(mysql, "select 1"); + check_stmt(stmt); + + DIE_UNLESS(mysql_warning_count(mysql) == 0); + query_int_variable(mysql, "@@warning_count", &warning_count); + DIE_UNLESS(warning_count); + + rc= mysql_stmt_execute(stmt); + check_execute(stmt, rc); + + DIE_UNLESS(mysql_warning_count(mysql) == 0); + mysql_stmt_close(stmt); + + query_int_variable(mysql, "@@warning_count", &warning_count); + DIE_UNLESS(warning_count); + + stmt= mysql_simple_prepare(mysql, "drop table if exists inexistant"); + check_stmt(stmt); + + query_int_variable(mysql, "@@warning_count", &warning_count); + DIE_UNLESS(warning_count == 0); + mysql_stmt_close(stmt); + + DBUG_VOID_RETURN; +} + + static void test_bug38486(void) { MYSQL_STMT *stmt; @@ -19154,6 +19196,7 @@ static struct my_tests_st my_tests[]= { { "test_wl4166_2", test_wl4166_2 }, { "test_wl4166_3", test_wl4166_3 }, { "test_wl4166_4", test_wl4166_4 }, + { "test_bug36004", test_bug36004 }, { "test_wl4435", test_wl4435 }, { "test_wl4435_2", test_wl4435_2 }, { "test_bug38486", test_bug38486 }, From 9a1043417d99769026277ed34b629c7bf9eae494 Mon Sep 17 00:00:00 2001 From: Konstantin Osipov Date: Sat, 21 Nov 2009 02:06:30 +0300 Subject: [PATCH 13/23] Backport the test case for Bug#31881 "A statement is not aborted immediately if an error inside a stored routine" from 6.0-codebase. --- mysql-test/r/errors.result | 36 ++++++++++++++++++++++++++++++++++++ mysql-test/t/errors.test | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+) diff --git a/mysql-test/r/errors.result b/mysql-test/r/errors.result index d15daf2e4b0..b5863b94026 100644 --- a/mysql-test/r/errors.result +++ b/mysql-test/r/errors.result @@ -55,6 +55,42 @@ Error 1054 Unknown column 'b' in 'field list' INSERT INTO t1 SELECT b FROM t1; ERROR 42S22: Unknown column 'b' in 'field list' DROP TABLE t1; +flush status; +drop table if exists t1, t2; +create table t1 (a int unique); +create table t2 (a int); +drop function if exists f1; +Warnings: +Note 1305 FUNCTION f1 does not exist +drop function if exists f2; +Warnings: +Note 1305 FUNCTION f2 does not exist +create function f1() returns int +begin +insert into t1 (a) values (1); +insert into t1 (a) values (1); +return 1; +end| +create function f2() returns int +begin +insert into t2 (a) values (1); +return 2; +end| +flush status; +select f1(), f2(); +ERROR 23000: Duplicate entry '1' for key 'a' +show status like 'Com_insert'; +Variable_name Value +Com_insert 2 +select * from t1; +a +1 +select * from t2; +a +drop table t1; +drop table t2; +drop function f1; +drop function f2; SET NAMES utf8; SET sql_quote_show_create= _binary x'5452C39C45'; ERROR 42000: Variable 'sql_quote_show_create' can't be set to the value of 'TR\xC3\x9CE' diff --git a/mysql-test/t/errors.test b/mysql-test/t/errors.test index 820766c3a78..44c514f1244 100644 --- a/mysql-test/t/errors.test +++ b/mysql-test/t/errors.test @@ -68,6 +68,40 @@ INSERT INTO t1 SELECT b FROM t1; DROP TABLE t1; # End of 5.0 tests +flush status; +--disable_warnings +drop table if exists t1, t2; +--enable_warnings +create table t1 (a int unique); +create table t2 (a int); +drop function if exists f1; +drop function if exists f2; + +delimiter |; + +create function f1() returns int +begin + insert into t1 (a) values (1); + insert into t1 (a) values (1); + return 1; +end| +create function f2() returns int +begin + insert into t2 (a) values (1); + return 2; +end| +delimiter ;| + +flush status; +--error 1062 +select f1(), f2(); +show status like 'Com_insert'; +select * from t1; +select * from t2; +drop table t1; +drop table t2; +drop function f1; +drop function f2; # # testing the value encoding in the error messages of set_var # From a2a437b7cae6e5d78296a936738a07f2d9ef88f9 Mon Sep 17 00:00:00 2001 From: Konstantin Osipov Date: Sat, 21 Nov 2009 02:12:23 +0300 Subject: [PATCH 14/23] Backport the implementation of vio_pending from 6.0-codebase. Original changeset: ------------------------------------------------------------ revno: 2626 committer: davi@mysql.com/endora.local timestamp: Wed 2008-04-23 09:33:25 -0300 message: Fix for main.ssl and main.ssl_compress test case failures under pool-of-threads. The problem is that the SSL layer has a read buffer and might read more data than requested by the VIO layer. The SSL layer empties the socket buffer which causes the socket to not be signaled for IO if the client is waiting for a command which is sitting in the read buffer. The solution is to retrieve from the transport layer the number of bytes waiting in the read buffer. The data in the read buffer needs to be processed before waiting for more data. --- include/violite.h | 1 + vio/viosocket.c | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/include/violite.h b/include/violite.h index 0af7a566307..3e8e430392b 100644 --- a/include/violite.h +++ b/include/violite.h @@ -86,6 +86,7 @@ my_bool vio_peer_addr(Vio* vio, char *buf, uint16 *port); void vio_in_addr(Vio *vio, struct in_addr *in); my_bool vio_poll_read(Vio *vio, uint timeout); my_bool vio_is_connected(Vio *vio); +ssize_t vio_pending(Vio *vio); #ifdef HAVE_OPENSSL #include diff --git a/vio/viosocket.c b/vio/viosocket.c index 30187cbed56..51345d072b2 100644 --- a/vio/viosocket.c +++ b/vio/viosocket.c @@ -855,3 +855,27 @@ int vio_close_shared_memory(Vio * vio) } #endif /* HAVE_SMEM */ #endif /* __WIN__ */ + + +/** + Number of bytes in the read buffer. + + @return number of bytes in the read buffer or < 0 if error. +*/ + +ssize_t vio_pending(Vio *vio) +{ +#ifdef HAVE_OPENSSL + SSL *ssl= (SSL*) vio->ssl_arg; +#endif + + if (vio->read_pos < vio->read_end) + return vio->read_end - vio->read_pos; + +#ifdef HAVE_OPENSSL + if (ssl) + return SSL_pending(ssl); +#endif + + return 0; +} From 7fc7fb0eff5bdd27f20a2143154f11c975e8f5af Mon Sep 17 00:00:00 2001 From: Konstantin Osipov Date: Sat, 21 Nov 2009 13:15:02 +0300 Subject: [PATCH 15/23] Backport of: ------------------------------------------------------------ revno: 2627 committer: davi@mysql.com/endora.local timestamp: Wed 2008-04-23 13:25:02 -0300 message: Fix for a build failure on Windows due to ssize_t not being declared. --- include/config-win.h | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/include/config-win.h b/include/config-win.h index 364c4f92134..431bfcfa702 100644 --- a/include/config-win.h +++ b/include/config-win.h @@ -145,12 +145,23 @@ 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 +#ifndef HAVE_SIZE_T +#ifndef _SIZE_T_DEFINED +typedef SIZE_T size_t; +#define _SIZE_T_DEFINED +#endif +#endif + +#ifndef HAVE_SSIZE_T +#ifndef _SSIZE_T_DEFINED +typedef SSIZE_T ssize_t; +#define _SSIZE_T_DEFINED +#endif +#endif + #define Socket_defined #define my_socket SOCKET #define SIGPIPE SIGINT From 7e532b13469001e3cf30390d60e023450118c5d4 Mon Sep 17 00:00:00 2001 From: Konstantin Osipov Date: Mon, 23 Nov 2009 14:01:20 +0300 Subject: [PATCH 16/23] Backport of: ------------------------------------------------------------ revno: 2642 committer: davi@mysql.com/endora.local timestamp: Fri 2008-05-16 01:29:09 -0300 message: Fix for a valgrind warning due to a jump on a uninitialized variable. The problem was that the sql profile preparation function wasn't being called for all possible code paths of query execution. The solution is to move the preparation to the dispatch_command function and to explicitly call the profile preparation function on bootstrap. --- sql/sql_parse.cc | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 99fb08abcca..c2021710d6c 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -812,11 +812,7 @@ bool do_command(THD *thd) net_new_transaction(net); - packet_length= my_net_read(net); -#if defined(ENABLED_PROFILING) - thd->profiling.start_new_query(); -#endif - if (packet_length == packet_error) + if ((packet_length= my_net_read(net)) == packet_error) { DBUG_PRINT("info",("Got error %d reading command from socket %s", net->error, @@ -873,9 +869,6 @@ bool do_command(THD *thd) return_value= dispatch_command(command, thd, packet+1, (uint) (packet_length-1)); out: -#if defined(ENABLED_PROFILING) - thd->profiling.finish_current_query(); -#endif DBUG_RETURN(return_value); } #endif /* EMBEDDED_LIBRARY */ @@ -977,6 +970,9 @@ bool dispatch_command(enum enum_server_command command, THD *thd, DBUG_ENTER("dispatch_command"); DBUG_PRINT("info",("packet: '%*.s'; command: %d", packet_length, packet, command)); +#if defined(ENABLED_PROFILING) + thd->profiling.start_new_query(); +#endif MYSQL_COMMAND_START(thd->thread_id, command, thd->security_ctx->priv_user, (char *) thd->security_ctx->host_or_ip); @@ -1608,6 +1604,9 @@ bool dispatch_command(enum enum_server_command command, THD *thd, thd->packet.shrink(thd->variables.net_buffer_length); // Reclaim some memory free_root(thd->mem_root,MYF(MY_KEEP_PREALLOC)); +#if defined(ENABLED_PROFILING) + thd->profiling.finish_current_query(); +#endif if (MYSQL_QUERY_DONE_ENABLED() || MYSQL_COMMAND_DONE_ENABLED()) { int res; From 777c3034017e3d90937e055e9928b42a48ad6adf Mon Sep 17 00:00:00 2001 From: Konstantin Osipov Date: Mon, 23 Nov 2009 16:09:39 +0300 Subject: [PATCH 17/23] Backport of: ------------------------------------------------------------ revno: 2630.13.2 committer: Davi Arnaut branch nick: WL4284-6.0 timestamp: Thu 2008-07-03 18:26:51 -0300 message: Remove unused USING_TRANSACTIONS macro which unnecessarily cumbers the code. This macro is a historical leftover and has no practical use since its unconditionally defined. --- sql/handler.cc | 21 +++++++++------------ sql/handler.h | 2 -- sql/log.cc | 3 +-- sql/log_event.cc | 3 +-- sql/set_var.cc | 2 -- sql/sql_class.cc | 4 ---- sql/sql_class.h | 10 ---------- sql/sql_parse.cc | 2 -- 8 files changed, 11 insertions(+), 36 deletions(-) diff --git a/sql/handler.cc b/sql/handler.cc index ad7e1ecfa80..9d1fc723208 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -992,7 +992,7 @@ int ha_prepare(THD *thd) THD_TRANS *trans=all ? &thd->transaction.all : &thd->transaction.stmt; Ha_trx_info *ha_info= trans->ha_list; DBUG_ENTER("ha_prepare"); -#ifdef USING_TRANSACTIONS + if (ha_info) { for (; ha_info; ha_info= ha_info->next()) @@ -1018,7 +1018,7 @@ int ha_prepare(THD *thd) } } } -#endif /* USING_TRANSACTIONS */ + DBUG_RETURN(error); } @@ -1146,7 +1146,7 @@ int ha_commit_trans(THD *thd, bool all) my_error(ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG, MYF(0)); DBUG_RETURN(2); } -#ifdef USING_TRANSACTIONS + if (ha_info) { uint rw_ha_count; @@ -1227,7 +1227,6 @@ end: /* Free resources and perform other cleanup even for 'empty' transactions. */ else if (is_real_trans) thd->transaction.cleanup(); -#endif /* USING_TRANSACTIONS */ DBUG_RETURN(error); } @@ -1249,7 +1248,7 @@ int ha_commit_one_phase(THD *thd, bool all) bool is_real_trans=all || thd->transaction.all.ha_list == 0; Ha_trx_info *ha_info= trans->ha_list, *ha_info_next; DBUG_ENTER("ha_commit_one_phase"); -#ifdef USING_TRANSACTIONS + if (ha_info) { for (; ha_info; ha_info= ha_info_next) @@ -1279,7 +1278,7 @@ int ha_commit_one_phase(THD *thd, bool all) /* Free resources and perform other cleanup even for 'empty' transactions. */ if (is_real_trans) thd->transaction.cleanup(); -#endif /* USING_TRANSACTIONS */ + DBUG_RETURN(error); } @@ -1319,7 +1318,7 @@ int ha_rollback_trans(THD *thd, bool all) my_error(ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG, MYF(0)); DBUG_RETURN(1); } -#ifdef USING_TRANSACTIONS + if (ha_info) { /* Close all cursors that can not survive ROLLBACK */ @@ -1350,7 +1349,6 @@ int ha_rollback_trans(THD *thd, bool all) /* Always cleanup. Even if there nht==0. There may be savepoints. */ if (is_real_trans) thd->transaction.cleanup(); -#endif /* USING_TRANSACTIONS */ if (all) thd->transaction_rollback_request= FALSE; @@ -1386,7 +1384,7 @@ int ha_rollback_trans(THD *thd, bool all) int ha_autocommit_or_rollback(THD *thd, int error) { DBUG_ENTER("ha_autocommit_or_rollback"); -#ifdef USING_TRANSACTIONS + if (thd->transaction.stmt.ha_list) { if (!error) @@ -1404,7 +1402,6 @@ int ha_autocommit_or_rollback(THD *thd, int error) thd->variables.tx_isolation=thd->session_tx_isolation; } else -#endif { if (!error) RUN_HOOK(transaction, after_commit, (thd, FALSE)); @@ -1812,7 +1809,7 @@ int ha_savepoint(THD *thd, SAVEPOINT *sv) &thd->transaction.all); Ha_trx_info *ha_info= trans->ha_list; DBUG_ENTER("ha_savepoint"); -#ifdef USING_TRANSACTIONS + for (; ha_info; ha_info= ha_info->next()) { int err; @@ -1836,7 +1833,7 @@ int ha_savepoint(THD *thd, SAVEPOINT *sv) engines are prepended to the beginning of the list. */ sv->ha_list= trans->ha_list; -#endif /* USING_TRANSACTIONS */ + DBUG_RETURN(error); } diff --git a/sql/handler.h b/sql/handler.h index 05a9e13653c..5f028796cf3 100644 --- a/sql/handler.h +++ b/sql/handler.h @@ -31,8 +31,6 @@ #define NO_HASH /* Not yet implemented */ #endif -#define USING_TRANSACTIONS - // the following is for checking tables #define HA_ADMIN_ALREADY_DONE 1 diff --git a/sql/log.cc b/sql/log.cc index e7deebad196..0abcdb59551 100644 --- a/sql/log.cc +++ b/sql/log.cc @@ -4089,7 +4089,6 @@ bool MYSQL_BIN_LOG::write(Log_event *event_info) } #endif /* HAVE_REPLICATION */ -#if defined(USING_TRANSACTIONS) /* Should we write to the binlog cache or to the binlog on disk? Write to the binlog cache if: @@ -4124,7 +4123,7 @@ bool MYSQL_BIN_LOG::write(Log_event *event_info) LOCK_log. */ } -#endif /* USING_TRANSACTIONS */ + DBUG_PRINT("info",("event type: %d",event_info->get_type_code())); /* diff --git a/sql/log_event.cc b/sql/log_event.cc index 3a54717a45f..87af8911fb9 100644 --- a/sql/log_event.cc +++ b/sql/log_event.cc @@ -3895,7 +3895,6 @@ int Format_description_log_event::do_apply_event(Relay_log_info const *rli) int ret= 0; DBUG_ENTER("Format_description_log_event::do_apply_event"); -#ifdef USING_TRANSACTIONS /* As a transaction NEVER spans on 2 or more binlogs: if we have an active transaction at this point, the master died @@ -3917,7 +3916,7 @@ int Format_description_log_event::do_apply_event(Relay_log_info const *rli) "its binary log, thus rolled back too."); const_cast(rli)->cleanup_context(thd, 1); } -#endif + /* If this event comes from ourselves, there is no cleaning task to perform, we don't call Start_log_event_v3::do_apply_event() diff --git a/sql/set_var.cc b/sql/set_var.cc index 36597658077..1028e5441ae 100644 --- a/sql/set_var.cc +++ b/sql/set_var.cc @@ -1395,12 +1395,10 @@ static void fix_thd_mem_root(THD *thd, enum_var_type type) static void fix_trans_mem_root(THD *thd, enum_var_type type) { -#ifdef USING_TRANSACTIONS if (type != OPT_GLOBAL) reset_root_defaults(&thd->transaction.mem_root, thd->variables.trans_alloc_block_size, thd->variables.trans_prealloc_size); -#endif } diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 441a3037317..b7d88eca89a 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -936,11 +936,9 @@ void THD::init_for_queries() reset_root_defaults(mem_root, variables.query_alloc_block_size, variables.query_prealloc_size); -#ifdef USING_TRANSACTIONS reset_root_defaults(&transaction.mem_root, variables.trans_alloc_block_size, variables.trans_prealloc_size); -#endif transaction.xid_state.xid.null(); transaction.xid_state.in_thd=1; } @@ -1059,9 +1057,7 @@ THD::~THD() DBUG_PRINT("info", ("freeing security context")); main_security_ctx.destroy(); safeFree(db); -#ifdef USING_TRANSACTIONS free_root(&transaction.mem_root,MYF(0)); -#endif mysys_var=0; // Safety (shouldn't be needed) pthread_mutex_destroy(&LOCK_thd_data); #ifndef DBUG_OFF diff --git a/sql/sql_class.h b/sql/sql_class.h index a968258dd1b..03a92c1a685 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -1434,19 +1434,13 @@ public: */ if (!xid_state.rm_error) xid_state.xid.null(); -#ifdef USING_TRANSACTIONS free_root(&mem_root,MYF(MY_KEEP_PREALLOC)); -#endif } st_transactions() { -#ifdef USING_TRANSACTIONS bzero((char*)this, sizeof(*this)); xid_state.xid.null(); init_sql_alloc(&mem_root, ALLOC_ROOT_MIN_BLOCK_SIZE, 0); -#else - xid_state.xa_state= XA_NOTR; -#endif } } transaction; Field *dup_field; @@ -1932,11 +1926,7 @@ public: } inline bool active_transaction() { -#ifdef USING_TRANSACTIONS return server_status & SERVER_STATUS_IN_TRANS; -#else - return 0; -#endif } inline bool fill_derived_tables() { diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index c2021710d6c..cabfaf14c24 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -511,9 +511,7 @@ static void handle_bootstrap_impl(THD *thd) break; free_root(thd->mem_root,MYF(MY_KEEP_PREALLOC)); -#ifdef USING_TRANSACTIONS free_root(&thd->transaction.mem_root,MYF(MY_KEEP_PREALLOC)); -#endif } DBUG_VOID_RETURN; From 7edfae4e867358c76c3c21815a3f25b07372d319 Mon Sep 17 00:00:00 2001 From: Konstantin Osipov Date: Mon, 23 Nov 2009 19:57:31 +0300 Subject: [PATCH 18/23] Backport of: ------------------------------------------------------------- revno: 2877 committer: Davi Arnaut branch nick: 35164-6.0 timestamp: Wed 2008-10-15 19:53:18 -0300 message: Bug#35164: Large number of invalid pthread_attr_setschedparam calls Bug#37536: Thread scheduling causes performance degradation at low thread count Bug#12702: Long queries take 100% of CPU and freeze other applications under Windows The problem is that although having threads with different priorities yields marginal improvements [1] in some platforms [2], relying on some statically defined priorities (QUERY_PRIOR and WAIT_PRIOR) to play well (or to work at all) with different scheduling practices and disciplines is, at best, a shot in the dark as the meaning of priority values may change depending on the scheduling policy set for the process. Another problem is that increasing priorities can hurt other concurrent (running on the same hardware) applications (such as AMP) by causing starvation problems as MySQL threads will successively preempt lower priority processes. This can be evidenced by Bug#12702. The solution is to not change the threads priorities and rely on the system scheduler to perform its job. This also enables a system admin to increase or decrease the scheduling priority of the MySQL process, if intended. Furthermore, the internal wrappers and code for changing the priority of threads is being removed as they are now unused and ancient. 1. Due to unintentional side effects. On Solaris this could artificially help benchmarks as calling the priority changing syscall millions of times is more beneficial than the actual setting of the priority. 2. Where it actually works. It has never worked on Linux as the default scheduling policy SCHED_OTHER only accepts the static priority 0. --- configure.in | 8 ++--- include/config-netware.h | 1 - include/my_pthread.h | 35 ++------------------ mysys/my_pthread.c | 46 ++------------------------- mysys/thr_alarm.c | 6 ++-- sql/mysql_priv.h | 12 +------ sql/mysqld.cc | 26 +++------------ sql/slave.cc | 9 ++---- sql/slave.h | 3 +- sql/sql_parse.cc | 5 --- sql/sql_prepare.cc | 12 ------- sql/unireg.h | 2 +- storage/innobase/handler/ha_innodb.cc | 7 ---- storage/innobase/include/srv0srv.h | 3 -- storage/innobase/os/os0thread.c | 14 -------- storage/innobase/srv/srv0srv.c | 3 -- 16 files changed, 20 insertions(+), 172 deletions(-) diff --git a/configure.in b/configure.in index 3910422a0f7..aeebb2c5796 100644 --- a/configure.in +++ b/configure.in @@ -2098,11 +2098,9 @@ AC_CHECK_FUNCS(alarm bcmp bfill bmove bsearch bzero \ localtime_r gethrtime gmtime_r \ locking longjmp lrand48 madvise mallinfo memcpy memmove \ mkstemp mlockall perror poll pread pthread_attr_create mmap mmap64 getpagesize \ - pthread_attr_getstacksize pthread_attr_setprio pthread_attr_setschedparam \ - pthread_attr_setstacksize pthread_condattr_create pthread_getsequence_np \ - pthread_key_delete pthread_rwlock_rdlock pthread_setprio \ - pthread_setprio_np pthread_setschedparam pthread_sigmask readlink \ - realpath rename rint rwlock_init setupterm \ + pthread_attr_getstacksize pthread_attr_setstacksize pthread_condattr_create \ + pthread_getsequence_np pthread_key_delete pthread_rwlock_rdlock pthread_sigmask \ + readlink realpath rename rint rwlock_init setupterm \ shmget shmat shmdt shmctl sigaction sigemptyset sigaddset \ sighold sigset sigthreadmask port_create sleep \ snprintf socket stpcpy strcasecmp strerror strsignal strnlen strpbrk strstr \ diff --git a/include/config-netware.h b/include/config-netware.h index 4b9e1437170..adde3c4fbd2 100644 --- a/include/config-netware.h +++ b/include/config-netware.h @@ -73,7 +73,6 @@ extern "C" { #undef HAVE_FINITE #undef HAVE_GETPWNAM #undef HAVE_GETPWUID -#undef HAVE_PTHREAD_SETSCHEDPARAM #undef HAVE_READLINK #undef HAVE_STPCPY /* changes end */ diff --git a/include/my_pthread.h b/include/my_pthread.h index b6d9feae067..eff6d654f2e 100644 --- a/include/my_pthread.h +++ b/include/my_pthread.h @@ -35,7 +35,6 @@ typedef DWORD pthread_t; typedef struct thread_attr { DWORD dwStackSize ; DWORD dwCreatingFlag ; - int priority ; } pthread_attr_t ; typedef struct { int dummy; } pthread_condattr_t; @@ -110,7 +109,6 @@ 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); struct tm *localtime_r(const time_t *timep,struct tm *tmp); struct tm *gmtime_r(const time_t *timep,struct tm *tmp); @@ -141,19 +139,18 @@ int pthread_join(pthread_t thread, void **value_ptr); #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_kill(A,B) pthread_dummy((A) ? 0 : ESRCH) /* 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) +/* per the platform's documentation */ +#define pthread_yield() Sleep(0) #else /* Normal threads */ @@ -181,8 +178,6 @@ 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)) @@ -254,32 +249,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) && !defined (__GNUC__) -/* - Workaround for bug on Solaris where pthread.h have bug in GNU - version of pthread.h => configure says yes, header files says - no. So not used with gcc and issue is Solaris only, so will - be used on Solaris using SunStudio. -*/ -#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 */ diff --git a/mysys/my_pthread.c b/mysys/my_pthread.c index aba3e47d754..ee839e5567e 100644 --- a/mysys/my_pthread.c +++ b/mysys/my_pthread.c @@ -30,47 +30,6 @@ #endif uint thd_lib_detected= 0; - -#ifndef my_pthread_setprio -void my_pthread_setprio(pthread_t thread_id,int prior) -{ -#ifdef HAVE_PTHREAD_SETSCHEDPARAM - struct sched_param tmp_sched_param; - bzero((char*) &tmp_sched_param,sizeof(tmp_sched_param)); - tmp_sched_param.sched_priority=prior; - VOID(pthread_setschedparam(thread_id,SCHED_POLICY,&tmp_sched_param)); -#endif -} -#endif - -#ifndef my_pthread_getprio -int my_pthread_getprio(pthread_t thread_id) -{ -#ifdef HAVE_PTHREAD_SETSCHEDPARAM - struct sched_param tmp_sched_param; - int policy; - if (!pthread_getschedparam(thread_id,&policy,&tmp_sched_param)) - { - return tmp_sched_param.sched_priority; - } -#endif - return -1; -} -#endif - -#ifndef my_pthread_attr_setprio -void my_pthread_attr_setprio(pthread_attr_t *attr, int priority) -{ -#ifdef HAVE_PTHREAD_SETSCHEDPARAM - struct sched_param tmp_sched_param; - bzero((char*) &tmp_sched_param,sizeof(tmp_sched_param)); - tmp_sched_param.sched_priority=priority; - VOID(pthread_attr_setschedparam(attr,&tmp_sched_param)); -#endif -} -#endif - - /* To allow use of pthread_getspecific with two arguments */ #ifdef HAVE_NONPOSIX_PTHREAD_GETSPECIFIC @@ -364,9 +323,8 @@ int sigwait(sigset_t *setp, int *sigp) pthread_attr_setscope(&thr_attr,PTHREAD_SCOPE_PROCESS); pthread_attr_setdetachstate(&thr_attr,PTHREAD_CREATE_DETACHED); pthread_attr_setstacksize(&thr_attr,8196); - my_pthread_attr_setprio(&thr_attr,100); /* Very high priority */ - VOID(pthread_create(&sigwait_thread_id,&thr_attr,sigwait_thread,setp)); - VOID(pthread_attr_destroy(&thr_attr)); + pthread_create(&sigwait_thread_id,&thr_attr,sigwait_thread,setp); + pthread_attr_destroy(&thr_attr); } pthread_mutex_lock(&LOCK_sigwait); diff --git a/mysys/thr_alarm.c b/mysys/thr_alarm.c index b710a7eee39..ead598c025a 100644 --- a/mysys/thr_alarm.c +++ b/mysys/thr_alarm.c @@ -97,10 +97,8 @@ void init_thr_alarm(uint max_alarms) pthread_attr_setscope(&thr_attr,PTHREAD_SCOPE_PROCESS); pthread_attr_setdetachstate(&thr_attr,PTHREAD_CREATE_DETACHED); pthread_attr_setstacksize(&thr_attr,8196); - - my_pthread_attr_setprio(&thr_attr,100); /* Very high priority */ - VOID(pthread_create(&alarm_thread,&thr_attr,alarm_handler,NULL)); - VOID(pthread_attr_destroy(&thr_attr)); + pthread_create(&alarm_thread,&thr_attr,alarm_handler,NULL); + pthread_attr_destroy(&thr_attr); } #elif defined(USE_ONE_SIGNAL_HAND) pthread_sigmask(SIG_BLOCK, &s, NULL); /* used with sigwait() */ diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h index 6d97bfe3f16..c6454679e28 100644 --- a/sql/mysql_priv.h +++ b/sql/mysql_priv.h @@ -428,17 +428,7 @@ protected: #if defined(__WIN__) #undef FLUSH_TIME #define FLUSH_TIME 1800 /**< Flush every half hour */ - -#define INTERRUPT_PRIOR -2 -#define CONNECT_PRIOR -1 -#define WAIT_PRIOR 0 -#define QUERY_PRIOR 2 -#else -#define INTERRUPT_PRIOR 10 -#define CONNECT_PRIOR 9 -#define WAIT_PRIOR 8 -#define QUERY_PRIOR 6 -#endif /* __WIN92__ */ +#endif /* __WIN__ */ /* Bits from testflag */ #define TEST_PRINT_CACHED_TABLES 1 diff --git a/sql/mysqld.cc b/sql/mysqld.cc index ac575865841..f0947601c00 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -48,10 +48,6 @@ #endif #endif -#ifndef DEFAULT_SKIP_THREAD_PRIORITY -#define DEFAULT_SKIP_THREAD_PRIORITY 0 -#endif - #include #include #include @@ -2681,8 +2677,6 @@ static void start_signal_handler(void) #if !defined(HAVE_DEC_3_2_THREADS) pthread_attr_setscope(&thr_attr,PTHREAD_SCOPE_SYSTEM); (void) pthread_attr_setdetachstate(&thr_attr,PTHREAD_CREATE_DETACHED); - if (!(opt_specialflag & SPECIAL_NO_PRIOR)) - my_pthread_attr_setprio(&thr_attr,INTERRUPT_PRIOR); #if defined(__ia64__) || defined(__ia64) /* Peculiar things with ia64 platforms - it seems we only have half the @@ -2802,8 +2796,6 @@ pthread_handler_t signal_hand(void *arg __attribute__((unused))) abort_loop=1; // mark abort for threads #ifdef USE_ONE_SIGNAL_HAND pthread_t tmp; - if (!(opt_specialflag & SPECIAL_NO_PRIOR)) - my_pthread_attr_setprio(&connection_attrib,INTERRUPT_PRIOR); if (pthread_create(&tmp,&connection_attrib, kill_server_thread, (void*) &sig)) sql_print_error("Can't create thread to kill server"); @@ -3629,8 +3621,6 @@ static int init_thread_environment() (void) pthread_attr_setdetachstate(&connection_attrib, PTHREAD_CREATE_DETACHED); pthread_attr_setscope(&connection_attrib, PTHREAD_SCOPE_SYSTEM); - if (!(opt_specialflag & SPECIAL_NO_PRIOR)) - my_pthread_attr_setprio(&connection_attrib,WAIT_PRIOR); if (pthread_key_create(&THR_THD,NULL) || pthread_key_create(&THR_MALLOC,NULL)) @@ -4338,8 +4328,6 @@ int main(int argc, char **argv) unireg_abort(1); // Will do exit init_signals(); - if (!(opt_specialflag & SPECIAL_NO_PRIOR)) - my_pthread_setprio(pthread_self(),CONNECT_PRIOR); #if defined(__ia64__) || defined(__ia64) /* Peculiar things with ia64 platforms - it seems we only have half the @@ -5029,8 +5017,6 @@ void handle_connections_sockets() LINT_INIT(new_sock); - (void) my_pthread_getprio(pthread_self()); // For debugging - FD_ZERO(&clientFDs); if (ip_sock != INVALID_SOCKET) { @@ -6453,8 +6439,9 @@ Can't be set to 1 if --log-slave-updates is used.", {"skip-symlink", OPT_SKIP_SYMLINKS, "Don't allow symlinking of tables. Deprecated option. Use --skip-symbolic-links instead.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, {"skip-thread-priority", OPT_SKIP_PRIOR, - "Don't give threads different priorities. Deprecated option.", 0, 0, 0, GET_NO_ARG, NO_ARG, - DEFAULT_SKIP_THREAD_PRIORITY, 0, 0, 0, 0, 0}, + "Don't give threads different priorities. This option is deprecated " + "because it has no effect; the implied behavior is already the default.", + 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, #ifdef HAVE_REPLICATION {"slave-load-tmpdir", OPT_SLAVE_LOAD_TMPDIR, "The location where the slave should put its temporary files when \ @@ -7922,9 +7909,6 @@ static int mysql_init_variables(void) #ifdef HAVE_SMEM shared_memory_base_name= default_shared_memory_base_name; #endif -#if !defined(my_pthread_setprio) && !defined(HAVE_PTHREAD_SETSCHEDPARAM) - opt_specialflag |= SPECIAL_NO_PRIOR; -#endif #if defined(__WIN__) || defined(__NETWARE__) /* Allow Win32 and NetWare users to move MySQL anywhere */ @@ -8208,8 +8192,8 @@ mysqld_get_one_option(int optid, case (int) OPT_SKIP_PRIOR: opt_specialflag|= SPECIAL_NO_PRIOR; sql_print_warning("The --skip-thread-priority startup option is deprecated " - "and will be removed in MySQL 7.0. MySQL 6.0 and up do not " - "give threads different priorities."); + "and will be removed in MySQL 7.0. This option has no effect " + "as the implied behavior is already the default."); break; case (int) OPT_SKIP_LOCK: opt_external_locking=0; diff --git a/sql/slave.cc b/sql/slave.cc index 8be17860c61..96aa9890c89 100644 --- a/sql/slave.cc +++ b/sql/slave.cc @@ -612,8 +612,7 @@ int start_slave_thread(pthread_handler h_func, pthread_mutex_t *start_lock, pthread_cond_t *start_cond, volatile uint *slave_running, volatile ulong *slave_run_id, - Master_info* mi, - bool high_priority) + Master_info* mi) { pthread_t th; ulong start_id; @@ -643,8 +642,6 @@ int start_slave_thread(pthread_handler h_func, pthread_mutex_t *start_lock, } start_id= *slave_run_id; DBUG_PRINT("info",("Creating new slave thread")); - if (high_priority) - my_pthread_attr_setprio(&connection_attrib,CONNECT_PRIOR); if (pthread_create(&th, &connection_attrib, h_func, (void*)mi)) { if (start_lock) @@ -707,13 +704,13 @@ int start_slave_threads(bool need_slave_mutex, bool wait_for_start, error=start_slave_thread(handle_slave_io,lock_io,lock_cond_io, cond_io, &mi->slave_running, &mi->slave_run_id, - mi, 1); //high priority, to read the most possible + mi); if (!error && (thread_mask & SLAVE_SQL)) { error=start_slave_thread(handle_slave_sql,lock_sql,lock_cond_sql, cond_sql, &mi->rli.slave_running, &mi->rli.slave_run_id, - mi, 0); + mi); if (error) terminate_slave_threads(mi, thread_mask & SLAVE_IO, !need_slave_mutex); } diff --git a/sql/slave.h b/sql/slave.h index eff0fa49f61..8fb44007032 100644 --- a/sql/slave.h +++ b/sql/slave.h @@ -164,8 +164,7 @@ int start_slave_thread(pthread_handler h_func, pthread_mutex_t* start_lock, pthread_cond_t* start_cond, volatile uint *slave_running, volatile ulong *slave_run_id, - Master_info* mi, - bool high_priority); + Master_info* mi); /* If fd is -1, dump to NET */ int mysql_table_dump(THD* thd, const char* db, diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index cabfaf14c24..0aee5e4bd06 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -1228,9 +1228,6 @@ bool dispatch_command(enum enum_server_command command, THD *thd, thd->profiling.set_query_source(thd->query(), thd->query_length()); #endif - if (!(specialflag & SPECIAL_NO_PRIOR)) - my_pthread_setprio(pthread_self(),QUERY_PRIOR); - mysql_parse(thd, thd->query(), thd->query_length(), &end_of_stmt); while (!thd->killed && (end_of_stmt != NULL) && ! thd->is_error()) @@ -1283,8 +1280,6 @@ bool dispatch_command(enum enum_server_command command, THD *thd, mysql_parse(thd, beginning_of_next_stmt, length, &end_of_stmt); } - if (!(specialflag & SPECIAL_NO_PRIOR)) - my_pthread_setprio(pthread_self(),WAIT_PRIOR); DBUG_PRINT("info",("query ready")); break; } diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc index 168934206e5..d624c22f43a 100644 --- a/sql/sql_prepare.cc +++ b/sql/sql_prepare.cc @@ -2615,14 +2615,8 @@ void mysqld_stmt_fetch(THD *thd, char *packet, uint packet_length) thd->stmt_arena= stmt; thd->set_n_backup_statement(stmt, &stmt_backup); - if (!(specialflag & SPECIAL_NO_PRIOR)) - my_pthread_setprio(pthread_self(), QUERY_PRIOR); - cursor->fetch(num_rows); - if (!(specialflag & SPECIAL_NO_PRIOR)) - my_pthread_setprio(pthread_self(), WAIT_PRIOR); - if (!cursor->is_open()) { stmt->close_cursor(); @@ -3386,14 +3380,8 @@ reexecute: thd->m_reprepare_observer = &reprepare_observer; } - if (!(specialflag & SPECIAL_NO_PRIOR)) - my_pthread_setprio(pthread_self(),QUERY_PRIOR); - error= execute(expanded_query, open_cursor) || thd->is_error(); - if (!(specialflag & SPECIAL_NO_PRIOR)) - my_pthread_setprio(pthread_self(), WAIT_PRIOR); - thd->m_reprepare_observer= NULL; if (error && !thd->is_fatal_error && !thd->killed && diff --git a/sql/unireg.h b/sql/unireg.h index a390b755772..80c6ad23907 100644 --- a/sql/unireg.h +++ b/sql/unireg.h @@ -126,7 +126,7 @@ #define SPECIAL_SAME_DB_NAME 16 /* form name = file name */ #define SPECIAL_ENGLISH 32 /* English error messages */ #define SPECIAL_NO_RESOLVE 64 /* Don't use gethostname */ -#define SPECIAL_NO_PRIOR 128 /* Don't prioritize threads */ +#define SPECIAL_NO_PRIOR 128 /* Obsolete */ #define SPECIAL_BIG_SELECTS 256 /* Don't use heap tables */ #define SPECIAL_NO_HOST_CACHE 512 /* Don't cache hosts */ #define SPECIAL_SHORT_LOG_FORMAT 1024 diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc index 851957e53a5..da41f3c7bbc 100644 --- a/storage/innobase/handler/ha_innodb.cc +++ b/storage/innobase/handler/ha_innodb.cc @@ -2046,13 +2046,6 @@ innobase_init( ut_a(default_path); - if (specialflag & SPECIAL_NO_PRIOR) { - srv_set_thread_priorities = FALSE; - } else { - srv_set_thread_priorities = TRUE; - srv_query_thread_priority = QUERY_PRIOR; - } - /* Set InnoDB initialization parameters according to the values read from MySQL .cnf file */ diff --git a/storage/innobase/include/srv0srv.h b/storage/innobase/include/srv0srv.h index 23472bd100e..9804a3e7a85 100644 --- a/storage/innobase/include/srv0srv.h +++ b/storage/innobase/include/srv0srv.h @@ -207,9 +207,6 @@ extern unsigned long long srv_stats_sample_pages; extern ibool srv_use_doublewrite_buf; extern ibool srv_use_checksums; -extern ibool srv_set_thread_priorities; -extern int srv_query_thread_priority; - extern ulong srv_max_buf_pool_modified_pct; extern ulong srv_max_purge_lag; diff --git a/storage/innobase/os/os0thread.c b/storage/innobase/os/os0thread.c index 9a2d95cb166..2cac26fa128 100644 --- a/storage/innobase/os/os0thread.c +++ b/storage/innobase/os/os0thread.c @@ -133,15 +133,6 @@ os_thread_create( 0, /* thread runs immediately */ &win_thread_id); - if (srv_set_thread_priorities) { - - /* Set created thread priority the same as a normal query - in MYSQL: we try to prevent starvation of threads by - assigning same priority QUERY_PRIOR to all */ - - ut_a(SetThreadPriority(thread, srv_query_thread_priority)); - } - if (thread_id) { *thread_id = win_thread_id; } @@ -200,11 +191,6 @@ os_thread_create( #ifndef UNIV_HPUX10 pthread_attr_destroy(&attr); #endif - if (srv_set_thread_priorities) { - - my_pthread_setprio(pthread, srv_query_thread_priority); - } - if (thread_id) { *thread_id = pthread; } diff --git a/storage/innobase/srv/srv0srv.c b/storage/innobase/srv/srv0srv.c index d638b23692e..4722640af3f 100644 --- a/storage/innobase/srv/srv0srv.c +++ b/storage/innobase/srv/srv0srv.c @@ -369,9 +369,6 @@ UNIV_INTERN unsigned long long srv_stats_sample_pages = 8; UNIV_INTERN ibool srv_use_doublewrite_buf = TRUE; UNIV_INTERN ibool srv_use_checksums = TRUE; -UNIV_INTERN ibool srv_set_thread_priorities = TRUE; -UNIV_INTERN int srv_query_thread_priority = 0; - UNIV_INTERN ulong srv_replication_delay = 0; /*-------------------------------------------*/ From 26cd9abe4fcc058004ad8e656ff5b6713c0118f4 Mon Sep 17 00:00:00 2001 From: Konstantin Osipov Date: Mon, 23 Nov 2009 20:08:37 +0300 Subject: [PATCH 19/23] A follow up for the fix for Bug#35164 (remove priorities on Windows). --- mysys/my_wincond.c | 7 ------- 1 file changed, 7 deletions(-) diff --git a/mysys/my_wincond.c b/mysys/my_wincond.c index e7d8073a163..ad1636011db 100644 --- a/mysys/my_wincond.c +++ b/mysys/my_wincond.c @@ -181,7 +181,6 @@ int pthread_attr_init(pthread_attr_t *connect_att) { connect_att->dwStackSize = 0; connect_att->dwCreatingFlag = 0; - connect_att->priority = 0; return 0; } @@ -191,12 +190,6 @@ int pthread_attr_setstacksize(pthread_attr_t *connect_att,DWORD stack) return 0; } -int pthread_attr_setprio(pthread_attr_t *connect_att,int priority) -{ - connect_att->priority=priority; - return 0; -} - int pthread_attr_destroy(pthread_attr_t *connect_att) { bzero((uchar*) connect_att,sizeof(*connect_att)); From 4575f703340f943e856cae6c8fe3371a0ec11e86 Mon Sep 17 00:00:00 2001 From: Alexander Nozdrin Date: Tue, 24 Nov 2009 09:27:16 +0300 Subject: [PATCH 20/23] Remove handle_delayed_insert_impl(). --- sql/sql_insert.cc | 391 +++++++++++++++++++++++----------------------- 1 file changed, 193 insertions(+), 198 deletions(-) diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index b1c7c7f647e..ea125f425a0 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -2291,201 +2291,6 @@ void kill_delayed_threads(void) } -static void handle_delayed_insert_impl(THD *thd, Delayed_insert *di) -{ - DBUG_ENTER("handle_delayed_insert_impl"); - thd->thread_stack= (char*) &thd; - if (init_thr_lock() || thd->store_globals()) - { - /* Can't use my_error since store_globals has perhaps failed */ - thd->stmt_da->set_error_status(thd, ER_OUT_OF_RESOURCES, - ER(ER_OUT_OF_RESOURCES), NULL); - thd->fatal_error(); - goto err; - } - - /* - Open table requires an initialized lex in case the table is - partitioned. The .frm file contains a partial SQL string which is - parsed using a lex, that depends on initialized thd->lex. - */ - lex_start(thd); - thd->lex->sql_command= SQLCOM_INSERT; // For innodb::store_lock() - /* - Statement-based replication of INSERT DELAYED has problems with RAND() - and user vars, so in mixed mode we go to row-based. - */ - thd->lex->set_stmt_unsafe(); - thd->set_current_stmt_binlog_row_based_if_mixed(); - - /* Open table */ - if (!(di->table= open_n_lock_single_table(thd, &di->table_list, - TL_WRITE_DELAYED))) - { - thd->fatal_error(); // Abort waiting inserts - goto err; - } - if (!(di->table->file->ha_table_flags() & HA_CAN_INSERT_DELAYED)) - { - my_error(ER_DELAYED_NOT_SUPPORTED, MYF(ME_FATALERROR), - di->table_list.table_name); - goto err; - } - if (di->table->triggers) - { - /* - Table has triggers. This is not an error, but we do - not support triggers with delayed insert. Terminate the delayed - thread without an error and thus request lock upgrade. - */ - goto err; - } - di->table->copy_blobs=1; - - /* Tell client that the thread is initialized */ - pthread_cond_signal(&di->cond_client); - - /* Now wait until we get an insert or lock to handle */ - /* We will not abort as long as a client thread uses this thread */ - - for (;;) - { - if (thd->killed == THD::KILL_CONNECTION) - { - uint lock_count; - /* - Remove this from delay insert list so that no one can request a - table from this - */ - pthread_mutex_unlock(&di->mutex); - pthread_mutex_lock(&LOCK_delayed_insert); - di->unlink(); - lock_count=di->lock_count(); - pthread_mutex_unlock(&LOCK_delayed_insert); - pthread_mutex_lock(&di->mutex); - if (!lock_count && !di->tables_in_use && !di->stacked_inserts) - break; // Time to die - } - - if (!di->status && !di->stacked_inserts) - { - struct timespec abstime; - set_timespec(abstime, delayed_insert_timeout); - - /* Information for pthread_kill */ - di->thd.mysys_var->current_mutex= &di->mutex; - di->thd.mysys_var->current_cond= &di->cond; - thd_proc_info(&(di->thd), "Waiting for INSERT"); - - DBUG_PRINT("info",("Waiting for someone to insert rows")); - while (!thd->killed) - { - int error; -#if defined(HAVE_BROKEN_COND_TIMEDWAIT) - error=pthread_cond_wait(&di->cond,&di->mutex); -#else - error=pthread_cond_timedwait(&di->cond,&di->mutex,&abstime); -#ifdef EXTRA_DEBUG - if (error && error != EINTR && error != ETIMEDOUT) - { - fprintf(stderr, "Got error %d from pthread_cond_timedwait\n",error); - DBUG_PRINT("error",("Got error %d from pthread_cond_timedwait", - error)); - } -#endif -#endif - if (thd->killed || di->status) - break; - if (error == ETIMEDOUT || error == ETIME) - { - thd->killed= THD::KILL_CONNECTION; - break; - } - } - /* We can't lock di->mutex and mysys_var->mutex at the same time */ - pthread_mutex_unlock(&di->mutex); - pthread_mutex_lock(&di->thd.mysys_var->mutex); - di->thd.mysys_var->current_mutex= 0; - di->thd.mysys_var->current_cond= 0; - pthread_mutex_unlock(&di->thd.mysys_var->mutex); - pthread_mutex_lock(&di->mutex); - } - thd_proc_info(&(di->thd), 0); - - if (di->tables_in_use && ! thd->lock) - { - bool not_used; - /* - Request for new delayed insert. - Lock the table, but avoid to be blocked by a global read lock. - If we got here while a global read lock exists, then one or more - inserts started before the lock was requested. These are allowed - to complete their work before the server returns control to the - client which requested the global read lock. The delayed insert - handler will close the table and finish when the outstanding - inserts are done. - */ - if (! (thd->lock= mysql_lock_tables(thd, &di->table, 1, - MYSQL_LOCK_IGNORE_GLOBAL_READ_LOCK, - ¬_used))) - { - /* Fatal error */ - di->dead= 1; - thd->killed= THD::KILL_CONNECTION; - } - pthread_cond_broadcast(&di->cond_client); - } - if (di->stacked_inserts) - { - if (di->handle_inserts()) - { - /* Some fatal error */ - di->dead= 1; - thd->killed= THD::KILL_CONNECTION; - } - } - di->status=0; - if (!di->stacked_inserts && !di->tables_in_use && thd->lock) - { - /* - No one is doing a insert delayed - Unlock table so that other threads can use it - */ - MYSQL_LOCK *lock=thd->lock; - thd->lock=0; - pthread_mutex_unlock(&di->mutex); - /* - We need to release next_insert_id before unlocking. This is - enforced by handler::ha_external_lock(). - */ - di->table->file->ha_release_auto_increment(); - mysql_unlock_tables(thd, lock); - ha_autocommit_or_rollback(thd, 0); - di->group_count=0; - pthread_mutex_lock(&di->mutex); - } - if (di->tables_in_use) - pthread_cond_broadcast(&di->cond_client); // If waiting clients - } - -err: - /* - mysql_lock_tables() can potentially start a transaction and write - a table map. In the event of an error, that transaction has to be - rolled back. We only need to roll back a potential statement - transaction, since real transactions are rolled back in - close_thread_tables(). - - TODO: This is not true any more, table maps are generated on the - first call to ha_*_row() instead. Remove code that are used to - cover for the case outlined above. - */ - ha_autocommit_or_rollback(thd, 1); - - DBUG_VOID_RETURN; -} - - /* * Create a new delayed insert thread */ @@ -2518,11 +2323,201 @@ pthread_handler_t handle_delayed_insert(void *arg) /* Can't use my_error since store_globals has not yet been called */ thd->stmt_da->set_error_status(thd, ER_OUT_OF_RESOURCES, ER(ER_OUT_OF_RESOURCES), NULL); - goto end; } - handle_delayed_insert_impl(thd, di); + else + { + DBUG_ENTER("handle_delayed_insert"); + thd->thread_stack= (char*) &thd; + if (init_thr_lock() || thd->store_globals()) + { + /* Can't use my_error since store_globals has perhaps failed */ + thd->stmt_da->set_error_status(thd, ER_OUT_OF_RESOURCES, + ER(ER_OUT_OF_RESOURCES), NULL); + thd->fatal_error(); + goto err; + } + + /* + Open table requires an initialized lex in case the table is + partitioned. The .frm file contains a partial SQL string which is + parsed using a lex, that depends on initialized thd->lex. + */ + lex_start(thd); + thd->lex->sql_command= SQLCOM_INSERT; // For innodb::store_lock() + /* + Statement-based replication of INSERT DELAYED has problems with RAND() + and user vars, so in mixed mode we go to row-based. + */ + thd->lex->set_stmt_unsafe(); + thd->set_current_stmt_binlog_row_based_if_mixed(); + + /* Open table */ + if (!(di->table= open_n_lock_single_table(thd, &di->table_list, + TL_WRITE_DELAYED))) + { + thd->fatal_error(); // Abort waiting inserts + goto err; + } + if (!(di->table->file->ha_table_flags() & HA_CAN_INSERT_DELAYED)) + { + my_error(ER_DELAYED_NOT_SUPPORTED, MYF(ME_FATALERROR), + di->table_list.table_name); + goto err; + } + if (di->table->triggers) + { + /* + Table has triggers. This is not an error, but we do + not support triggers with delayed insert. Terminate the delayed + thread without an error and thus request lock upgrade. + */ + goto err; + } + di->table->copy_blobs=1; + + /* Tell client that the thread is initialized */ + pthread_cond_signal(&di->cond_client); + + /* Now wait until we get an insert or lock to handle */ + /* We will not abort as long as a client thread uses this thread */ + + for (;;) + { + if (thd->killed == THD::KILL_CONNECTION) + { + uint lock_count; + /* + Remove this from delay insert list so that no one can request a + table from this + */ + pthread_mutex_unlock(&di->mutex); + pthread_mutex_lock(&LOCK_delayed_insert); + di->unlink(); + lock_count=di->lock_count(); + pthread_mutex_unlock(&LOCK_delayed_insert); + pthread_mutex_lock(&di->mutex); + if (!lock_count && !di->tables_in_use && !di->stacked_inserts) + break; // Time to die + } + + if (!di->status && !di->stacked_inserts) + { + struct timespec abstime; + set_timespec(abstime, delayed_insert_timeout); + + /* Information for pthread_kill */ + di->thd.mysys_var->current_mutex= &di->mutex; + di->thd.mysys_var->current_cond= &di->cond; + thd_proc_info(&(di->thd), "Waiting for INSERT"); + + DBUG_PRINT("info",("Waiting for someone to insert rows")); + while (!thd->killed) + { + int error; +#if defined(HAVE_BROKEN_COND_TIMEDWAIT) + error=pthread_cond_wait(&di->cond,&di->mutex); +#else + error=pthread_cond_timedwait(&di->cond,&di->mutex,&abstime); +#ifdef EXTRA_DEBUG + if (error && error != EINTR && error != ETIMEDOUT) + { + fprintf(stderr, "Got error %d from pthread_cond_timedwait\n",error); + DBUG_PRINT("error",("Got error %d from pthread_cond_timedwait", + error)); + } +#endif +#endif + if (thd->killed || di->status) + break; + if (error == ETIMEDOUT || error == ETIME) + { + thd->killed= THD::KILL_CONNECTION; + break; + } + } + /* We can't lock di->mutex and mysys_var->mutex at the same time */ + pthread_mutex_unlock(&di->mutex); + pthread_mutex_lock(&di->thd.mysys_var->mutex); + di->thd.mysys_var->current_mutex= 0; + di->thd.mysys_var->current_cond= 0; + pthread_mutex_unlock(&di->thd.mysys_var->mutex); + pthread_mutex_lock(&di->mutex); + } + thd_proc_info(&(di->thd), 0); + + if (di->tables_in_use && ! thd->lock) + { + bool not_used; + /* + Request for new delayed insert. + Lock the table, but avoid to be blocked by a global read lock. + If we got here while a global read lock exists, then one or more + inserts started before the lock was requested. These are allowed + to complete their work before the server returns control to the + client which requested the global read lock. The delayed insert + handler will close the table and finish when the outstanding + inserts are done. + */ + if (! (thd->lock= mysql_lock_tables(thd, &di->table, 1, + MYSQL_LOCK_IGNORE_GLOBAL_READ_LOCK, + ¬_used))) + { + /* Fatal error */ + di->dead= 1; + thd->killed= THD::KILL_CONNECTION; + } + pthread_cond_broadcast(&di->cond_client); + } + if (di->stacked_inserts) + { + if (di->handle_inserts()) + { + /* Some fatal error */ + di->dead= 1; + thd->killed= THD::KILL_CONNECTION; + } + } + di->status=0; + if (!di->stacked_inserts && !di->tables_in_use && thd->lock) + { + /* + No one is doing a insert delayed + Unlock table so that other threads can use it + */ + MYSQL_LOCK *lock=thd->lock; + thd->lock=0; + pthread_mutex_unlock(&di->mutex); + /* + We need to release next_insert_id before unlocking. This is + enforced by handler::ha_external_lock(). + */ + di->table->file->ha_release_auto_increment(); + mysql_unlock_tables(thd, lock); + ha_autocommit_or_rollback(thd, 0); + di->group_count=0; + pthread_mutex_lock(&di->mutex); + } + if (di->tables_in_use) + pthread_cond_broadcast(&di->cond_client); // If waiting clients + } + + err: + /* + mysql_lock_tables() can potentially start a transaction and write + a table map. In the event of an error, that transaction has to be + rolled back. We only need to roll back a potential statement + transaction, since real transactions are rolled back in + close_thread_tables(). + + TODO: This is not true any more, table maps are generated on the + first call to ha_*_row() instead. Remove code that are used to + cover for the case outlined above. + */ + ha_autocommit_or_rollback(thd, 1); + + DBUG_LEAVE; + } -end: /* di should be unlinked from the thread handler list and have no active clients From 4cff617c2541279a53b92acbd4e4d8716dc54873 Mon Sep 17 00:00:00 2001 From: Konstantin Osipov Date: Tue, 24 Nov 2009 16:54:59 +0300 Subject: [PATCH 21/23] Backport of: ---------------------------------------------------------------------- ChangeSet@1.2571, 2008-04-08 12:30:06+02:00, vvaintroub@wva. +122 -0 Bug#32082 : definition of VOID in my_global.h conflicts with Windows SDK headers VOID macro is now removed. Its usage is replaced with void cast. In some cases, where cast does not make much sense (pthread_*, printf, hash_delete, my_seek), cast is ommited. --- client/mysqladmin.cc | 4 +- client/mysqldump.c | 10 +- client/mysqlimport.c | 8 +- client/mysqlslap.c | 16 +- client/mysqltest.cc | 8 +- client/sql_string.cc | 2 +- extra/comp_err.c | 8 +- extra/replace.c | 4 +- include/my_alarm.h | 10 +- include/my_global.h | 11 -- libmysql/libmysql.c | 2 +- mysys/errors.c | 2 +- mysys/hash.c | 2 +- mysys/mf_iocache2.c | 4 +- mysys/mf_loadpath.c | 8 +- mysys/mf_path.c | 6 +- mysys/my_append.c | 4 +- mysys/my_clock.c | 2 +- mysys/my_copy.c | 8 +- mysys/my_fstream.c | 4 +- mysys/my_getwd.c | 2 +- mysys/my_lib.c | 22 +-- mysys/my_lockmem.c | 4 +- mysys/my_pthread.c | 5 +- mysys/my_redel.c | 6 +- mysys/stacktrace.c | 3 - mysys/thr_alarm.c | 16 +- mysys/thr_lock.c | 18 +-- sql/derror.cc | 6 +- sql/des_key_file.cc | 4 +- sql/discover.cc | 4 +- sql/field.cc | 4 +- sql/filesort.cc | 2 +- sql/ha_ndbcluster.cc | 4 +- sql/ha_partition.cc | 28 ++-- sql/handler.cc | 6 +- sql/hostname.cc | 28 ++-- sql/init.cc | 2 +- sql/item.cc | 2 +- sql/item_cmpfunc.cc | 2 +- sql/item_strfunc.cc | 12 +- sql/lock.cc | 14 +- sql/log.cc | 20 +-- sql/log_event.cc | 8 +- sql/mysqld.cc | 12 +- sql/opt_range.h | 2 +- sql/protocol.cc | 3 + sql/records.cc | 6 +- sql/sp_head.cc | 8 +- sql/sp_pcontext.cc | 40 ++--- sql/sql_acl.cc | 101 ++++++------ sql/sql_base.cc | 108 ++++++------- sql/sql_cache.cc | 17 +- sql/sql_connect.cc | 2 +- sql/sql_db.cc | 16 +- sql/sql_delete.cc | 12 +- sql/sql_handler.cc | 4 +- sql/sql_insert.cc | 20 +-- sql/sql_map.cc | 16 +- sql/sql_parse.cc | 20 +-- sql/sql_select.cc | 10 +- sql/sql_servers.cc | 6 +- sql/sql_show.cc | 22 +-- sql/sql_string.cc | 2 +- sql/sql_table.cc | 108 +++++++------ sql/sql_test.cc | 28 ++-- sql/sql_trigger.cc | 4 +- sql/sql_update.cc | 4 +- sql/sql_view.cc | 8 +- sql/table.cc | 30 ++-- sql/tztime.cc | 8 +- sql/udf_example.c | 12 +- sql/uniques.cc | 4 +- sql/unireg.cc | 14 +- storage/archive/ha_archive.cc | 12 +- storage/blackhole/ha_blackhole.cc | 2 +- storage/csv/ha_tina.cc | 6 +- storage/csv/transparent_file.cc | 4 +- storage/example/ha_example.cc | 2 +- storage/federated/ha_federated.cc | 6 +- storage/heap/hp_clear.c | 6 +- storage/heap/hp_create.c | 4 +- storage/heap/hp_test1.c | 2 +- storage/heap/hp_test2.c | 2 +- storage/innobase/handler/ha_innodb.cc | 4 +- storage/myisam/ft_eval.c | 4 +- storage/myisam/ha_myisam.cc | 12 +- storage/myisam/mi_changed.c | 2 +- storage/myisam/mi_check.c | 70 ++++---- storage/myisam/mi_close.c | 6 +- storage/myisam/mi_create.c | 4 +- storage/myisam/mi_dbug.c | 36 ++--- storage/myisam/mi_delete.c | 4 +- storage/myisam/mi_delete_all.c | 4 +- storage/myisam/mi_dynrec.c | 10 +- storage/myisam/mi_info.c | 2 +- storage/myisam/mi_locking.c | 18 +-- storage/myisam/mi_log.c | 14 +- storage/myisam/mi_open.c | 16 +- storage/myisam/mi_packrec.c | 6 +- storage/myisam/mi_panic.c | 2 +- storage/myisam/mi_rsame.c | 4 +- storage/myisam/mi_statrec.c | 2 +- storage/myisam/mi_test1.c | 6 +- storage/myisam/mi_test2.c | 2 +- storage/myisam/mi_test3.c | 2 +- storage/myisam/mi_update.c | 4 +- storage/myisam/mi_write.c | 4 +- storage/myisam/myisamchk.c | 86 +++++----- storage/myisam/myisamlog.c | 50 +++--- storage/myisam/myisampack.c | 220 +++++++++++++------------- storage/myisam/sort.c | 2 +- storage/myisammrg/myrg_close.c | 2 +- storage/myisammrg/myrg_create.c | 2 +- storage/myisammrg/myrg_open.c | 24 +-- strings/str_test.c | 16 +- tests/thread_test.c | 2 +- 117 files changed, 835 insertions(+), 845 deletions(-) diff --git a/client/mysqladmin.cc b/client/mysqladmin.cc index 500a890a9ab..808919fbd0c 100644 --- a/client/mysqladmin.cc +++ b/client/mysqladmin.cc @@ -325,8 +325,8 @@ int main(int argc,char *argv[]) if (tty_password) opt_password = get_tty_password(NullS); - VOID(signal(SIGINT,endprog)); /* Here if abort */ - VOID(signal(SIGTERM,endprog)); /* Here if abort */ + (void) signal(SIGINT,endprog); /* Here if abort */ + (void) signal(SIGTERM,endprog); /* Here if abort */ if (opt_compress) mysql_options(&mysql,MYSQL_OPT_COMPRESS,NullS); diff --git a/client/mysqldump.c b/client/mysqldump.c index 95206802fd7..ebf0add4590 100644 --- a/client/mysqldump.c +++ b/client/mysqldump.c @@ -2001,7 +2001,7 @@ static uint dump_events_for_db(char *db) mysql_free_result(event_list_res); if (lock_tables) - VOID(mysql_query_with_error_report(mysql, 0, "UNLOCK TABLES")); + (void) mysql_query_with_error_report(mysql, 0, "UNLOCK TABLES"); DBUG_RETURN(0); } @@ -2204,7 +2204,7 @@ static uint dump_routines_for_db(char *db) DBUG_RETURN(1); if (lock_tables) - VOID(mysql_query_with_error_report(mysql, 0, "UNLOCK TABLES")); + (void) mysql_query_with_error_report(mysql, 0, "UNLOCK TABLES"); DBUG_RETURN(0); } @@ -4086,7 +4086,7 @@ static int dump_all_tables_in_db(char *database) check_io(md_result_file); } if (lock_tables) - VOID(mysql_query_with_error_report(mysql, 0, "UNLOCK TABLES")); + (void) mysql_query_with_error_report(mysql, 0, "UNLOCK TABLES"); if (flush_privileges && using_mysql_db == 0) { fprintf(md_result_file,"\n--\n-- Flush Grant Tables \n--\n"); @@ -4160,7 +4160,7 @@ static my_bool dump_all_views_in_db(char *database) check_io(md_result_file); } if (lock_tables) - VOID(mysql_query_with_error_report(mysql, 0, "UNLOCK TABLES")); + (void) mysql_query_with_error_report(mysql, 0, "UNLOCK TABLES"); return 0; } /* dump_all_tables_in_db */ @@ -4332,7 +4332,7 @@ static int dump_selected_tables(char *db, char **table_names, int tables) check_io(md_result_file); } if (lock_tables) - VOID(mysql_query_with_error_report(mysql, 0, "UNLOCK TABLES")); + (void) mysql_query_with_error_report(mysql, 0, "UNLOCK TABLES"); DBUG_RETURN(0); } /* dump_selected_tables */ diff --git a/client/mysqlimport.c b/client/mysqlimport.c index 5b8ec95c06d..969cff929d2 100644 --- a/client/mysqlimport.c +++ b/client/mysqlimport.c @@ -610,8 +610,8 @@ int main(int argc, char **argv) pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); - VOID(pthread_mutex_init(&counter_mutex, NULL)); - VOID(pthread_cond_init(&count_threshhold, NULL)); + pthread_mutex_init(&counter_mutex, NULL); + pthread_cond_init(&count_threshhold, NULL); for (counter= 0; *argv != NULL; argv++) /* Loop through tables */ { @@ -650,8 +650,8 @@ int main(int argc, char **argv) pthread_cond_timedwait(&count_threshhold, &counter_mutex, &abstime); } pthread_mutex_unlock(&counter_mutex); - VOID(pthread_mutex_destroy(&counter_mutex)); - VOID(pthread_cond_destroy(&count_threshhold)); + pthread_mutex_destroy(&counter_mutex); + pthread_cond_destroy(&count_threshhold); pthread_attr_destroy(&attr); } else diff --git a/client/mysqlslap.c b/client/mysqlslap.c index f13b5099766..21b40824be7 100644 --- a/client/mysqlslap.c +++ b/client/mysqlslap.c @@ -352,10 +352,10 @@ int main(int argc, char **argv) } } - VOID(pthread_mutex_init(&counter_mutex, NULL)); - VOID(pthread_cond_init(&count_threshhold, NULL)); - VOID(pthread_mutex_init(&sleeper_mutex, NULL)); - VOID(pthread_cond_init(&sleep_threshhold, NULL)); + pthread_mutex_init(&counter_mutex, NULL); + pthread_cond_init(&count_threshhold, NULL); + pthread_mutex_init(&sleeper_mutex, NULL); + pthread_cond_init(&sleep_threshhold, NULL); /* Main iterations loop */ eptr= engine_options; @@ -386,10 +386,10 @@ int main(int argc, char **argv) } while (eptr ? (eptr= eptr->next) : 0); - VOID(pthread_mutex_destroy(&counter_mutex)); - VOID(pthread_cond_destroy(&count_threshhold)); - VOID(pthread_mutex_destroy(&sleeper_mutex)); - VOID(pthread_cond_destroy(&sleep_threshhold)); + pthread_mutex_destroy(&counter_mutex); + pthread_cond_destroy(&count_threshhold); + pthread_mutex_destroy(&sleeper_mutex); + pthread_cond_destroy(&sleep_threshhold); if (!opt_only_print) mysql_close(&mysql); /* Close & free connection */ diff --git a/client/mysqltest.cc b/client/mysqltest.cc index a4c526be70c..a6d7c7c1a8e 100644 --- a/client/mysqltest.cc +++ b/client/mysqltest.cc @@ -696,12 +696,12 @@ pthread_handler_t send_one_query(void *arg) struct st_connection *cn= (struct st_connection*)arg; mysql_thread_init(); - VOID(mysql_send_query(&cn->mysql, cn->cur_query, cn->cur_query_len)); + (void) mysql_send_query(&cn->mysql, cn->cur_query, cn->cur_query_len); mysql_thread_end(); pthread_mutex_lock(&cn->mutex); cn->query_done= 1; - VOID(pthread_cond_signal(&cn->cond)); + pthread_cond_signal(&cn->cond); pthread_mutex_unlock(&cn->mutex); pthread_exit(0); return 0; @@ -9063,7 +9063,7 @@ REPLACE *init_replace(char * *from, char * *to,uint count, free_sets(&sets); DBUG_RETURN(0); } - VOID(make_new_set(&sets)); /* Set starting set */ + (void) make_new_set(&sets); /* Set starting set */ make_sets_invisible(&sets); /* Hide previus sets */ used_sets=-1; word_states=make_new_set(&sets); /* Start of new word */ @@ -9534,7 +9534,7 @@ int insert_pointer_name(reg1 POINTER_ARRAY *pa,char * name) pa->flag[pa->typelib.count]=0; /* Reset flag */ pa->typelib.type_names[pa->typelib.count++]= (char*) pa->str+pa->length; pa->typelib.type_names[pa->typelib.count]= NullS; /* Put end-mark */ - VOID(strmov((char*) pa->str+pa->length,name)); + (void) strmov((char*) pa->str+pa->length,name); pa->length+=length; DBUG_RETURN(0); } /* insert_pointer_name */ diff --git a/client/sql_string.cc b/client/sql_string.cc index 46fd1cb0012..3292bc7e6f2 100644 --- a/client/sql_string.cc +++ b/client/sql_string.cc @@ -130,7 +130,7 @@ bool String::set(double num,uint decimals, CHARSET_INFO *cs) int decpt,sign; char *pos,*to; - VOID(fconvert(num,(int) decimals,&decpt,&sign,buff+1)); + (void) fconvert(num,(int) decimals,&decpt,&sign,buff+1); if (!my_isdigit(&my_charset_latin1, buff[1])) { // Nan or Inf pos=buff+1; diff --git a/extra/comp_err.c b/extra/comp_err.c index 405f745eaf3..4bcd4c74a1d 100644 --- a/extra/comp_err.c +++ b/extra/comp_err.c @@ -1039,11 +1039,11 @@ static char *parse_text_line(char *pos) switch (*++pos) { case '\\': case '"': - VOID(strmov(pos - 1, pos)); + (void) strmov(pos - 1, pos); break; case 'n': pos[-1]= '\n'; - VOID(strmov(pos, pos + 1)); + (void) strmov(pos, pos + 1); break; default: if (*pos >= '0' && *pos < '8') @@ -1053,10 +1053,10 @@ static char *parse_text_line(char *pos) nr= nr * 8 + (*(pos++) - '0'); pos -= i; pos[-1]= nr; - VOID(strmov(pos, pos + i)); + (void) strmov(pos, pos + i); } else if (*pos) - VOID(strmov(pos - 1, pos)); /* Remove '\' */ + (void) strmov(pos - 1, pos); /* Remove '\' */ } } else diff --git a/extra/replace.c b/extra/replace.c index 9b7695eddcb..3f07183807c 100644 --- a/extra/replace.c +++ b/extra/replace.c @@ -311,7 +311,7 @@ static int insert_pointer_name(reg1 POINTER_ARRAY *pa,char * name) pa->flag[pa->typelib.count]=0; /* Reset flag */ pa->typelib.type_names[pa->typelib.count++]= (char*) (pa->str+pa->length); pa->typelib.type_names[pa->typelib.count]= NullS; /* Put end-mark */ - VOID(strmov((char*) pa->str + pa->length, name)); + (void) strmov((char*) pa->str + pa->length, name); pa->length+=length; DBUG_RETURN(0); } /* insert_pointer_name */ @@ -433,7 +433,7 @@ static REPLACE *init_replace(char * *from, char * *to,uint count, free_sets(&sets); DBUG_RETURN(0); } - VOID(make_new_set(&sets)); /* Set starting set */ + (void) make_new_set(&sets); /* Set starting set */ make_sets_invisible(&sets); /* Hide previus sets */ used_sets=-1; word_states=make_new_set(&sets); /* Start of new word */ diff --git a/include/my_alarm.h b/include/my_alarm.h index 750135d64ed..dd2d5642f5f 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 DONT_REMEMBER_SIGNAL -#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 /* DONT_REMEMBER_SIGNAL */ #else diff --git a/include/my_global.h b/include/my_global.h index f6d1592fc6f..815be622b16 100644 --- a/include/my_global.h +++ b/include/my_global.h @@ -542,17 +542,6 @@ extern "C" int madvise(void *addr, size_t len, int behav); #define DONT_REMEMBER_SIGNAL #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 */ - #if defined(_lint) || defined(FORCE_INIT_OF_VARS) #define LINT_INIT(var) var=0 /* No uninitialize-warning */ #else diff --git a/libmysql/libmysql.c b/libmysql/libmysql.c index 820c64cf84b..c4f16527551 100644 --- a/libmysql/libmysql.c +++ b/libmysql/libmysql.c @@ -556,7 +556,7 @@ my_bool handle_local_infile(MYSQL *mysql, const char *net_filename) if ((*options->local_infile_init)(&li_ptr, net_filename, options->local_infile_userdata)) { - VOID(my_net_write(net,(const uchar*) "",0)); /* Server needs one packet */ + (void) my_net_write(net,(const uchar*) "",0); /* Server needs one packet */ net_flush(net); strmov(net->sqlstate, unknown_sqlstate); net->last_errno= diff --git a/mysys/errors.c b/mysys/errors.c index 4000c5c4e52..37d33374fe1 100644 --- a/mysys/errors.c +++ b/mysys/errors.c @@ -104,7 +104,7 @@ void wait_for_free_space(const char *filename, int errors) MYF(ME_BELL | ME_NOREFRESH), MY_WAIT_FOR_USER_TO_FIX_PANIC, MY_WAIT_GIVE_USER_A_MESSAGE * MY_WAIT_FOR_USER_TO_FIX_PANIC ); - VOID(sleep(MY_WAIT_FOR_USER_TO_FIX_PANIC)); + (void) sleep(MY_WAIT_FOR_USER_TO_FIX_PANIC); } const char **get_global_errmsgs() diff --git a/mysys/hash.c b/mysys/hash.c index 9c1957bf0aa..6996b045d1c 100644 --- a/mysys/hash.c +++ b/mysys/hash.c @@ -541,7 +541,7 @@ my_bool my_hash_delete(HASH *hash, uchar *record) pos->next=empty_index; exit: - VOID(pop_dynamic(&hash->array)); + (void) pop_dynamic(&hash->array); if (hash->free) (*hash->free)((uchar*) record); DBUG_RETURN(0); diff --git a/mysys/mf_iocache2.c b/mysys/mf_iocache2.c index c54c7d13548..705a3fc46ec 100644 --- a/mysys/mf_iocache2.c +++ b/mysys/mf_iocache2.c @@ -135,7 +135,7 @@ void my_b_seek(IO_CACHE *info,my_off_t pos) b) see if there is a better way to make it work */ if (info->type == SEQ_READ_APPEND) - VOID(flush_io_cache(info)); + (void) flush_io_cache(info); offset=(pos - info->pos_in_file); @@ -163,7 +163,7 @@ void my_b_seek(IO_CACHE *info,my_off_t pos) info->write_pos = info->write_buffer + offset; DBUG_VOID_RETURN; } - VOID(flush_io_cache(info)); + (void) flush_io_cache(info); /* Correct buffer end so that we write in increments of IO_SIZE */ info->write_end=(info->write_buffer+info->buffer_length- (pos & (IO_SIZE-1))); diff --git a/mysys/mf_loadpath.c b/mysys/mf_loadpath.c index 48a69207839..fbf6f7f5d57 100644 --- a/mysys/mf_loadpath.c +++ b/mysys/mf_loadpath.c @@ -34,7 +34,7 @@ char * my_load_path(char * to, const char *path, if ((path[0] == FN_HOMELIB && path[1] == FN_LIBCHAR) || test_if_hard_path(path)) - VOID(strmov(buff,path)); + (void) strmov(buff,path); else if ((is_cur=(path[0] == FN_CURLIB && path[1] == FN_LIBCHAR)) || (is_prefix(path,FN_PARENTDIR)) || ! own_path_prefix) @@ -42,12 +42,12 @@ char * my_load_path(char * to, const char *path, if (is_cur) is_cur=2; /* Remove current dir */ if (! my_getwd(buff,(uint) (FN_REFLEN-strlen(path)+is_cur),MYF(0))) - VOID(strcat(buff,path+is_cur)); + (void) strcat(buff,path+is_cur); else - VOID(strmov(buff,path)); /* Return org file name */ + (void) strmov(buff,path); /* Return org file name */ } else - VOID(strxmov(buff,own_path_prefix,path,NullS)); + (void) strxmov(buff,own_path_prefix,path,NullS); strmov(to,buff); DBUG_PRINT("exit",("to: %s",to)); DBUG_RETURN(to); diff --git a/mysys/mf_path.c b/mysys/mf_path.c index 73e73cb7f76..d51cac732f5 100644 --- a/mysys/mf_path.c +++ b/mysys/mf_path.c @@ -42,7 +42,7 @@ char * my_path(char * to, const char *progname, ((prog=getenv("_")) != 0 && dirname_part(to, prog, &to_length)))) { - VOID(intern_filename(to,to)); + (void) intern_filename(to,to); if (!test_if_hard_path(to)) { if (!my_getwd(curr_dir,FN_REFLEN,MYF(0))) @@ -60,11 +60,11 @@ char * my_path(char * to, const char *progname, end= (char*) "/my/"; #endif } - VOID(intern_filename(to,end)); + (void) intern_filename(to,end); to=strend(to); if (to != start && to[-1] != FN_LIBCHAR) *to++ = FN_LIBCHAR; - VOID(strmov(to,own_pathname_part)); + (void) strmov(to,own_pathname_part); } DBUG_PRINT("exit",("to: '%s'",start)); DBUG_RETURN(start); diff --git a/mysys/my_append.c b/mysys/my_append.c index d8789f95d95..1ef3905b6f5 100644 --- a/mysys/my_append.c +++ b/mysys/my_append.c @@ -58,7 +58,7 @@ int my_append(const char *from, const char *to, myf MyFlags) } } err: - if (from_file >= 0) VOID(my_close(from_file,MyFlags)); - if (to_file >= 0) VOID(my_close(to_file,MyFlags)); + if (from_file >= 0) (void) my_close(from_file,MyFlags); + if (to_file >= 0) (void) my_close(to_file,MyFlags); DBUG_RETURN(-1); } diff --git a/mysys/my_clock.c b/mysys/my_clock.c index adc755028d5..d17f26ed316 100644 --- a/mysys/my_clock.c +++ b/mysys/my_clock.c @@ -24,7 +24,7 @@ long my_clock(void) { #if !defined(__WIN__) && !defined(__NETWARE__) struct tms tmsbuf; - VOID(times(&tmsbuf)); + (void) times(&tmsbuf); return (tmsbuf.tms_utime + tmsbuf.tms_stime); #else return clock(); diff --git a/mysys/my_copy.c b/mysys/my_copy.c index 418e2b6f8a2..d38507c111a 100644 --- a/mysys/my_copy.c +++ b/mysys/my_copy.c @@ -112,19 +112,19 @@ int my_copy(const char *from, const char *to, myf MyFlags) struct utimbuf timep; timep.actime = stat_buff.st_atime; timep.modtime = stat_buff.st_mtime; - VOID(utime((char*) to, &timep)); /* last accessed and modified times */ + (void) utime((char*) to, &timep); /* last accessed and modified times */ } #endif DBUG_RETURN(0); } err: - if (from_file >= 0) VOID(my_close(from_file,MyFlags)); + if (from_file >= 0) (void) my_close(from_file,MyFlags); if (to_file >= 0) { - VOID(my_close(to_file, MyFlags)); + (void) my_close(to_file, MyFlags); /* attempt to delete the to-file we've partially written */ - VOID(my_delete(to, MyFlags)); + (void) my_delete(to, MyFlags); } DBUG_RETURN(-1); } /* my_copy */ diff --git a/mysys/my_fstream.c b/mysys/my_fstream.c index 2059e1a9f18..0c7e4ef7aa3 100644 --- a/mysys/my_fstream.c +++ b/mysys/my_fstream.c @@ -119,7 +119,7 @@ size_t my_fwrite(FILE *stream, const uchar *Buffer, size_t Count, myf MyFlags) #ifdef EINTR if (errno == EINTR) { - VOID(my_fseek(stream,seekptr,MY_SEEK_SET,MYF(0))); + (void) my_fseek(stream,seekptr,MY_SEEK_SET,MYF(0)); continue; } #endif @@ -133,7 +133,7 @@ size_t my_fwrite(FILE *stream, const uchar *Buffer, size_t Count, myf MyFlags) { wait_for_free_space("[stream]", errors); errors++; - VOID(my_fseek(stream,seekptr,MY_SEEK_SET,MYF(0))); + (void) my_fseek(stream,seekptr,MY_SEEK_SET,MYF(0)); continue; } #endif diff --git a/mysys/my_getwd.c b/mysys/my_getwd.c index e0c5b94b53e..6ef8d571492 100644 --- a/mysys/my_getwd.c +++ b/mysys/my_getwd.c @@ -51,7 +51,7 @@ int my_getwd(char * buf, size_t size, myf MyFlags) (long) buf, (uint) size, MyFlags)); if (curr_dir[0]) /* Current pos is saved here */ - VOID(strmake(buf,&curr_dir[0],size-1)); + (void) strmake(buf,&curr_dir[0],size-1); else { #if defined(HAVE_GETCWD) diff --git a/mysys/my_lib.c b/mysys/my_lib.c index 033f8789b49..dcc1263f383 100644 --- a/mysys/my_lib.c +++ b/mysys/my_lib.c @@ -159,8 +159,8 @@ MY_DIR *my_dir(const char *path, myf MyFlags) goto error; bzero(finfo.mystat, sizeof(MY_STAT)); - VOID(strmov(tmp_file,dp->d_name)); - VOID(my_stat(tmp_path, finfo.mystat, MyFlags)); + (void) strmov(tmp_file,dp->d_name); + (void) my_stat(tmp_path, finfo.mystat, MyFlags); if (!(finfo.mystat->st_mode & MY_S_IREAD)) continue; } @@ -266,7 +266,7 @@ char * directory_file_name (char * dst, const char *src) /* what about when we have logical_name:???? */ if (src[slen] == FN_DEVCHAR) { /* Xlate logical name and see what we get */ - VOID(strmov(dst,src)); + (void) strmov(dst,src); dst[slen] = 0; /* remove colon */ if (!(src = getenv (dst))) return dst; /* Can't translate */ @@ -282,13 +282,13 @@ char * directory_file_name (char * dst, const char *src) slen = strlen (src) - 1; if (src[slen] != FN_C_AFTER_DIR && src[slen] != FN_C_AFTER_DIR_2) { /* no recursion here! */ - VOID(strmov(dst, src)); + (void) strmov(dst, src); return(dst); } } else { /* not a directory spec */ - VOID(strmov(dst, src)); + (void) strmov(dst, src); return(dst); } } @@ -296,13 +296,13 @@ char * directory_file_name (char * dst, const char *src) bracket = src[slen]; /* End char */ if (!(ptr = strchr (src, bracket - 2))) { /* no opening bracket */ - VOID(strmov (dst, src)); + (void) strmov (dst, src); return dst; } if (!(rptr = strrchr (src, '.'))) rptr = ptr; slen = rptr - src; - VOID(strmake (dst, src, slen)); + (void) strmake (dst, src, slen); if (*rptr == '.') { /* Put bracket and add */ @@ -323,7 +323,7 @@ char * directory_file_name (char * dst, const char *src) && (ptr[rlen] == FN_C_AFTER_DIR || ptr[rlen] == FN_C_AFTER_DIR_2) && ptr[rlen - 1] == '.') { - VOID(strmov(esa,ptr)); + (void) strmov(esa,ptr); esa[rlen - 1] = FN_C_AFTER_DIR; esa[rlen] = '\0'; return (directory_file_name (dst, esa)); @@ -331,13 +331,13 @@ char * directory_file_name (char * dst, const char *src) else dst[slen - 1] = ':'; } - VOID(strmov(dst+slen,"[000000]")); + (void) strmov(dst+slen,"[000000]"); slen += 8; } - VOID(strmov(strmov(dst+slen,rptr+1)-1,".DIR.1")); + (void) strmov(strmov(dst+slen,rptr+1)-1,".DIR.1"); return dst; } - VOID(strmov(dst, src)); + (void) strmov(dst, src); if (dst[slen] == '/' && slen > 1) dst[slen] = 0; return dst; diff --git a/mysys/my_lockmem.c b/mysys/my_lockmem.c index b96331cd3cf..f2c6d52a382 100644 --- a/mysys/my_lockmem.c +++ b/mysys/my_lockmem.c @@ -59,7 +59,7 @@ uchar *my_malloc_lock(uint size,myf MyFlags) /* Add block in a list for munlock */ if (!(element=(struct st_mem_list*) my_malloc(sizeof(*element),MyFlags))) { - VOID(munlock((uchar*) ptr,size)); + (void) munlock((uchar*) ptr,size); free(ptr); DBUG_RETURN(0); } @@ -85,7 +85,7 @@ void my_free_lock(uchar *ptr,myf Myflags __attribute__((unused))) element=(struct st_mem_list*) list->data; if (ptr == element->page) { /* Found locked mem */ - VOID(munlock((uchar*) ptr,element->size)); + (void) munlock((uchar*) ptr,element->size); mem_list=list_delete(mem_list,list); break; } diff --git a/mysys/my_pthread.c b/mysys/my_pthread.c index ee839e5567e..fd1798ab203 100644 --- a/mysys/my_pthread.c +++ b/mysys/my_pthread.c @@ -30,6 +30,7 @@ #endif uint thd_lib_detected= 0; + /* To allow use of pthread_getspecific with two arguments */ #ifdef HAVE_NONPOSIX_PTHREAD_GETSPECIFIC @@ -267,7 +268,7 @@ void sigwait_handle_sig(int sig) { pthread_mutex_lock(&LOCK_sigwait); sigaddset(&pending_set, sig); - VOID(pthread_cond_signal(&COND_sigwait)); /* inform sigwait() about signal */ + pthread_cond_signal(&COND_sigwait); /* inform sigwait() about signal */ pthread_mutex_unlock(&LOCK_sigwait); } @@ -350,7 +351,7 @@ int sigwait(sigset_t *setp, int *sigp) return 0; } } - VOID(pthread_cond_wait(&COND_sigwait,&LOCK_sigwait)); + pthread_cond_wait(&COND_sigwait,&LOCK_sigwait); } return 0; } diff --git a/mysys/my_redel.c b/mysys/my_redel.c index 6521253f949..77040870048 100644 --- a/mysys/my_redel.c +++ b/mysys/my_redel.c @@ -89,7 +89,7 @@ int my_copystat(const char *from, const char *to, int MyFlags) } if ((statbuf.st_mode & S_IFMT) != S_IFREG) return 1; - VOID(chmod(to, statbuf.st_mode & 07777)); /* Copy modes */ + (void) chmod(to, statbuf.st_mode & 07777); /* Copy modes */ #if !defined(__WIN__) && !defined(__NETWARE__) if (statbuf.st_nlink > 1 && MyFlags & MY_LINK_WARNING) @@ -107,7 +107,7 @@ int my_copystat(const char *from, const char *to, int MyFlags) struct utimbuf timep; timep.actime = statbuf.st_atime; timep.modtime = statbuf.st_mtime; - VOID(utime((char*) to, &timep));/* Update last accessed and modified times */ + (void) utime((char*) to, &timep);/* Update last accessed and modified times */ } #else if (MyFlags & MY_COPYTIME) @@ -115,7 +115,7 @@ int my_copystat(const char *from, const char *to, int MyFlags) time_t time[2]; time[0]= statbuf.st_atime; time[1]= statbuf.st_mtime; - VOID(utime((char*) to, time));/* Update last accessed and modified times */ + (void) utime((char*) to, time);/* Update last accessed and modified times */ } #endif #endif diff --git a/mysys/stacktrace.c b/mysys/stacktrace.c index 66a361b5421..0b9e6eefcce 100644 --- a/mysys/stacktrace.c +++ b/mysys/stacktrace.c @@ -13,9 +13,6 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* Workaround for Bug#32082: VOID redefinition on Win results in compile errors*/ -#define DONT_DEFINE_VOID 1 - #include #include diff --git a/mysys/thr_alarm.c b/mysys/thr_alarm.c index ead598c025a..9ab862fa755 100644 --- a/mysys/thr_alarm.c +++ b/mysys/thr_alarm.c @@ -772,7 +772,7 @@ static void *test_thread(void *arg) break; continue; } - VOID(getchar()); /* Somebody was playing */ + (void) getchar(); /* Somebody was playing */ } } } @@ -784,7 +784,7 @@ static void *test_thread(void *arg) } pthread_mutex_lock(&LOCK_thread_count); thread_count--; - VOID(pthread_cond_signal(&COND_thread_count)); /* Tell main we are ready */ + pthread_cond_signal(&COND_thread_count); /* Tell main we are ready */ pthread_mutex_unlock(&LOCK_thread_count); free((uchar*) arg); return 0; @@ -813,7 +813,7 @@ static void *signal_hand(void *arg __attribute__((unused))) pthread_detach_this_thread(); init_thr_alarm(10); /* Setup alarm handler */ pthread_mutex_lock(&LOCK_thread_count); /* Required by bsdi */ - VOID(pthread_cond_signal(&COND_thread_count)); /* Tell main we are ready */ + pthread_cond_signal(&COND_thread_count); /* Tell main we are ready */ pthread_mutex_unlock(&LOCK_thread_count); sigemptyset(&set); /* Catch all signals */ @@ -904,7 +904,7 @@ int main(int argc __attribute__((unused)),char **argv __attribute__((unused))) #ifdef NOT_USED sigemptyset(&set); sigaddset(&set, thr_client_alarm); - VOID(pthread_sigmask(SIG_UNBLOCK, &set, (sigset_t*) 0)); + pthread_sigmask(SIG_UNBLOCK, &set, (sigset_t*) 0); #endif pthread_attr_init(&thr_attr); @@ -913,10 +913,10 @@ int main(int argc __attribute__((unused)),char **argv __attribute__((unused))) pthread_attr_setstacksize(&thr_attr,65536L); /* Start signal thread and wait for it to start */ - VOID(pthread_mutex_lock(&LOCK_thread_count)); + pthread_mutex_lock(&LOCK_thread_count); pthread_create(&tid,&thr_attr,signal_hand,NULL); - VOID(pthread_cond_wait(&COND_thread_count,&LOCK_thread_count)); - VOID(pthread_mutex_unlock(&LOCK_thread_count)); + pthread_cond_wait(&COND_thread_count,&LOCK_thread_count); + pthread_mutex_unlock(&LOCK_thread_count); DBUG_PRINT("info",("signal thread created")); thr_setconcurrency(3); @@ -944,7 +944,7 @@ int main(int argc __attribute__((unused)),char **argv __attribute__((unused))) alarm_info.next_alarm_time); while (thread_count) { - VOID(pthread_cond_wait(&COND_thread_count,&LOCK_thread_count)); + pthread_cond_wait(&COND_thread_count,&LOCK_thread_count); if (thread_count == 1) { printf("Calling end_thr_alarm. This should cancel the last thread\n"); diff --git a/mysys/thr_lock.c b/mysys/thr_lock.c index 4bb818b1b30..1d724de641c 100644 --- a/mysys/thr_lock.c +++ b/mysys/thr_lock.c @@ -316,7 +316,7 @@ void thr_lock_init(THR_LOCK *lock) { DBUG_ENTER("thr_lock_init"); bzero((char*) lock,sizeof(*lock)); - VOID(pthread_mutex_init(&lock->mutex,MY_MUTEX_INIT_FAST)); + pthread_mutex_init(&lock->mutex,MY_MUTEX_INIT_FAST); lock->read.last= &lock->read.data; lock->read_wait.last= &lock->read_wait.data; lock->write_wait.last= &lock->write_wait.data; @@ -522,7 +522,7 @@ thr_lock(THR_LOCK_DATA *data, THR_LOCK_OWNER *owner, data->cond=0; /* safety */ data->type=lock_type; data->owner= owner; /* Must be reset ! */ - VOID(pthread_mutex_lock(&lock->mutex)); + pthread_mutex_lock(&lock->mutex); DBUG_PRINT("lock",("data: 0x%lx thread: 0x%lx lock: 0x%lx type: %d", (long) data, data->owner->info->thread_id, (long) lock, (int) lock_type)); @@ -794,7 +794,7 @@ static inline void free_all_read_locks(THR_LOCK *lock, data->owner->info->thread_id)); /* purecov: end */ data->cond=0; /* Mark thread free */ - VOID(pthread_cond_signal(cond)); + pthread_cond_signal(cond); } while ((data=data->next)); *lock->read_wait.last=0; if (!lock->read_wait.data) @@ -904,7 +904,7 @@ static void wake_up_waiters(THR_LOCK *lock) { pthread_cond_t *cond=data->cond; data->cond=0; /* Mark thread free */ - VOID(pthread_cond_signal(cond)); /* Start waiting thread */ + pthread_cond_signal(cond); /* Start waiting thread */ } if (data->type != TL_WRITE_ALLOW_WRITE || !lock->write_wait.data || @@ -955,7 +955,7 @@ static void wake_up_waiters(THR_LOCK *lock) lock->write.last= &data->next; data->next=0; /* Only one write lock */ data->cond=0; /* Mark thread free */ - VOID(pthread_cond_signal(cond)); /* Start waiting thread */ + pthread_cond_signal(cond); /* Start waiting thread */ } while (lock_type == TL_WRITE_ALLOW_WRITE && (data=lock->write_wait.data) && data->type == TL_WRITE_ALLOW_WRITE); @@ -1526,7 +1526,7 @@ void thr_print_locks(void) list= list_rest(list)) { THR_LOCK *lock=(THR_LOCK*) list->data; - VOID(pthread_mutex_lock(&lock->mutex)); + pthread_mutex_lock(&lock->mutex); printf("lock: 0x%lx:",(ulong) lock); if ((lock->write_wait.data || lock->read_wait.data) && (! lock->read.data && ! lock->write.data)) @@ -1544,7 +1544,7 @@ void thr_print_locks(void) thr_print_lock("write_wait",&lock->write_wait); thr_print_lock("read",&lock->read); thr_print_lock("read_wait",&lock->read_wait); - VOID(pthread_mutex_unlock(&lock->mutex)); + pthread_mutex_unlock(&lock->mutex); puts(""); } fflush(stdout); @@ -1684,7 +1684,7 @@ static void *test_thread(void *arg) thr_print_locks(); pthread_mutex_lock(&LOCK_thread_count); thread_count--; - VOID(pthread_cond_signal(&COND_thread_count)); /* Tell main we are ready */ + pthread_cond_signal(&COND_thread_count); /* Tell main we are ready */ pthread_mutex_unlock(&LOCK_thread_count); free((uchar*) arg); return 0; @@ -1745,7 +1745,7 @@ int main(int argc __attribute__((unused)),char **argv __attribute__((unused))) } #endif #ifdef HAVE_THR_SETCONCURRENCY - VOID(thr_setconcurrency(2)); + (void) thr_setconcurrency(2); #endif for (i=0 ; i < (int) array_elements(lock_counts) ; i++) { diff --git a/sql/derror.cc b/sql/derror.cc index 3073f37eba3..95481e3212f 100644 --- a/sql/derror.cc +++ b/sql/derror.cc @@ -143,7 +143,7 @@ Error message file '%s' had only %d error messages,\n\ but it should contain at least %d error messages.\n\ Check that the above file is the right version for this program!", name,count,error_messages); - VOID(my_close(file,MYF(MY_WME))); + (void) my_close(file,MYF(MY_WME)); DBUG_RETURN(1); } @@ -170,7 +170,7 @@ Check that the above file is the right version for this program!", { point[i]= *point +uint2korr(head+10+i+i); } - VOID(my_close(file,MYF(0))); + (void) my_close(file,MYF(0)); DBUG_RETURN(0); err: @@ -187,7 +187,7 @@ err: } sql_print_error(errmsg, name); if (file != FERR) - VOID(my_close(file,MYF(MY_WME))); + (void) my_close(file,MYF(MY_WME)); DBUG_RETURN(1); } /* read_texts */ diff --git a/sql/des_key_file.cc b/sql/des_key_file.cc index 317cb237360..87ad6ff12b0 100644 --- a/sql/des_key_file.cc +++ b/sql/des_key_file.cc @@ -43,7 +43,7 @@ load_des_key_file(const char *file_name) DBUG_ENTER("load_des_key_file"); DBUG_PRINT("enter",("name: %s",file_name)); - VOID(pthread_mutex_lock(&LOCK_des_key_file)); + pthread_mutex_lock(&LOCK_des_key_file); if ((file=my_open(file_name,O_RDONLY | O_BINARY ,MYF(MY_WME))) < 0 || init_io_cache(&io, file, IO_SIZE*2, READ_CACHE, 0, 0, MYF(MY_WME))) goto error; @@ -96,7 +96,7 @@ error: my_close(file,MYF(0)); end_io_cache(&io); } - VOID(pthread_mutex_unlock(&LOCK_des_key_file)); + pthread_mutex_unlock(&LOCK_des_key_file); DBUG_RETURN(result); } #endif /* HAVE_OPENSSL */ diff --git a/sql/discover.cc b/sql/discover.cc index 56dc00cc5c4..f475cfbf72a 100644 --- a/sql/discover.cc +++ b/sql/discover.cc @@ -82,7 +82,7 @@ int readfrm(const char *name, uchar **frmdata, size_t *len) err: if (file > 0) - VOID(my_close(file,MYF(MY_WME))); + (void) my_close(file,MYF(MY_WME)); err_end: /* Here when no file */ DBUG_RETURN (error); @@ -118,7 +118,7 @@ int writefrm(const char *name, const uchar *frmdata, size_t len) { if (my_write(file, frmdata, len,MYF(MY_WME | MY_NABP))) error= 2; - VOID(my_close(file,MYF(0))); + (void) my_close(file,MYF(0)); } DBUG_RETURN(error); } /* writefrm */ diff --git a/sql/field.cc b/sql/field.cc index 615d081918b..8077336583e 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -4200,7 +4200,7 @@ String *Field_float::val_str(String *val_buffer, char buff[70],*pos=buff; int decpt,sign,tmp_dec=dec; - VOID(sfconvert(&nr,tmp_dec,&decpt,&sign,buff)); + (void) sfconvert(&nr,tmp_dec,&decpt,&sign,buff); if (sign) { *to++='-'; @@ -4559,7 +4559,7 @@ String *Field_double::val_str(String *val_buffer, char *pos= buff; int decpt,sign,tmp_dec=dec; - VOID(fconvert(nr,tmp_dec,&decpt,&sign,buff)); + (void) fconvert(nr,tmp_dec,&decpt,&sign,buff); if (sign) { *to++='-'; diff --git a/sql/filesort.cc b/sql/filesort.cc index 8f18471b378..3104e6824b0 100644 --- a/sql/filesort.cc +++ b/sql/filesort.cc @@ -1318,7 +1318,7 @@ int merge_buffers(SORTPARAM *param, IO_CACHE *from_file, if (!(error= (int) read_to_buffer(from_file,buffpek, rec_length))) { - VOID(queue_remove(&queue,0)); + (void) queue_remove(&queue,0); reuse_freed_buff(&queue, buffpek, rec_length); break; /* One buffer have been removed */ } diff --git a/sql/ha_ndbcluster.cc b/sql/ha_ndbcluster.cc index 83cceb0da76..b71a7f602ab 100644 --- a/sql/ha_ndbcluster.cc +++ b/sql/ha_ndbcluster.cc @@ -6904,7 +6904,7 @@ int ndbcluster_drop_database_impl(const char *path) while ((tabname=it++)) { tablename_to_filename(tabname, tmp, FN_REFLEN - (tmp - full_path)-1); - VOID(pthread_mutex_lock(&LOCK_open)); + pthread_mutex_lock(&LOCK_open); if (ha_ndbcluster::delete_table(0, ndb, full_path, dbname, tabname)) { const NdbError err= dict->getNdbError(); @@ -6914,7 +6914,7 @@ int ndbcluster_drop_database_impl(const char *path) ret= ndb_to_mysql_error(&err); } } - VOID(pthread_mutex_unlock(&LOCK_open)); + pthread_mutex_unlock(&LOCK_open); } DBUG_RETURN(ret); } diff --git a/sql/ha_partition.cc b/sql/ha_partition.cc index 0d5fc454a0c..2ec92173d14 100644 --- a/sql/ha_partition.cc +++ b/sql/ha_partition.cc @@ -641,7 +641,7 @@ int ha_partition::drop_partitions(const char *path) part_elem->part_state= PART_IS_DROPPED; } } while (++i < num_parts); - VOID(sync_ddl_log()); + (void) sync_ddl_log(); DBUG_RETURN(error); } @@ -739,7 +739,7 @@ int ha_partition::rename_partitions(const char *path) part_elem->log_entry= NULL; /* Indicate success */ } } while (++i < temp_partitions); - VOID(sync_ddl_log()); + (void) sync_ddl_log(); } i= 0; do @@ -791,7 +791,7 @@ int ha_partition::rename_partitions(const char *path) error= ret_error; else if (deactivate_ddl_log_entry(sub_elem->log_entry->entry_pos)) error= 1; - VOID(sync_ddl_log()); + (void) sync_ddl_log(); } file= m_new_file[part]; create_subpartition_name(part_name_buff, path, @@ -822,7 +822,7 @@ int ha_partition::rename_partitions(const char *path) error= ret_error; else if (deactivate_ddl_log_entry(part_elem->log_entry->entry_pos)) error= 1; - VOID(sync_ddl_log()); + (void) sync_ddl_log(); } file= m_new_file[i]; create_partition_name(part_name_buff, path, @@ -840,7 +840,7 @@ int ha_partition::rename_partitions(const char *path) } } } while (++i < num_parts); - VOID(sync_ddl_log()); + (void) sync_ddl_log(); DBUG_RETURN(error); } @@ -1295,7 +1295,7 @@ int ha_partition::prepare_new_partition(TABLE *tbl, DBUG_RETURN(0); error: if (create_flag) - VOID(file->ha_delete_table(part_name)); + (void) file->ha_delete_table(part_name); DBUG_RETURN(error); } @@ -2210,7 +2210,7 @@ bool ha_partition::create_handler_file(const char *name) { result= my_write(file, (uchar *) file_buffer, tot_len_byte, MYF(MY_WME | MY_NABP)) != 0; - VOID(my_close(file, MYF(0))); + (void) my_close(file, MYF(0)); } else result= TRUE; @@ -2396,7 +2396,7 @@ bool ha_partition::get_from_handler_file(const char *name, MEM_ROOT *mem_root) len_bytes= 4 * len_words; if (!(file_buffer= (char*) my_malloc(len_bytes, MYF(0)))) goto err1; - VOID(my_seek(file, 0, MY_SEEK_SET, MYF(0))); + my_seek(file, 0, MY_SEEK_SET, MYF(0)); if (my_read(file, (uchar *) file_buffer, len_bytes, MYF(MY_NABP))) goto err2; @@ -2418,7 +2418,7 @@ bool ha_partition::get_from_handler_file(const char *name, MEM_ROOT *mem_root) if (len_words != (tot_partition_words + tot_name_words + 4)) goto err3; name_buffer_ptr= file_buffer + 16 + 4 * tot_partition_words; - VOID(my_close(file, MYF(0))); + (void) my_close(file, MYF(0)); m_file_buffer= file_buffer; // Will be freed in clear_handler_file() m_name_buffer_ptr= name_buffer_ptr; @@ -2443,7 +2443,7 @@ err3: err2: my_free(file_buffer, MYF(0)); err1: - VOID(my_close(file, MYF(0))); + (void) my_close(file, MYF(0)); DBUG_RETURN(TRUE); } @@ -5844,9 +5844,9 @@ void ha_partition::late_extra_cache(uint partition_id) DBUG_VOID_RETURN; file= m_file[partition_id]; if (m_extra_cache_size == 0) - VOID(file->extra(HA_EXTRA_CACHE)); + (void) file->extra(HA_EXTRA_CACHE); else - VOID(file->extra_opt(HA_EXTRA_CACHE, m_extra_cache_size)); + (void) file->extra_opt(HA_EXTRA_CACHE, m_extra_cache_size); DBUG_VOID_RETURN; } @@ -5870,7 +5870,7 @@ void ha_partition::late_extra_no_cache(uint partition_id) if (!m_extra_cache) DBUG_VOID_RETURN; file= m_file[partition_id]; - VOID(file->extra(HA_EXTRA_NO_CACHE)); + (void) file->extra(HA_EXTRA_NO_CACHE); DBUG_VOID_RETURN; } @@ -6675,7 +6675,7 @@ static PARTITION_SHARE *get_share(const char *table_name, TABLE *table) if (!partition_init) { partition_init++; - VOID(pthread_mutex_init(&partition_mutex, MY_MUTEX_INIT_FAST)); + pthread_mutex_init(&partition_mutex, MY_MUTEX_INIT_FAST); (void) hash_init(&partition_open_tables, system_charset_info, 32, 0, 0, (hash_get_key) partition_get_key, 0, 0); } diff --git a/sql/handler.cc b/sql/handler.cc index 9d1fc723208..17a92b00b4f 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -3014,7 +3014,7 @@ static bool update_frm_version(TABLE *table) } err: if (file >= 0) - VOID(my_close(file,MYF(MY_WME))); + (void) my_close(file,MYF(MY_WME)); DBUG_RETURN(result); } @@ -3647,7 +3647,7 @@ int ha_create_table(THD *thd, const char *path, name= get_canonical_filename(table.file, share.path.str, name_buff); error= table.file->ha_create(name, &table, create_info); - VOID(closefrm(&table, 0)); + (void) closefrm(&table, 0); if (error) { strxmov(name_buff, db, ".", table_name, NullS); @@ -3718,7 +3718,7 @@ int ha_create_table_from_engine(THD* thd, const char *db, const char *name) get_canonical_filename(table.file, path, path); error=table.file->ha_create(path, &table, &create_info); - VOID(closefrm(&table, 1)); + (void) closefrm(&table, 1); DBUG_RETURN(error != 0); } diff --git a/sql/hostname.cc b/sql/hostname.cc index 45b10d16ce2..b498c548e61 100644 --- a/sql/hostname.cc +++ b/sql/hostname.cc @@ -87,7 +87,7 @@ static void add_hostname(struct in_addr *in,const char *name) { if (!(specialflag & SPECIAL_NO_HOST_CACHE)) { - VOID(pthread_mutex_lock(&hostname_cache->lock)); + pthread_mutex_lock(&hostname_cache->lock); host_entry *entry; if (!(entry=(host_entry*) hostname_cache->search((uchar*) &in->s_addr,0))) { @@ -106,7 +106,7 @@ static void add_hostname(struct in_addr *in,const char *name) (void) hostname_cache->add(entry); } } - VOID(pthread_mutex_unlock(&hostname_cache->lock)); + pthread_mutex_unlock(&hostname_cache->lock); } } @@ -118,20 +118,20 @@ inline void add_wrong_ip(struct in_addr *in) void inc_host_errors(struct in_addr *in) { - VOID(pthread_mutex_lock(&hostname_cache->lock)); + pthread_mutex_lock(&hostname_cache->lock); host_entry *entry; if ((entry=(host_entry*) hostname_cache->search((uchar*) &in->s_addr,0))) entry->errors++; - VOID(pthread_mutex_unlock(&hostname_cache->lock)); + pthread_mutex_unlock(&hostname_cache->lock); } void reset_host_errors(struct in_addr *in) { - VOID(pthread_mutex_lock(&hostname_cache->lock)); + pthread_mutex_lock(&hostname_cache->lock); host_entry *entry; if ((entry=(host_entry*) hostname_cache->search((uchar*) &in->s_addr,0))) entry->errors=0; - VOID(pthread_mutex_unlock(&hostname_cache->lock)); + pthread_mutex_unlock(&hostname_cache->lock); } /* Deal with systems that don't defined INADDR_LOOPBACK */ @@ -153,7 +153,7 @@ char * ip_to_hostname(struct in_addr *in, uint *errors) /* Check first if we have name in cache */ if (!(specialflag & SPECIAL_NO_HOST_CACHE)) { - VOID(pthread_mutex_lock(&hostname_cache->lock)); + pthread_mutex_lock(&hostname_cache->lock); if ((entry=(host_entry*) hostname_cache->search((uchar*) &in->s_addr,0))) { char *name; @@ -162,10 +162,10 @@ char * ip_to_hostname(struct in_addr *in, uint *errors) else name=my_strdup(entry->hostname,MYF(0)); *errors= entry->errors; - VOID(pthread_mutex_unlock(&hostname_cache->lock)); + pthread_mutex_unlock(&hostname_cache->lock); DBUG_RETURN(name); } - VOID(pthread_mutex_unlock(&hostname_cache->lock)); + pthread_mutex_unlock(&hostname_cache->lock); } struct hostent *hp, *check; @@ -214,10 +214,10 @@ char * ip_to_hostname(struct in_addr *in, uint *errors) } my_gethostbyname_r_free(); #else - VOID(pthread_mutex_lock(&LOCK_hostname)); + pthread_mutex_lock(&LOCK_hostname); if (!(hp=gethostbyaddr((char*) in,sizeof(*in), AF_INET))) { - VOID(pthread_mutex_unlock(&LOCK_hostname)); + pthread_mutex_unlock(&LOCK_hostname); DBUG_PRINT("error",("gethostbyaddr returned %d",errno)); if (errno == HOST_NOT_FOUND || errno == NO_DATA) @@ -227,17 +227,17 @@ char * ip_to_hostname(struct in_addr *in, uint *errors) } if (!hp->h_name[0]) // Don't allow empty hostnames { - VOID(pthread_mutex_unlock(&LOCK_hostname)); + pthread_mutex_unlock(&LOCK_hostname); DBUG_PRINT("error",("Got an empty hostname")); goto add_wrong_ip_and_return; } if (!(name=my_strdup(hp->h_name,MYF(0)))) { - VOID(pthread_mutex_unlock(&LOCK_hostname)); + pthread_mutex_unlock(&LOCK_hostname); DBUG_RETURN(0); // out of memory } check=gethostbyname(name); - VOID(pthread_mutex_unlock(&LOCK_hostname)); + pthread_mutex_unlock(&LOCK_hostname); if (!check) { DBUG_PRINT("error",("gethostbyname returned %d",errno)); diff --git a/sql/init.cc b/sql/init.cc index afda36b6b9d..cada907b013 100644 --- a/sql/init.cc +++ b/sql/init.cc @@ -40,7 +40,7 @@ void unireg_init(ulong options) my_abort_hook=unireg_abort; /* Abort with close of databases */ #endif - VOID(strmov(reg_ext,".frm")); + (void) strmov(reg_ext,".frm"); reg_ext_length= 4; specialflag=SPECIAL_SAME_DB_NAME | options; /* Set options from argv */ DBUG_VOID_RETURN; diff --git a/sql/item.cc b/sql/item.cc index b59a82f8045..21e06eee589 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -1196,7 +1196,7 @@ void Item_case_expr::print(String *str, enum_query_type) { if (str->reserve(MAX_INT_WIDTH + sizeof("case_expr@"))) return; /* purecov: inspected */ - VOID(str->append(STRING_WITH_LEN("case_expr@"))); + (void) str->append(STRING_WITH_LEN("case_expr@")); str->qs_append(m_case_expr_id); } diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc index 981b4bf0b92..9e0fe0b2562 100644 --- a/sql/item_cmpfunc.cc +++ b/sql/item_cmpfunc.cc @@ -4187,7 +4187,7 @@ void Item_cond::neg_arguments(THD *thd) if (!(new_item= new Item_func_not(item))) return; // Fatal OEM error } - VOID(li.replace(new_item)); + (void) li.replace(new_item); } } diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index d4ef55e5609..923b943c950 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -465,18 +465,18 @@ String *Item_func_des_encrypt::val_str(String *str) if (arg_count == 1) { /* Protect against someone doing FLUSH DES_KEY_FILE */ - VOID(pthread_mutex_lock(&LOCK_des_key_file)); + pthread_mutex_lock(&LOCK_des_key_file); keyschedule= des_keyschedule[key_number=des_default_key]; - VOID(pthread_mutex_unlock(&LOCK_des_key_file)); + pthread_mutex_unlock(&LOCK_des_key_file); } else if (args[1]->result_type() == INT_RESULT) { key_number= (uint) args[1]->val_int(); if (key_number > 9) goto error; - VOID(pthread_mutex_lock(&LOCK_des_key_file)); + pthread_mutex_lock(&LOCK_des_key_file); keyschedule= des_keyschedule[key_number]; - VOID(pthread_mutex_unlock(&LOCK_des_key_file)); + pthread_mutex_unlock(&LOCK_des_key_file); } else { @@ -566,9 +566,9 @@ String *Item_func_des_decrypt::val_str(String *str) key_number > 9) goto error; - VOID(pthread_mutex_lock(&LOCK_des_key_file)); + pthread_mutex_lock(&LOCK_des_key_file); keyschedule= des_keyschedule[key_number]; - VOID(pthread_mutex_unlock(&LOCK_des_key_file)); + pthread_mutex_unlock(&LOCK_des_key_file); } else { diff --git a/sql/lock.cc b/sql/lock.cc index 6cdd654fb92..56ae94ddc39 100644 --- a/sql/lock.cc +++ b/sql/lock.cc @@ -325,7 +325,7 @@ MYSQL_LOCK *mysql_lock_tables(THD *thd, TABLE **tables, uint count, if (rc > 1) /* a timeout or a deadlock */ { if (sql_lock->table_count) - VOID(unlock_external(thd, sql_lock->table, sql_lock->table_count)); + (void) unlock_external(thd, sql_lock->table, sql_lock->table_count); reset_lock_data_and_free(&sql_lock); my_error(rc, MYF(0)); break; @@ -357,7 +357,7 @@ MYSQL_LOCK *mysql_lock_tables(THD *thd, TABLE **tables, uint count, thr_multi_unlock(sql_lock->locks, sql_lock->lock_count); if (sql_lock->table_count) - VOID(unlock_external(thd, sql_lock->table, sql_lock->table_count)); + (void) unlock_external(thd, sql_lock->table, sql_lock->table_count); /* If thr_multi_lock fails it resets lock type for tables, which @@ -433,7 +433,7 @@ void mysql_unlock_tables(THD *thd, MYSQL_LOCK *sql_lock) if (sql_lock->lock_count) thr_multi_unlock(sql_lock->locks,sql_lock->lock_count); if (sql_lock->table_count) - VOID(unlock_external(thd,sql_lock->table,sql_lock->table_count)); + (void) unlock_external(thd,sql_lock->table,sql_lock->table_count); my_free((uchar*) sql_lock,MYF(0)); DBUG_VOID_RETURN; } @@ -497,7 +497,7 @@ void mysql_unlock_read_tables(THD *thd, MYSQL_LOCK *sql_lock) /* Unlock all read locked tables */ if (i != found) { - VOID(unlock_external(thd,table,i-found)); + (void) unlock_external(thd,table,i-found); sql_lock->table_count=found; } /* Fix the lock positions in TABLE */ @@ -978,7 +978,7 @@ int lock_and_wait_for_table_name(THD *thd, TABLE_LIST *table_list) if (wait_if_global_read_lock(thd, 0, 1)) DBUG_RETURN(1); - VOID(pthread_mutex_lock(&LOCK_open)); + pthread_mutex_lock(&LOCK_open); if ((lock_retcode = lock_table_name(thd, table_list, TRUE)) < 0) goto end; if (lock_retcode && wait_for_locked_table_names(thd, table_list)) @@ -1622,8 +1622,8 @@ bool make_global_read_lock_block_commit(THD *thd) void broadcast_refresh(void) { - VOID(pthread_cond_broadcast(&COND_refresh)); - VOID(pthread_cond_broadcast(&COND_global_read_lock)); + pthread_cond_broadcast(&COND_refresh); + pthread_cond_broadcast(&COND_global_read_lock); } /** diff --git a/sql/log.cc b/sql/log.cc index 0abcdb59551..c6802a9a6ed 100644 --- a/sql/log.cc +++ b/sql/log.cc @@ -2909,7 +2909,7 @@ bool MYSQL_BIN_LOG::reset_logs(THD* thd) thread. If the transaction involved MyISAM tables, it should go into binlog even on rollback. */ - VOID(pthread_mutex_lock(&LOCK_thread_count)); + pthread_mutex_lock(&LOCK_thread_count); /* Save variables so that we can reopen the log */ save_name=name; @@ -2989,7 +2989,7 @@ bool MYSQL_BIN_LOG::reset_logs(THD* thd) my_free((uchar*) save_name, MYF(0)); err: - VOID(pthread_mutex_unlock(&LOCK_thread_count)); + pthread_mutex_unlock(&LOCK_thread_count); pthread_mutex_unlock(&LOCK_index); pthread_mutex_unlock(&LOCK_log); DBUG_RETURN(error); @@ -4084,7 +4084,7 @@ bool MYSQL_BIN_LOG::write(Log_event *event_info) if ((thd && !(thd->options & OPTION_BIN_LOG)) || (!binlog_filter->db_ok(local_db))) { - VOID(pthread_mutex_unlock(&LOCK_log)); + pthread_mutex_unlock(&LOCK_log); DBUG_RETURN(0); } #endif /* HAVE_REPLICATION */ @@ -4546,7 +4546,7 @@ bool MYSQL_BIN_LOG::write(THD *thd, IO_CACHE *cache, Log_event *commit_event, bool incident) { DBUG_ENTER("MYSQL_BIN_LOG::write(THD *, IO_CACHE *, Log_event *)"); - VOID(pthread_mutex_lock(&LOCK_log)); + pthread_mutex_lock(&LOCK_log); /* NULL would represent nothing to replicate after ROLLBACK */ DBUG_ASSERT(commit_event != NULL); @@ -4635,7 +4635,7 @@ bool MYSQL_BIN_LOG::write(THD *thd, IO_CACHE *cache, Log_event *commit_event, else rotate_and_purge(RP_LOCK_LOG_IS_ALREADY_LOCKED); } - VOID(pthread_mutex_unlock(&LOCK_log)); + pthread_mutex_unlock(&LOCK_log); DBUG_RETURN(0); @@ -4645,7 +4645,7 @@ err: write_error= 1; sql_print_error(ER(ER_ERROR_ON_WRITE), name, errno); } - VOID(pthread_mutex_unlock(&LOCK_log)); + pthread_mutex_unlock(&LOCK_log); DBUG_RETURN(1); } @@ -4865,7 +4865,7 @@ bool flush_error_log() char err_renamed[FN_REFLEN], *end; end= strmake(err_renamed,log_error_file,FN_REFLEN-4); strmov(end, "-old"); - VOID(pthread_mutex_lock(&LOCK_error_log)); + pthread_mutex_lock(&LOCK_error_log); #ifdef __WIN__ char err_temp[FN_REFLEN+4]; /* @@ -4912,7 +4912,7 @@ bool flush_error_log() else result= 1; #endif - VOID(pthread_mutex_unlock(&LOCK_error_log)); + pthread_mutex_unlock(&LOCK_error_log); } return result; } @@ -4987,7 +4987,7 @@ static void print_buffer_to_file(enum loglevel level, const char *buffer) DBUG_ENTER("print_buffer_to_file"); DBUG_PRINT("enter",("buffer: %s", buffer)); - VOID(pthread_mutex_lock(&LOCK_error_log)); + pthread_mutex_lock(&LOCK_error_log); skr= my_time(0); localtime_r(&skr, &tm_tmp); @@ -5006,7 +5006,7 @@ static void print_buffer_to_file(enum loglevel level, const char *buffer) fflush(stderr); - VOID(pthread_mutex_unlock(&LOCK_error_log)); + pthread_mutex_unlock(&LOCK_error_log); DBUG_VOID_RETURN; } diff --git a/sql/log_event.cc b/sql/log_event.cc index 87af8911fb9..3d35dec4fb0 100644 --- a/sql/log_event.cc +++ b/sql/log_event.cc @@ -3056,9 +3056,9 @@ int Query_log_event::do_apply_event(Relay_log_info const *rli, { thd->set_time((time_t)when); thd->set_query((char*)query_arg, q_len_arg); - VOID(pthread_mutex_lock(&LOCK_thread_count)); + pthread_mutex_lock(&LOCK_thread_count); thd->query_id = next_query_id(); - VOID(pthread_mutex_unlock(&LOCK_thread_count)); + pthread_mutex_unlock(&LOCK_thread_count); thd->variables.pseudo_thread_id= thread_id; // for temp tables DBUG_PRINT("query",("%s", thd->query())); @@ -4580,9 +4580,9 @@ int Load_log_event::do_apply_event(NET* net, Relay_log_info const *rli, if (rpl_filter->db_ok(thd->db)) { thd->set_time((time_t)when); - VOID(pthread_mutex_lock(&LOCK_thread_count)); + pthread_mutex_lock(&LOCK_thread_count); thd->query_id = next_query_id(); - VOID(pthread_mutex_unlock(&LOCK_thread_count)); + pthread_mutex_unlock(&LOCK_thread_count); thd->warning_info->opt_clear_warning_info(thd->query_id); TABLE_LIST tables; diff --git a/sql/mysqld.cc b/sql/mysqld.cc index f0947601c00..1cab245b317 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -1039,14 +1039,14 @@ static void close_server_sock() { ip_sock=INVALID_SOCKET; DBUG_PRINT("info",("calling shutdown on TCP/IP socket")); - VOID(shutdown(tmp_sock, SHUT_RDWR)); + (void) shutdown(tmp_sock, SHUT_RDWR); #if defined(__NETWARE__) /* The following code is disabled for normal systems as it causes MySQL to hang on AIX 4.3 during shutdown */ DBUG_PRINT("info",("calling closesocket on TCP/IP socket")); - VOID(closesocket(tmp_sock)); + (void) closesocket(tmp_sock); #endif } tmp_sock=unix_sock; @@ -1054,16 +1054,16 @@ static void close_server_sock() { unix_sock=INVALID_SOCKET; DBUG_PRINT("info",("calling shutdown on unix socket")); - VOID(shutdown(tmp_sock, SHUT_RDWR)); + (void) shutdown(tmp_sock, SHUT_RDWR); #if defined(__NETWARE__) /* The following code is disabled for normal systems as it may cause MySQL to hang on AIX 4.3 during shutdown */ DBUG_PRINT("info",("calling closesocket on unix/IP socket")); - VOID(closesocket(tmp_sock)); + (void) closesocket(tmp_sock); #endif - VOID(unlink(mysqld_unix_port)); + (void) unlink(mysqld_unix_port); } DBUG_VOID_RETURN; #endif @@ -5175,7 +5175,7 @@ void handle_connections_sockets() if (!(thd= new THD)) { (void) shutdown(new_sock, SHUT_RDWR); - VOID(closesocket(new_sock)); + (void) closesocket(new_sock); continue; } if (!(vio_tmp=vio_new(new_sock, diff --git a/sql/opt_range.h b/sql/opt_range.h index 393ffcb2115..0bb2243080a 100644 --- a/sql/opt_range.h +++ b/sql/opt_range.h @@ -730,7 +730,7 @@ class SQL_SELECT :public Sql_alloc { class FT_SELECT: public QUICK_RANGE_SELECT { public: FT_SELECT(THD *thd, TABLE *table, uint key) : - QUICK_RANGE_SELECT (thd, table, key, 1) { VOID(init()); } + QUICK_RANGE_SELECT (thd, table, key, 1) { (void) init(); } ~FT_SELECT() { file->ft_end(); } int init() { return error=file->ft_init(); } int reset() { return 0; } diff --git a/sql/protocol.cc b/sql/protocol.cc index 5990f0f001a..ba1f770fea6 100644 --- a/sql/protocol.cc +++ b/sql/protocol.cc @@ -247,6 +247,7 @@ net_send_ok(THD *thd, if (!error) error= net_flush(net); + thd->stmt_da->can_overwrite_status= FALSE; DBUG_PRINT("info", ("OK sent, so no more error sending allowed")); @@ -406,6 +407,7 @@ bool net_send_error_packet(THD *thd, uint sql_errno, const char *err, buff[2]= '#'; pos= (uchar*) strmov((char*) buff+3, sqlstate); } + converted_err_len= convert_error_message((char*)converted_err, sizeof(converted_err), thd->variables.character_set_results, @@ -414,6 +416,7 @@ bool net_send_error_packet(THD *thd, uint sql_errno, const char *err, length= (uint) (strmake((char*) pos, (char*)converted_err, MYSQL_ERRMSG_SIZE) - (char*) buff); err= (char*) buff; + DBUG_RETURN(net_write_command(net,(uchar) 255, (uchar*) "", 0, (uchar*) err, length)); } diff --git a/sql/records.cc b/sql/records.cc index 8fd63d104a4..9ec19c55841 100644 --- a/sql/records.cc +++ b/sql/records.cc @@ -178,7 +178,7 @@ void init_read_record(READ_RECORD *info,THD *thd, TABLE *table, if (table->s->tmp_table == NON_TRANSACTIONAL_TMP_TABLE && !table->sort.addon_field) - VOID(table->file->extra(HA_EXTRA_MMAP)); + (void) table->file->extra(HA_EXTRA_MMAP); if (table->sort.addon_field) { @@ -266,8 +266,8 @@ void init_read_record(READ_RECORD *info,THD *thd, TABLE *table, !(table->s->db_options_in_use & HA_OPTION_PACK_RECORD) || (use_record_cache < 0 && !(table->file->ha_table_flags() & HA_NOT_DELETE_WITH_CACHE)))) - VOID(table->file->extra_opt(HA_EXTRA_CACHE, - thd->variables.read_buff_size)); + (void) table->file->extra_opt(HA_EXTRA_CACHE, + thd->variables.read_buff_size); } /* Condition pushdown to storage engine */ if (thd->variables.engine_condition_pushdown && diff --git a/sql/sp_head.cc b/sql/sp_head.cc index 1fb8fd257df..f90aefc2a3f 100644 --- a/sql/sp_head.cc +++ b/sql/sp_head.cc @@ -1769,9 +1769,9 @@ sp_head::execute_function(THD *thd, Item **argp, uint argcount, as one select and not resetting THD::user_var_events before each invocation. */ - VOID(pthread_mutex_lock(&LOCK_thread_count)); + pthread_mutex_lock(&LOCK_thread_count); q= global_query_id; - VOID(pthread_mutex_unlock(&LOCK_thread_count)); + pthread_mutex_unlock(&LOCK_thread_count); mysql_bin_log.start_union_events(thd, q + 1); binlog_save_options= thd->options; thd->options&= ~OPTION_BIN_LOG; @@ -2736,9 +2736,9 @@ sp_lex_keeper::reset_lex_and_exec_core(THD *thd, uint *nextp, */ thd->lex= m_lex; - VOID(pthread_mutex_lock(&LOCK_thread_count)); + pthread_mutex_lock(&LOCK_thread_count); thd->query_id= next_query_id(); - VOID(pthread_mutex_unlock(&LOCK_thread_count)); + pthread_mutex_unlock(&LOCK_thread_count); if (thd->prelocked_mode == NON_PRELOCKED) { diff --git a/sql/sp_pcontext.cc b/sql/sp_pcontext.cc index 31c307ebe74..48ceb1371ca 100644 --- a/sql/sp_pcontext.cc +++ b/sql/sp_pcontext.cc @@ -63,21 +63,21 @@ sp_pcontext::sp_pcontext() m_context_handlers(0), m_parent(NULL), m_pboundary(0), m_label_scope(LABEL_DEFAULT_SCOPE) { - VOID(my_init_dynamic_array(&m_vars, sizeof(sp_variable_t *), + (void) my_init_dynamic_array(&m_vars, sizeof(sp_variable_t *), PCONTEXT_ARRAY_INIT_ALLOC, - PCONTEXT_ARRAY_INCREMENT_ALLOC)); - VOID(my_init_dynamic_array(&m_case_expr_id_lst, sizeof(int), + PCONTEXT_ARRAY_INCREMENT_ALLOC); + (void) my_init_dynamic_array(&m_case_expr_id_lst, sizeof(int), PCONTEXT_ARRAY_INIT_ALLOC, - PCONTEXT_ARRAY_INCREMENT_ALLOC)); - VOID(my_init_dynamic_array(&m_conds, sizeof(sp_cond_type_t *), + PCONTEXT_ARRAY_INCREMENT_ALLOC); + (void) my_init_dynamic_array(&m_conds, sizeof(sp_cond_type_t *), PCONTEXT_ARRAY_INIT_ALLOC, - PCONTEXT_ARRAY_INCREMENT_ALLOC)); - VOID(my_init_dynamic_array(&m_cursors, sizeof(LEX_STRING), + PCONTEXT_ARRAY_INCREMENT_ALLOC); + (void) my_init_dynamic_array(&m_cursors, sizeof(LEX_STRING), PCONTEXT_ARRAY_INIT_ALLOC, - PCONTEXT_ARRAY_INCREMENT_ALLOC)); - VOID(my_init_dynamic_array(&m_handlers, sizeof(sp_cond_type_t *), + PCONTEXT_ARRAY_INCREMENT_ALLOC); + (void) my_init_dynamic_array(&m_handlers, sizeof(sp_cond_type_t *), PCONTEXT_ARRAY_INIT_ALLOC, - PCONTEXT_ARRAY_INCREMENT_ALLOC)); + PCONTEXT_ARRAY_INCREMENT_ALLOC); m_label.empty(); m_children.empty(); @@ -91,21 +91,21 @@ sp_pcontext::sp_pcontext(sp_pcontext *prev, label_scope_type label_scope) m_context_handlers(0), m_parent(prev), m_pboundary(0), m_label_scope(label_scope) { - VOID(my_init_dynamic_array(&m_vars, sizeof(sp_variable_t *), + (void) my_init_dynamic_array(&m_vars, sizeof(sp_variable_t *), PCONTEXT_ARRAY_INIT_ALLOC, - PCONTEXT_ARRAY_INCREMENT_ALLOC)); - VOID(my_init_dynamic_array(&m_case_expr_id_lst, sizeof(int), + PCONTEXT_ARRAY_INCREMENT_ALLOC); + (void) my_init_dynamic_array(&m_case_expr_id_lst, sizeof(int), PCONTEXT_ARRAY_INIT_ALLOC, - PCONTEXT_ARRAY_INCREMENT_ALLOC)); - VOID(my_init_dynamic_array(&m_conds, sizeof(sp_cond_type_t *), + PCONTEXT_ARRAY_INCREMENT_ALLOC); + (void) my_init_dynamic_array(&m_conds, sizeof(sp_cond_type_t *), PCONTEXT_ARRAY_INIT_ALLOC, - PCONTEXT_ARRAY_INCREMENT_ALLOC)); - VOID(my_init_dynamic_array(&m_cursors, sizeof(LEX_STRING), + PCONTEXT_ARRAY_INCREMENT_ALLOC); + (void) my_init_dynamic_array(&m_cursors, sizeof(LEX_STRING), PCONTEXT_ARRAY_INIT_ALLOC, - PCONTEXT_ARRAY_INCREMENT_ALLOC)); - VOID(my_init_dynamic_array(&m_handlers, sizeof(sp_cond_type_t *), + PCONTEXT_ARRAY_INCREMENT_ALLOC); + (void) my_init_dynamic_array(&m_handlers, sizeof(sp_cond_type_t *), PCONTEXT_ARRAY_INIT_ALLOC, - PCONTEXT_ARRAY_INCREMENT_ALLOC)); + PCONTEXT_ARRAY_INCREMENT_ALLOC); m_label.empty(); m_children.empty(); diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc index 46d7f3ce89d..641423605aa 100644 --- a/sql/sql_acl.cc +++ b/sql/sql_acl.cc @@ -326,7 +326,7 @@ static my_bool acl_load(THD *thd, TABLE_LIST *tables) init_read_record(&read_record_info,thd,table= tables[0].table,NULL,1,0, FALSE); table->use_all_columns(); - VOID(my_init_dynamic_array(&acl_hosts,sizeof(ACL_HOST),20,50)); + (void) my_init_dynamic_array(&acl_hosts,sizeof(ACL_HOST),20,50); while (!(read_record_info.read_record(&read_record_info))) { ACL_HOST host; @@ -366,7 +366,7 @@ static my_bool acl_load(THD *thd, TABLE_LIST *tables) host.access|=REFERENCES_ACL | INDEX_ACL | ALTER_ACL | CREATE_TMP_ACL; } #endif - VOID(push_dynamic(&acl_hosts,(uchar*) &host)); + (void) push_dynamic(&acl_hosts,(uchar*) &host); } my_qsort((uchar*) dynamic_element(&acl_hosts,0,ACL_HOST*),acl_hosts.elements, sizeof(ACL_HOST),(qsort_cmp) acl_compare); @@ -375,7 +375,7 @@ static my_bool acl_load(THD *thd, TABLE_LIST *tables) init_read_record(&read_record_info,thd,table=tables[1].table,NULL,1,0,FALSE); table->use_all_columns(); - VOID(my_init_dynamic_array(&acl_users,sizeof(ACL_USER),50,100)); + (void) my_init_dynamic_array(&acl_users,sizeof(ACL_USER),50,100); password_length= table->field[2]->field_length / table->field[2]->charset()->mbmaxlen; if (password_length < SCRAMBLED_PASSWORD_CHAR_LENGTH_323) @@ -550,7 +550,7 @@ static my_bool acl_load(THD *thd, TABLE_LIST *tables) user.access|= SUPER_ACL | EXECUTE_ACL; #endif } - VOID(push_dynamic(&acl_users,(uchar*) &user)); + (void) push_dynamic(&acl_users,(uchar*) &user); if (!user.host.hostname || (user.host.hostname[0] == wild_many && !user.host.hostname[1])) allow_all_hosts=1; // Anyone can connect @@ -563,7 +563,7 @@ static my_bool acl_load(THD *thd, TABLE_LIST *tables) init_read_record(&read_record_info,thd,table=tables[2].table,NULL,1,0,FALSE); table->use_all_columns(); - VOID(my_init_dynamic_array(&acl_dbs,sizeof(ACL_DB),50,100)); + (void) my_init_dynamic_array(&acl_dbs,sizeof(ACL_DB),50,100); while (!(read_record_info.read_record(&read_record_info))) { ACL_DB db; @@ -613,7 +613,7 @@ static my_bool acl_load(THD *thd, TABLE_LIST *tables) db.access|=REFERENCES_ACL | INDEX_ACL | ALTER_ACL; } #endif - VOID(push_dynamic(&acl_dbs,(uchar*) &db)); + (void) push_dynamic(&acl_dbs,(uchar*) &db); } my_qsort((uchar*) dynamic_element(&acl_dbs,0,ACL_DB*),acl_dbs.elements, sizeof(ACL_DB),(qsort_cmp) acl_compare); @@ -706,7 +706,7 @@ my_bool acl_reload(THD *thd) } if ((old_initialized=initialized)) - VOID(pthread_mutex_lock(&acl_cache->lock)); + pthread_mutex_lock(&acl_cache->lock); old_acl_hosts=acl_hosts; old_acl_users=acl_users; @@ -733,7 +733,7 @@ my_bool acl_reload(THD *thd) delete_dynamic(&old_acl_dbs); } if (old_initialized) - VOID(pthread_mutex_unlock(&acl_cache->lock)); + pthread_mutex_unlock(&acl_cache->lock); end: close_thread_tables(thd); DBUG_RETURN(return_val); @@ -885,7 +885,7 @@ int acl_getroot(THD *thd, USER_RESOURCES *mqh, DBUG_RETURN(0); } - VOID(pthread_mutex_lock(&acl_cache->lock)); + pthread_mutex_lock(&acl_cache->lock); /* Find acl entry in user database. Note, that find_acl_user is not the same, @@ -1064,7 +1064,7 @@ int acl_getroot(THD *thd, USER_RESOURCES *mqh, else *sctx->priv_host= 0; } - VOID(pthread_mutex_unlock(&acl_cache->lock)); + pthread_mutex_unlock(&acl_cache->lock); DBUG_RETURN(res); } @@ -1111,7 +1111,7 @@ bool acl_getroot_no_password(Security_context *sctx, char *user, char *host, DBUG_RETURN(FALSE); } - VOID(pthread_mutex_lock(&acl_cache->lock)); + pthread_mutex_lock(&acl_cache->lock); sctx->master_access= 0; sctx->db_access= 0; @@ -1165,7 +1165,7 @@ bool acl_getroot_no_password(Security_context *sctx, char *user, char *host, else *sctx->priv_host= 0; } - VOID(pthread_mutex_unlock(&acl_cache->lock)); + pthread_mutex_unlock(&acl_cache->lock); DBUG_RETURN(res); } @@ -1254,7 +1254,7 @@ static void acl_insert_user(const char *user, const char *host, set_user_salt(&acl_user, password, password_len); - VOID(push_dynamic(&acl_users,(uchar*) &acl_user)); + (void) push_dynamic(&acl_users,(uchar*) &acl_user); if (!acl_user.host.hostname || (acl_user.host.hostname[0] == wild_many && !acl_user.host.hostname[1])) allow_all_hosts=1; // Anyone can connect /* purecov: tested */ @@ -1320,7 +1320,7 @@ static void acl_insert_db(const char *user, const char *host, const char *db, acl_db.db=strdup_root(&mem,db); acl_db.access=privileges; acl_db.sort=get_sort(3,acl_db.host.hostname,acl_db.db,acl_db.user); - VOID(push_dynamic(&acl_dbs,(uchar*) &acl_db)); + (void) push_dynamic(&acl_dbs,(uchar*) &acl_db); my_qsort((uchar*) dynamic_element(&acl_dbs,0,ACL_DB*),acl_dbs.elements, sizeof(ACL_DB),(qsort_cmp) acl_compare); } @@ -1344,7 +1344,7 @@ ulong acl_get(const char *host, const char *ip, acl_entry *entry; DBUG_ENTER("acl_get"); - VOID(pthread_mutex_lock(&acl_cache->lock)); + pthread_mutex_lock(&acl_cache->lock); end=strmov((tmp_db=strmov(strmov(key, ip ? ip : "")+1,user)+1),db); if (lower_case_table_names) { @@ -1356,7 +1356,7 @@ ulong acl_get(const char *host, const char *ip, key_length))) { db_access=entry->access; - VOID(pthread_mutex_unlock(&acl_cache->lock)); + pthread_mutex_unlock(&acl_cache->lock); DBUG_PRINT("exit", ("access: 0x%lx", db_access)); DBUG_RETURN(db_access); } @@ -1410,7 +1410,7 @@ exit: memcpy((uchar*) entry->key,key,key_length); acl_cache->add(entry); } - VOID(pthread_mutex_unlock(&acl_cache->lock)); + pthread_mutex_unlock(&acl_cache->lock); DBUG_PRINT("exit", ("access: 0x%lx", db_access & host_access)); DBUG_RETURN(db_access & host_access); } @@ -1426,10 +1426,11 @@ exit: static void init_check_host(void) { DBUG_ENTER("init_check_host"); - VOID(my_init_dynamic_array(&acl_wild_hosts,sizeof(struct acl_host_and_ip), - acl_users.elements,1)); - VOID(my_hash_init(&acl_check_hosts,system_charset_info,acl_users.elements,0,0, - (my_hash_get_key) check_get_key,0,0)); + (void) my_init_dynamic_array(&acl_wild_hosts,sizeof(struct acl_host_and_ip), + acl_users.elements,1); + (void) my_hash_init(&acl_check_hosts,system_charset_info, + acl_users.elements, 0, 0, + (my_hash_get_key) check_get_key, 0, 0); if (!allow_all_hosts) { for (uint i=0 ; i < acl_users.elements ; i++) @@ -1491,12 +1492,12 @@ bool acl_check_host(const char *host, const char *ip) { if (allow_all_hosts) return 0; - VOID(pthread_mutex_lock(&acl_cache->lock)); + pthread_mutex_lock(&acl_cache->lock); if ((host && my_hash_search(&acl_check_hosts,(uchar*) host,strlen(host))) || (ip && my_hash_search(&acl_check_hosts,(uchar*) ip, strlen(ip)))) { - VOID(pthread_mutex_unlock(&acl_cache->lock)); + pthread_mutex_unlock(&acl_cache->lock); return 0; // Found host } for (uint i=0 ; i < acl_wild_hosts.elements ; i++) @@ -1504,11 +1505,11 @@ bool acl_check_host(const char *host, const char *ip) acl_host_and_ip *acl=dynamic_element(&acl_wild_hosts,i,acl_host_and_ip*); if (compare_hostname(acl, host, ip)) { - VOID(pthread_mutex_unlock(&acl_cache->lock)); + pthread_mutex_unlock(&acl_cache->lock); return 0; // Host ok } } - VOID(pthread_mutex_unlock(&acl_cache->lock)); + pthread_mutex_unlock(&acl_cache->lock); return 1; // Host is not allowed } @@ -1622,11 +1623,11 @@ bool change_password(THD *thd, const char *host, const char *user, if (!(table= open_ltable(thd, &tables, TL_WRITE, 0))) DBUG_RETURN(1); - VOID(pthread_mutex_lock(&acl_cache->lock)); + pthread_mutex_lock(&acl_cache->lock); ACL_USER *acl_user; if (!(acl_user= find_acl_user(host, user, TRUE))) { - VOID(pthread_mutex_unlock(&acl_cache->lock)); + pthread_mutex_unlock(&acl_cache->lock); my_message(ER_PASSWORD_NO_MATCH, ER(ER_PASSWORD_NO_MATCH), MYF(0)); goto end; } @@ -1638,12 +1639,12 @@ bool change_password(THD *thd, const char *host, const char *user, acl_user->user ? acl_user->user : "", new_password, new_password_len)) { - VOID(pthread_mutex_unlock(&acl_cache->lock)); /* purecov: deadcode */ + pthread_mutex_unlock(&acl_cache->lock); /* purecov: deadcode */ goto end; } acl_cache->clear(1); // Clear locked hostname cache - VOID(pthread_mutex_unlock(&acl_cache->lock)); + pthread_mutex_unlock(&acl_cache->lock); result= 0; if (mysql_bin_log.is_open()) { @@ -1684,9 +1685,9 @@ bool is_acl_user(const char *host, const char *user) if (!initialized) return TRUE; - VOID(pthread_mutex_lock(&acl_cache->lock)); + pthread_mutex_lock(&acl_cache->lock); res= find_acl_user(host, user, TRUE) != NULL; - VOID(pthread_mutex_unlock(&acl_cache->lock)); + pthread_mutex_unlock(&acl_cache->lock); return res; } @@ -3443,7 +3444,7 @@ bool mysql_grant(THD *thd, const char *db, List &list, /* go through users in user_list */ rw_wrlock(&LOCK_grant); - VOID(pthread_mutex_lock(&acl_cache->lock)); + pthread_mutex_lock(&acl_cache->lock); grant_version++; int result=0; @@ -3475,7 +3476,7 @@ bool mysql_grant(THD *thd, const char *db, List &list, } } } - VOID(pthread_mutex_unlock(&acl_cache->lock)); + pthread_mutex_unlock(&acl_cache->lock); if (!result) { @@ -4635,12 +4636,12 @@ bool mysql_show_grants(THD *thd,LEX_USER *lex_user) } rw_rdlock(&LOCK_grant); - VOID(pthread_mutex_lock(&acl_cache->lock)); + pthread_mutex_lock(&acl_cache->lock); acl_user= find_acl_user(lex_user->host.str, lex_user->user.str, TRUE); if (!acl_user) { - VOID(pthread_mutex_unlock(&acl_cache->lock)); + pthread_mutex_unlock(&acl_cache->lock); rw_unlock(&LOCK_grant); my_error(ER_NONEXISTING_GRANT, MYF(0), @@ -4658,7 +4659,7 @@ bool mysql_show_grants(THD *thd,LEX_USER *lex_user) if (protocol->send_result_set_metadata(&field_list, Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF)) { - VOID(pthread_mutex_unlock(&acl_cache->lock)); + pthread_mutex_unlock(&acl_cache->lock); rw_unlock(&LOCK_grant); DBUG_RETURN(TRUE); @@ -4969,7 +4970,7 @@ bool mysql_show_grants(THD *thd,LEX_USER *lex_user) } end: - VOID(pthread_mutex_unlock(&acl_cache->lock)); + pthread_mutex_unlock(&acl_cache->lock); rw_unlock(&LOCK_grant); my_eof(thd); @@ -5767,7 +5768,7 @@ bool mysql_create_user(THD *thd, List &list) DBUG_RETURN(result != 1); rw_wrlock(&LOCK_grant); - VOID(pthread_mutex_lock(&acl_cache->lock)); + pthread_mutex_lock(&acl_cache->lock); while ((tmp_user_name= user_list++)) { @@ -5797,7 +5798,7 @@ bool mysql_create_user(THD *thd, List &list) } } - VOID(pthread_mutex_unlock(&acl_cache->lock)); + pthread_mutex_unlock(&acl_cache->lock); if (result) my_error(ER_CANNOT_USER, MYF(0), "CREATE USER", wrong_users.c_ptr_safe()); @@ -5849,7 +5850,7 @@ bool mysql_drop_user(THD *thd, List &list) thd->variables.sql_mode&= ~MODE_PAD_CHAR_TO_FULL_LENGTH; rw_wrlock(&LOCK_grant); - VOID(pthread_mutex_lock(&acl_cache->lock)); + pthread_mutex_lock(&acl_cache->lock); while ((tmp_user_name= user_list++)) { @@ -5870,7 +5871,7 @@ bool mysql_drop_user(THD *thd, List &list) /* Rebuild 'acl_check_hosts' since 'acl_users' has been modified */ rebuild_check_host(); - VOID(pthread_mutex_unlock(&acl_cache->lock)); + pthread_mutex_unlock(&acl_cache->lock); if (result) my_error(ER_CANNOT_USER, MYF(0), "DROP USER", wrong_users.c_ptr_safe()); @@ -5921,7 +5922,7 @@ bool mysql_rename_user(THD *thd, List &list) DBUG_RETURN(result != 1); rw_wrlock(&LOCK_grant); - VOID(pthread_mutex_lock(&acl_cache->lock)); + pthread_mutex_lock(&acl_cache->lock); while ((tmp_user_from= user_list++)) { @@ -5955,7 +5956,7 @@ bool mysql_rename_user(THD *thd, List &list) /* Rebuild 'acl_check_hosts' since 'acl_users' has been modified */ rebuild_check_host(); - VOID(pthread_mutex_unlock(&acl_cache->lock)); + pthread_mutex_unlock(&acl_cache->lock); if (result) my_error(ER_CANNOT_USER, MYF(0), "RENAME USER", wrong_users.c_ptr_safe()); @@ -6002,7 +6003,7 @@ bool mysql_revoke_all(THD *thd, List &list) DBUG_RETURN(result != 1); rw_wrlock(&LOCK_grant); - VOID(pthread_mutex_lock(&acl_cache->lock)); + pthread_mutex_lock(&acl_cache->lock); LEX_USER *lex_user, *tmp_lex_user; List_iterator user_list(list); @@ -6141,7 +6142,7 @@ bool mysql_revoke_all(THD *thd, List &list) } while (revoked); } - VOID(pthread_mutex_unlock(&acl_cache->lock)); + pthread_mutex_unlock(&acl_cache->lock); write_bin_log(thd, FALSE, thd->query(), thd->query_length()); @@ -6250,7 +6251,7 @@ bool sp_revoke_privileges(THD *thd, const char *sp_db, const char *sp_name, thd->push_internal_handler(&error_handler); rw_wrlock(&LOCK_grant); - VOID(pthread_mutex_lock(&acl_cache->lock)); + pthread_mutex_lock(&acl_cache->lock); /* This statement will be replicated as a statement, even when using @@ -6288,7 +6289,7 @@ bool sp_revoke_privileges(THD *thd, const char *sp_db, const char *sp_name, } } while (revoked); - VOID(pthread_mutex_unlock(&acl_cache->lock)); + pthread_mutex_unlock(&acl_cache->lock); rw_unlock(&LOCK_grant); close_thread_tables(thd); @@ -6329,7 +6330,7 @@ bool sp_grant_privileges(THD *thd, const char *sp_db, const char *sp_name, combo->user.str= sctx->user; - VOID(pthread_mutex_lock(&acl_cache->lock)); + pthread_mutex_lock(&acl_cache->lock); if ((au= find_acl_user(combo->host.str=(char*)sctx->host_or_ip,combo->user.str,FALSE))) goto found_acl; @@ -6340,11 +6341,11 @@ bool sp_grant_privileges(THD *thd, const char *sp_db, const char *sp_name, if((au= find_acl_user(combo->host.str=(char*)"%", combo->user.str, FALSE))) goto found_acl; - VOID(pthread_mutex_unlock(&acl_cache->lock)); + pthread_mutex_unlock(&acl_cache->lock); DBUG_RETURN(TRUE); found_acl: - VOID(pthread_mutex_unlock(&acl_cache->lock)); + pthread_mutex_unlock(&acl_cache->lock); bzero((char*)tables, sizeof(TABLE_LIST)); user_list.empty(); diff --git a/sql/sql_base.cc b/sql/sql_base.cc index 2c0ba87262a..52e203f1130 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -438,7 +438,7 @@ found: oldest_unused_share->next) { pthread_mutex_lock(&oldest_unused_share->mutex); - VOID(my_hash_delete(&table_def_cache, (uchar*) oldest_unused_share)); + my_hash_delete(&table_def_cache, (uchar*) oldest_unused_share); } DBUG_PRINT("exit", ("share: 0x%lx ref_count: %u", @@ -714,7 +714,7 @@ OPEN_TABLE_LIST *list_open_tables(THD *thd, const char *db, const char *wild) TABLE_LIST table_list; DBUG_ENTER("list_open_tables"); - VOID(pthread_mutex_lock(&LOCK_open)); + pthread_mutex_lock(&LOCK_open); bzero((char*) &table_list,sizeof(table_list)); start_list= &open_list; open_list=0; @@ -767,7 +767,7 @@ OPEN_TABLE_LIST *list_open_tables(THD *thd, const char *db, const char *wild) start_list= &(*start_list)->next; *start_list=0; } - VOID(pthread_mutex_unlock(&LOCK_open)); + pthread_mutex_unlock(&LOCK_open); DBUG_RETURN(open_list); } @@ -787,7 +787,7 @@ void intern_close_table(TABLE *table) free_io_cache(table); delete table->triggers; if (table->file) // Not true if name lock - VOID(closefrm(table, 1)); // close file + (void) closefrm(table, 1); // close file DBUG_VOID_RETURN; } @@ -864,7 +864,7 @@ bool close_cached_tables(THD *thd, TABLE_LIST *tables, bool have_lock, DBUG_ASSERT(thd || (!wait_for_refresh && !tables)); if (!have_lock) - VOID(pthread_mutex_lock(&LOCK_open)); + pthread_mutex_lock(&LOCK_open); if (!tables) { refresh_version++; // Force close of open tables @@ -874,14 +874,14 @@ bool close_cached_tables(THD *thd, TABLE_LIST *tables, bool have_lock, if (my_hash_delete(&open_cache,(uchar*) unused_tables)) printf("Warning: Couldn't delete open table from hash\n"); #else - VOID(my_hash_delete(&open_cache,(uchar*) unused_tables)); + (void) my_hash_delete(&open_cache,(uchar*) unused_tables); #endif } /* Free table shares */ while (oldest_unused_share->next) { pthread_mutex_lock(&oldest_unused_share->mutex); - VOID(my_hash_delete(&table_def_cache, (uchar*) oldest_unused_share)); + (void) my_hash_delete(&table_def_cache, (uchar*) oldest_unused_share); } DBUG_PRINT("tcache", ("incremented global refresh_version to: %lu", refresh_version)); @@ -1019,7 +1019,7 @@ bool close_cached_tables(THD *thd, TABLE_LIST *tables, bool have_lock, } } if (!have_lock) - VOID(pthread_mutex_unlock(&LOCK_open)); + pthread_mutex_unlock(&LOCK_open); if (wait_for_refresh) { pthread_mutex_lock(&thd->mysys_var->mutex); @@ -1049,7 +1049,7 @@ bool close_cached_connection_tables(THD *thd, bool if_wait_for_refresh, bzero(&tmp, sizeof(TABLE_LIST)); if (!have_lock) - VOID(pthread_mutex_lock(&LOCK_open)); + pthread_mutex_lock(&LOCK_open); for (idx= 0; idx < table_def_cache.records; idx++) { @@ -1082,7 +1082,7 @@ bool close_cached_connection_tables(THD *thd, bool if_wait_for_refresh, result= close_cached_tables(thd, tables, TRUE, FALSE, FALSE); if (!have_lock) - VOID(pthread_mutex_unlock(&LOCK_open)); + pthread_mutex_unlock(&LOCK_open); if (if_wait_for_refresh) { @@ -1199,7 +1199,7 @@ static void close_open_tables(THD *thd) safe_mutex_assert_not_owner(&LOCK_open); - VOID(pthread_mutex_lock(&LOCK_open)); + pthread_mutex_lock(&LOCK_open); DBUG_PRINT("info", ("thd->open_tables: 0x%lx", (long) thd->open_tables)); @@ -1209,7 +1209,7 @@ static void close_open_tables(THD *thd) /* Free tables to hold down open files */ while (open_cache.records > table_cache_size && unused_tables) - VOID(my_hash_delete(&open_cache,(uchar*) unused_tables)); /* purecov: tested */ + my_hash_delete(&open_cache,(uchar*) unused_tables); /* purecov: tested */ check_unused(); if (found_old_table) { @@ -1217,7 +1217,7 @@ static void close_open_tables(THD *thd) broadcast_refresh(); } - VOID(pthread_mutex_unlock(&LOCK_open)); + pthread_mutex_unlock(&LOCK_open); } @@ -1395,7 +1395,7 @@ bool close_thread_table(THD *thd, TABLE **table_ptr) if (table->needs_reopen_or_name_lock() || thd->version != refresh_version || !table->db_stat) { - VOID(my_hash_delete(&open_cache,(uchar*) table)); + my_hash_delete(&open_cache,(uchar*) table); found_old_table=1; } else @@ -2099,7 +2099,7 @@ void unlink_open_table(THD *thd, TABLE *find, bool unlock) /* Remove table from open_tables list. */ *prev= list->next; /* Close table. */ - VOID(my_hash_delete(&open_cache,(uchar*) list)); // Close table + my_hash_delete(&open_cache,(uchar*) list); // Close table } else { @@ -2141,14 +2141,14 @@ void drop_open_table(THD *thd, TABLE *table, const char *db_name, else { handlerton *table_type= table->s->db_type(); - VOID(pthread_mutex_lock(&LOCK_open)); + pthread_mutex_lock(&LOCK_open); /* unlink_open_table() also tells threads waiting for refresh or close that something has happened. */ unlink_open_table(thd, table, FALSE); quick_rm_table(table_type, db_name, table_name, 0); - VOID(pthread_mutex_unlock(&LOCK_open)); + pthread_mutex_unlock(&LOCK_open); } } @@ -2403,24 +2403,24 @@ bool lock_table_name_if_not_cached(THD *thd, const char *db, DBUG_ENTER("lock_table_name_if_not_cached"); key_length= (uint)(strmov(strmov(key, db) + 1, table_name) - key) + 1; - VOID(pthread_mutex_lock(&LOCK_open)); + pthread_mutex_lock(&LOCK_open); if (my_hash_search(&open_cache, (uchar *)key, key_length)) { - VOID(pthread_mutex_unlock(&LOCK_open)); + pthread_mutex_unlock(&LOCK_open); DBUG_PRINT("info", ("Table is cached, name-lock is not obtained")); *table= 0; DBUG_RETURN(FALSE); } if (!(*table= table_cache_insert_placeholder(thd, key, key_length))) { - VOID(pthread_mutex_unlock(&LOCK_open)); + pthread_mutex_unlock(&LOCK_open); DBUG_RETURN(TRUE); } (*table)->open_placeholder= 1; (*table)->next= thd->open_tables; thd->open_tables= *table; - VOID(pthread_mutex_unlock(&LOCK_open)); + pthread_mutex_unlock(&LOCK_open); DBUG_RETURN(FALSE); } @@ -2677,15 +2677,15 @@ TABLE *open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT *mem_root, */ TABLE tab; table= &tab; - VOID(pthread_mutex_lock(&LOCK_open)); + pthread_mutex_lock(&LOCK_open); if (!open_unireg_entry(thd, table, table_list, alias, key, key_length, mem_root, 0)) { DBUG_ASSERT(table_list->view != 0); - VOID(pthread_mutex_unlock(&LOCK_open)); + pthread_mutex_unlock(&LOCK_open); DBUG_RETURN(0); // VIEW } - VOID(pthread_mutex_unlock(&LOCK_open)); + pthread_mutex_unlock(&LOCK_open); } } /* @@ -2718,7 +2718,7 @@ TABLE *open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT *mem_root, on disk. */ - VOID(pthread_mutex_lock(&LOCK_open)); + pthread_mutex_lock(&LOCK_open); /* If it's the first table from a list of tables used in a query, @@ -2736,7 +2736,7 @@ TABLE *open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT *mem_root, /* Someone did a refresh while thread was opening tables */ if (refresh) *refresh=1; - VOID(pthread_mutex_unlock(&LOCK_open)); + pthread_mutex_unlock(&LOCK_open); DBUG_RETURN(0); } @@ -2802,7 +2802,7 @@ TABLE *open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT *mem_root, /* Avoid self-deadlocks by detecting self-dependencies. */ if (table->open_placeholder && table->in_use == thd) { - VOID(pthread_mutex_unlock(&LOCK_open)); + pthread_mutex_unlock(&LOCK_open); my_error(ER_UPDATE_TABLE_USED, MYF(0), table->s->table_name.str); DBUG_RETURN(0); } @@ -2843,7 +2843,7 @@ TABLE *open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT *mem_root, } else { - VOID(pthread_mutex_unlock(&LOCK_open)); + pthread_mutex_unlock(&LOCK_open); } /* There is a refresh in progress for this table. @@ -2876,7 +2876,7 @@ TABLE *open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT *mem_root, DBUG_PRINT("tcache", ("opening new table")); /* Free cache if too big */ while (open_cache.records > table_cache_size && unused_tables) - VOID(my_hash_delete(&open_cache,(uchar*) unused_tables)); /* purecov: tested */ + my_hash_delete(&open_cache,(uchar*) unused_tables); /* purecov: tested */ if (table_list->create) { @@ -2884,7 +2884,7 @@ TABLE *open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT *mem_root, if (check_if_table_exists(thd, table_list, &exists)) { - VOID(pthread_mutex_unlock(&LOCK_open)); + pthread_mutex_unlock(&LOCK_open); DBUG_RETURN(NULL); } @@ -2895,7 +2895,7 @@ TABLE *open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT *mem_root, */ if (!(table= table_cache_insert_placeholder(thd, key, key_length))) { - VOID(pthread_mutex_unlock(&LOCK_open)); + pthread_mutex_unlock(&LOCK_open); DBUG_RETURN(NULL); } /* @@ -2906,7 +2906,7 @@ TABLE *open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT *mem_root, table->open_placeholder= 1; table->next= thd->open_tables; thd->open_tables= table; - VOID(pthread_mutex_unlock(&LOCK_open)); + pthread_mutex_unlock(&LOCK_open); DBUG_RETURN(table); } /* Table exists. Let us try to open it. */ @@ -2915,7 +2915,7 @@ TABLE *open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT *mem_root, /* make a new table */ if (!(table=(TABLE*) my_malloc(sizeof(*table),MYF(MY_WME)))) { - VOID(pthread_mutex_unlock(&LOCK_open)); + pthread_mutex_unlock(&LOCK_open); DBUG_RETURN(NULL); } @@ -2924,7 +2924,7 @@ TABLE *open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT *mem_root, if (error > 0) { my_free((uchar*)table, MYF(0)); - VOID(pthread_mutex_unlock(&LOCK_open)); + pthread_mutex_unlock(&LOCK_open); DBUG_RETURN(NULL); } if (table_list->view || error < 0) @@ -2937,18 +2937,18 @@ TABLE *open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT *mem_root, table_list->view= (LEX*)1; my_free((uchar*)table, MYF(0)); - VOID(pthread_mutex_unlock(&LOCK_open)); + pthread_mutex_unlock(&LOCK_open); DBUG_RETURN(0); // VIEW } DBUG_PRINT("info", ("inserting table '%s'.'%s' 0x%lx into the cache", table->s->db.str, table->s->table_name.str, (long) table)); - VOID(my_hash_insert(&open_cache,(uchar*) table)); + (void) my_hash_insert(&open_cache,(uchar*) table); } check_unused(); // Debugging call - VOID(pthread_mutex_unlock(&LOCK_open)); + pthread_mutex_unlock(&LOCK_open); if (refresh) { table->next=thd->open_tables; /* Link into simple list */ @@ -3087,13 +3087,13 @@ bool reopen_table(TABLE *table) fix_merge_after_open(table->child_l, table->child_last_l, tmp.child_l, tmp.child_last_l)) { - VOID(closefrm(&tmp, 1)); // close file, free everything + (void) closefrm(&tmp, 1); // close file, free everything goto end; } delete table->triggers; if (table->file) - VOID(closefrm(table, 1)); // close file, free everything + (void) closefrm(table, 1); // close file, free everything *table= tmp; table->default_column_bitmaps(); @@ -3334,7 +3334,7 @@ bool reopen_tables(THD *thd, bool get_locks, bool mark_share_as_old) */ if (table->child_l || table->parent) detach_merge_children(table, TRUE); - VOID(my_hash_delete(&open_cache,(uchar*) table)); + my_hash_delete(&open_cache,(uchar*) table); error=1; } else @@ -3363,7 +3363,7 @@ bool reopen_tables(THD *thd, bool get_locks, bool mark_share_as_old) { while (err_tables) { - VOID(my_hash_delete(&open_cache, (uchar*) err_tables)); + my_hash_delete(&open_cache, (uchar*) err_tables); err_tables= err_tables->next; } } @@ -3645,7 +3645,7 @@ TABLE *drop_locked_tables(THD *thd,const char *db, const char *table_name) else { /* We already have a name lock, remove copy */ - VOID(my_hash_delete(&open_cache,(uchar*) table)); + my_hash_delete(&open_cache,(uchar*) table); } } else @@ -4252,7 +4252,7 @@ void detach_merge_children(TABLE *table, bool clear_refs) */ if ((first_detach= parent->children_attached)) { - VOID(parent->file->extra(HA_EXTRA_DETACH_CHILDREN)); + (void) parent->file->extra(HA_EXTRA_DETACH_CHILDREN); parent->children_attached= FALSE; DBUG_PRINT("myrg", ("detached parent: '%s'.'%s' 0x%lx", parent->s->db.str, parent->s->table_name.str, (long) parent)); @@ -8354,7 +8354,7 @@ my_bool mysql_rm_tmp_tables(void) So we hide error messages which happnes during deleting of these files(MYF(0)). */ - VOID(my_delete(filePath, MYF(0))); + (void) my_delete(filePath, MYF(0)); } } my_dirend(dirp); @@ -8396,7 +8396,7 @@ void remove_db_from_cache(const char *db) } } while (unused_tables && !unused_tables->s->version) - VOID(my_hash_delete(&open_cache,(uchar*) unused_tables)); + my_hash_delete(&open_cache,(uchar*) unused_tables); } @@ -8520,7 +8520,7 @@ bool remove_table_from_cache(THD *thd, const char *db, const char *table_name, } } while (unused_tables && !unused_tables->s->version) - VOID(my_hash_delete(&open_cache,(uchar*) unused_tables)); + my_hash_delete(&open_cache,(uchar*) unused_tables); DBUG_PRINT("info", ("Removing table from table_def_cache")); /* Remove table from table definition cache if it's not in use */ @@ -8533,7 +8533,7 @@ bool remove_table_from_cache(THD *thd, const char *db, const char *table_name, if (share->ref_count == 0) { pthread_mutex_lock(&share->mutex); - VOID(my_hash_delete(&table_def_cache, (uchar*) share)); + my_hash_delete(&table_def_cache, (uchar*) share); } } @@ -8710,12 +8710,12 @@ int abort_and_upgrade_lock(ALTER_PARTITION_PARAM_TYPE *lpt) DBUG_ENTER("abort_and_upgrade_locks"); lpt->old_lock_type= lpt->table->reginfo.lock_type; - VOID(pthread_mutex_lock(&LOCK_open)); + pthread_mutex_lock(&LOCK_open); /* If MERGE child, forward lock handling to parent. */ mysql_lock_abort(lpt->thd, lpt->table->parent ? lpt->table->parent : lpt->table, TRUE); - VOID(remove_table_from_cache(lpt->thd, lpt->db, lpt->table_name, flags)); - VOID(pthread_mutex_unlock(&LOCK_open)); + (void) remove_table_from_cache(lpt->thd, lpt->db, lpt->table_name, flags); + pthread_mutex_unlock(&LOCK_open); DBUG_RETURN(0); } @@ -8737,10 +8737,10 @@ int abort_and_upgrade_lock(ALTER_PARTITION_PARAM_TYPE *lpt) /* purecov: begin deadcode */ void close_open_tables_and_downgrade(ALTER_PARTITION_PARAM_TYPE *lpt) { - VOID(pthread_mutex_lock(&LOCK_open)); + pthread_mutex_lock(&LOCK_open); remove_table_from_cache(lpt->thd, lpt->db, lpt->table_name, RTFC_WAIT_OTHER_THREAD_FLAG); - VOID(pthread_mutex_unlock(&LOCK_open)); + pthread_mutex_unlock(&LOCK_open); /* If MERGE child, forward lock handling to parent. */ mysql_lock_downgrade_write(lpt->thd, lpt->table->parent ? lpt->table->parent : lpt->table, lpt->old_lock_type); @@ -8779,7 +8779,7 @@ void mysql_wait_completed_table(ALTER_PARTITION_PARAM_TYPE *lpt, TABLE *my_table DBUG_ENTER("mysql_wait_completed_table"); key_length=(uint) (strmov(strmov(key,lpt->db)+1,lpt->table_name)-key)+1; - VOID(pthread_mutex_lock(&LOCK_open)); + pthread_mutex_lock(&LOCK_open); HASH_SEARCH_STATE state; for (table= (TABLE*) my_hash_first(&open_cache,(uchar*) key,key_length, &state) ; @@ -8837,7 +8837,7 @@ void mysql_wait_completed_table(ALTER_PARTITION_PARAM_TYPE *lpt, TABLE *my_table */ mysql_lock_abort(lpt->thd, my_table->parent ? my_table->parent : my_table, FALSE); - VOID(pthread_mutex_unlock(&LOCK_open)); + pthread_mutex_unlock(&LOCK_open); DBUG_VOID_RETURN; } diff --git a/sql/sql_cache.cc b/sql/sql_cache.cc index ed6f593cc2e..fb370cbd16a 100644 --- a/sql/sql_cache.cc +++ b/sql/sql_cache.cc @@ -2126,8 +2126,8 @@ ulong Query_cache::init_cache() DUMP(this); - VOID(my_hash_init(&queries, &my_charset_bin, def_query_hash_size, 0, 0, - query_cache_query_get_key, 0, 0)); + (void) my_hash_init(&queries, &my_charset_bin, def_query_hash_size, 0, 0, + query_cache_query_get_key, 0, 0); #ifndef FN_NO_CASE_SENCE /* If lower_case_table_names!=0 then db and table names are already @@ -2137,8 +2137,8 @@ ulong Query_cache::init_cache() lower_case_table_names == 0 then we should distinguish my_table and MY_TABLE cases and so again can use binary collation. */ - VOID(my_hash_init(&tables, &my_charset_bin, def_table_hash_size, 0, 0, - query_cache_table_get_key, 0, 0)); + (void) my_hash_init(&tables, &my_charset_bin, def_table_hash_size, 0, 0, + query_cache_table_get_key, 0, 0); #else /* On windows, OS/2, MacOS X with HFS+ or any other case insensitive @@ -2148,10 +2148,11 @@ ulong Query_cache::init_cache() file system) and so should use case insensitive collation for comparison. */ - VOID(my_hash_init(&tables, - lower_case_table_names ? &my_charset_bin : - files_charset_info, - def_table_hash_size, 0, 0,query_cache_table_get_key, 0, 0)); + (void) my_hash_init(&tables, + lower_case_table_names ? &my_charset_bin : + files_charset_info, + def_table_hash_size, 0, 0,query_cache_table_get_key, + 0, 0); #endif queries_in_cache = 0; diff --git a/sql/sql_connect.cc b/sql/sql_connect.cc index 959209df412..f5f962a02a3 100644 --- a/sql/sql_connect.cc +++ b/sql/sql_connect.cc @@ -410,7 +410,7 @@ check_user(THD *thd, enum enum_server_command command, pthread_mutex_lock(&LOCK_connection_count); bool count_ok= connection_count <= max_connections || (thd->main_security_ctx.master_access & SUPER_ACL); - VOID(pthread_mutex_unlock(&LOCK_connection_count)); + pthread_mutex_unlock(&LOCK_connection_count); if (!count_ok) { // too many connections diff --git a/sql/sql_db.cc b/sql/sql_db.cc index 3198791d5d1..17626f05aa1 100644 --- a/sql/sql_db.cc +++ b/sql/sql_db.cc @@ -643,7 +643,7 @@ int mysql_create_db(THD *thd, char *db, HA_CREATE_INFO *create_info, goto exit2; } - VOID(pthread_mutex_lock(&LOCK_mysql_create_db)); + pthread_mutex_lock(&LOCK_mysql_create_db); /* Check directory */ path_len= build_table_filename(path, sizeof(path) - 1, db, "", "", 0); @@ -753,7 +753,7 @@ not_silent: } exit: - VOID(pthread_mutex_unlock(&LOCK_mysql_create_db)); + pthread_mutex_unlock(&LOCK_mysql_create_db); start_waiting_global_read_lock(thd); exit2: DBUG_RETURN(error); @@ -784,7 +784,7 @@ bool mysql_alter_db(THD *thd, const char *db, HA_CREATE_INFO *create_info) if ((error=wait_if_global_read_lock(thd,0,1))) goto exit2; - VOID(pthread_mutex_lock(&LOCK_mysql_create_db)); + pthread_mutex_lock(&LOCK_mysql_create_db); /* Recreate db options file: /dbpath/.db.opt @@ -830,7 +830,7 @@ bool mysql_alter_db(THD *thd, const char *db, HA_CREATE_INFO *create_info) my_ok(thd, result); exit: - VOID(pthread_mutex_unlock(&LOCK_mysql_create_db)); + pthread_mutex_unlock(&LOCK_mysql_create_db); start_waiting_global_read_lock(thd); exit2: DBUG_RETURN(error); @@ -882,7 +882,7 @@ bool mysql_rm_db(THD *thd,char *db,bool if_exists, bool silent) goto exit2; } - VOID(pthread_mutex_lock(&LOCK_mysql_create_db)); + pthread_mutex_lock(&LOCK_mysql_create_db); length= build_table_filename(path, sizeof(path) - 1, db, "", "", 0); strmov(path+length, MY_DB_OPT_FILE); // Append db option file name @@ -1030,7 +1030,7 @@ exit: */ if (thd->db && !strcmp(thd->db, db) && error == 0) mysql_change_db_impl(thd, NULL, 0, thd->variables.collation_server); - VOID(pthread_mutex_unlock(&LOCK_mysql_create_db)); + pthread_mutex_unlock(&LOCK_mysql_create_db); start_waiting_global_read_lock(thd); exit2: DBUG_RETURN(error); @@ -1143,9 +1143,9 @@ static long mysql_rm_known_files(THD *thd, MY_DIR *dirp, const char *db, goto err; table_list->db= (char*) (table_list+1); table_list->table_name= strmov(table_list->db, db) + 1; - VOID(filename_to_tablename(file->name, table_list->table_name, + (void) filename_to_tablename(file->name, table_list->table_name, MYSQL50_TABLE_NAME_PREFIX_LENGTH + - strlen(file->name) + 1)); + strlen(file->name) + 1); table_list->alias= table_list->table_name; // If lower_case_table_names=2 table_list->internal_tmp_table= is_prefix(file->name, tmp_file_prefix); /* Link into list */ diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc index 6b59cbc14c1..d8aa27c9695 100644 --- a/sql/sql_delete.cc +++ b/sql/sql_delete.cc @@ -1166,10 +1166,10 @@ bool mysql_truncate(THD *thd, TABLE_LIST *table_list, bool dont_send_ok) // crashes, replacement works. *(path + path_length - reg_ext_length)= // '\0'; path[path_length - reg_ext_length] = 0; - VOID(pthread_mutex_lock(&LOCK_open)); + pthread_mutex_lock(&LOCK_open); error= ha_create_table(thd, path, table_list->db, table_list->table_name, &create_info, 1); - VOID(pthread_mutex_unlock(&LOCK_open)); + pthread_mutex_unlock(&LOCK_open); query_cache_invalidate3(thd, table_list, 0); end: @@ -1184,15 +1184,15 @@ end: write_bin_log(thd, TRUE, thd->query(), thd->query_length()); my_ok(thd); // This should return record count } - VOID(pthread_mutex_lock(&LOCK_open)); + pthread_mutex_lock(&LOCK_open); unlock_table_name(thd, table_list); - VOID(pthread_mutex_unlock(&LOCK_open)); + pthread_mutex_unlock(&LOCK_open); } else if (error) { - VOID(pthread_mutex_lock(&LOCK_open)); + pthread_mutex_lock(&LOCK_open); unlock_table_name(thd, table_list); - VOID(pthread_mutex_unlock(&LOCK_open)); + pthread_mutex_unlock(&LOCK_open); } DBUG_RETURN(error); diff --git a/sql/sql_handler.cc b/sql/sql_handler.cc index ab3f2797405..da5ee93fcb9 100644 --- a/sql/sql_handler.cc +++ b/sql/sql_handler.cc @@ -143,14 +143,14 @@ static void mysql_ha_close_table(THD *thd, TABLE_LIST *tables, { (*table_ptr)->file->ha_index_or_rnd_end(); if (! is_locked) - VOID(pthread_mutex_lock(&LOCK_open)); + pthread_mutex_lock(&LOCK_open); if (close_thread_table(thd, table_ptr)) { /* Tell threads waiting for refresh that something has happened */ broadcast_refresh(); } if (! is_locked) - VOID(pthread_mutex_unlock(&LOCK_open)); + pthread_mutex_unlock(&LOCK_open); } else if (tables->table) { diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index b1c7c7f647e..278ad522c23 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -1033,7 +1033,7 @@ static bool check_view_insertability(THD * thd, TABLE_LIST *view) DBUG_ASSERT(view->table != 0 && view->field_translation != 0); - VOID(bitmap_init(&used_fields, used_fields_buff, table->s->fields, 0)); + (void) bitmap_init(&used_fields, used_fields_buff, table->s->fields, 0); bitmap_clear_all(&used_fields); view->contain_auto_increment= 0; @@ -1766,11 +1766,11 @@ public: pthread_mutex_init(&mutex,MY_MUTEX_INIT_FAST); pthread_cond_init(&cond,NULL); pthread_cond_init(&cond_client,NULL); - VOID(pthread_mutex_lock(&LOCK_thread_count)); + pthread_mutex_lock(&LOCK_thread_count); delayed_insert_threads++; delayed_lock= global_system_variables.low_priority_updates ? TL_WRITE_LOW_PRIORITY : TL_WRITE; - VOID(pthread_mutex_unlock(&LOCK_thread_count)); + pthread_mutex_unlock(&LOCK_thread_count); } ~Delayed_insert() { @@ -1780,7 +1780,7 @@ public: delete row; if (table) close_thread_tables(&thd); - VOID(pthread_mutex_lock(&LOCK_thread_count)); + pthread_mutex_lock(&LOCK_thread_count); pthread_mutex_destroy(&mutex); pthread_cond_destroy(&cond); pthread_cond_destroy(&cond_client); @@ -1789,8 +1789,8 @@ public: thd.security_ctx->user= thd.security_ctx->host=0; thread_count--; delayed_insert_threads--; - VOID(pthread_mutex_unlock(&LOCK_thread_count)); - VOID(pthread_cond_broadcast(&COND_thread_count)); /* Tell main we are ready */ + pthread_mutex_unlock(&LOCK_thread_count); + pthread_cond_broadcast(&COND_thread_count); /* Tell main we are ready */ } /* The following is for checking when we can delete ourselves */ @@ -2262,7 +2262,7 @@ static void end_delayed_insert(THD *thd) void kill_delayed_threads(void) { - VOID(pthread_mutex_lock(&LOCK_delayed_insert)); // For unlink from list + pthread_mutex_lock(&LOCK_delayed_insert); // For unlink from list I_List_iterator it(delayed_threads); Delayed_insert *di; @@ -2287,7 +2287,7 @@ void kill_delayed_threads(void) pthread_mutex_unlock(&di->thd.mysys_var->mutex); } } - VOID(pthread_mutex_unlock(&LOCK_delayed_insert)); // For unlink from list + pthread_mutex_unlock(&LOCK_delayed_insert); // For unlink from list } @@ -3499,7 +3499,7 @@ static TABLE *create_table_from_items(THD *thd, HA_CREATE_INFO *create_info, if (!(create_info->options & HA_LEX_CREATE_TMP_TABLE)) { - VOID(pthread_mutex_lock(&LOCK_open)); + pthread_mutex_lock(&LOCK_open); if (reopen_name_locked_table(thd, create_table, FALSE)) { quick_rm_table(create_info->db_type, create_table->db, @@ -3508,7 +3508,7 @@ static TABLE *create_table_from_items(THD *thd, HA_CREATE_INFO *create_info, } else table= create_table->table; - VOID(pthread_mutex_unlock(&LOCK_open)); + pthread_mutex_unlock(&LOCK_open); } else { diff --git a/sql/sql_map.cc b/sql/sql_map.cc index 55f9b08d3fe..7f77ce1212d 100644 --- a/sql/sql_map.cc +++ b/sql/sql_map.cc @@ -48,12 +48,12 @@ mapped_files::mapped_files(const char * filename,uchar *magic,uint magic_length) if (map && memcmp(map,magic,magic_length)) { my_error(ER_WRONG_MAGIC, MYF(0), name); - VOID(my_munmap((char*) map,(size_t)size)); + (void) my_munmap((char*) map,(size_t)size); map=0; } if (!map) { - VOID(my_close(file,MYF(0))); + (void) my_close(file,MYF(0)); file= -1; } } @@ -66,8 +66,8 @@ mapped_files::~mapped_files() #ifdef HAVE_MMAP if (file >= 0) { - VOID(my_munmap((char*) map,(size_t)size)); - VOID(my_close(file,MYF(0))); + (void) my_munmap((char*) map,(size_t)size); + (void) my_close(file,MYF(0)); file= -1; map=0; } my_free(name,MYF(0)); @@ -85,7 +85,7 @@ static I_List maps_in_use; mapped_files *map_file(const char * name,uchar *magic,uint magic_length) { #ifdef HAVE_MMAP - VOID(pthread_mutex_lock(&LOCK_mapped_file)); + pthread_mutex_lock(&LOCK_mapped_file); I_List_iterator list(maps_in_use); mapped_files *map; char path[FN_REFLEN]; @@ -108,7 +108,7 @@ mapped_files *map_file(const char * name,uchar *magic,uint magic_length) if (!map->map) my_error(ER_NO_FILE_MAPPING, MYF(0), path, map->error); } - VOID(pthread_mutex_unlock(&LOCK_mapped_file)); + pthread_mutex_unlock(&LOCK_mapped_file); return map; #else return NULL; @@ -122,10 +122,10 @@ mapped_files *map_file(const char * name,uchar *magic,uint magic_length) void unmap_file(mapped_files *map) { #ifdef HAVE_MMAP - VOID(pthread_mutex_lock(&LOCK_mapped_file)); + pthread_mutex_lock(&LOCK_mapped_file); if (!map->use_count--) delete map; - VOID(pthread_mutex_unlock(&LOCK_mapped_file)); + pthread_mutex_unlock(&LOCK_mapped_file); #endif } diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 0aee5e4bd06..1271c3112ff 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -983,7 +983,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd, thd->enable_slow_log= TRUE; thd->lex->sql_command= SQLCOM_END; /* to avoid confusing VIEW detectors */ thd->set_time(); - VOID(pthread_mutex_lock(&LOCK_thread_count)); + pthread_mutex_lock(&LOCK_thread_count); thd->query_id= global_query_id; switch( command ) { @@ -1005,7 +1005,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd, thread_running++; /* TODO: set thd->lex->sql_command to SQLCOM_END here */ - VOID(pthread_mutex_unlock(&LOCK_thread_count)); + pthread_mutex_unlock(&LOCK_thread_count); /** Clear the set of flags that are expected to be cleared at the @@ -1268,7 +1268,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd, (char *) thd->security_ctx->host_or_ip); thd->set_query(beginning_of_next_stmt, length); - VOID(pthread_mutex_lock(&LOCK_thread_count)); + pthread_mutex_lock(&LOCK_thread_count); /* Count each statement from the client. */ @@ -1276,7 +1276,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd, thd->query_id= next_query_id(); thd->set_time(); /* Reset the query start time. */ /* TODO: set thd->lex->sql_command to SQLCOM_END here */ - VOID(pthread_mutex_unlock(&LOCK_thread_count)); + pthread_mutex_unlock(&LOCK_thread_count); mysql_parse(thd, beginning_of_next_stmt, length, &end_of_stmt); } @@ -1494,8 +1494,8 @@ bool dispatch_command(enum enum_server_command command, THD *thd, } #endif #ifndef EMBEDDED_LIBRARY - VOID(my_net_write(net, (uchar*) buff, length)); - VOID(net_flush(net)); + (void) my_net_write(net, (uchar*) buff, length); + (void) net_flush(net); thd->stmt_da->disable_status(); #endif break; @@ -1590,9 +1590,9 @@ bool dispatch_command(enum enum_server_command command, THD *thd, thd_proc_info(thd, "cleaning up"); thd->set_query(NULL, 0); thd->command=COM_SLEEP; - VOID(pthread_mutex_lock(&LOCK_thread_count)); // For process list + pthread_mutex_lock(&LOCK_thread_count); // For process list thread_running--; - VOID(pthread_mutex_unlock(&LOCK_thread_count)); + pthread_mutex_unlock(&LOCK_thread_count); thd_proc_info(thd, 0); thd->packet.shrink(thd->variables.net_buffer_length); // Reclaim some memory free_root(thd->mem_root,MYF(MY_KEEP_PREALLOC)); @@ -7181,7 +7181,7 @@ uint kill_one_thread(THD *thd, ulong id, bool only_kill_query) uint error=ER_NO_SUCH_THREAD; DBUG_ENTER("kill_one_thread"); DBUG_PRINT("enter", ("id=%lu only_kill=%d", id, only_kill_query)); - VOID(pthread_mutex_lock(&LOCK_thread_count)); // For unlink from list + pthread_mutex_lock(&LOCK_thread_count); // For unlink from list I_List_iterator it(threads); while ((tmp=it++)) { @@ -7193,7 +7193,7 @@ uint kill_one_thread(THD *thd, ulong id, bool only_kill_query) break; } } - VOID(pthread_mutex_unlock(&LOCK_thread_count)); + pthread_mutex_unlock(&LOCK_thread_count); if (tmp) { diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 5fdab6b6f2f..fc1a378c371 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -3954,7 +3954,7 @@ update_ref_and_keys(THD *thd, DYNAMIC_ARRAY *keyuse,JOIN_TAB *join_tab, save_pos++; } i=(uint) (save_pos-(KEYUSE*) keyuse->buffer); - VOID(set_dynamic(keyuse,(uchar*) &key_end,i)); + (void) set_dynamic(keyuse,(uchar*) &key_end,i); keyuse->elements=i; } return FALSE; @@ -9189,7 +9189,7 @@ remove_eq_conds(THD *thd, COND *cond, Item::cond_result *cond_value) li.remove(); else if (item != new_item) { - VOID(li.replace(new_item)); + (void) li.replace(new_item); should_fix_fields=1; } if (*cond_value == Item::COND_UNDEF) @@ -11055,7 +11055,7 @@ do_select(JOIN *join,List *fields,TABLE *table,Procedure *procedure) if (table) { - VOID(table->file->extra(HA_EXTRA_WRITE_CACHE)); + (void) table->file->extra(HA_EXTRA_WRITE_CACHE); empty_record(table); if (table->group && join->tmp_table_param.sum_func_count && table->s->keys && !table->file->inited) @@ -12401,7 +12401,7 @@ end_send_group(JOIN *join, JOIN_TAB *join_tab __attribute__((unused)), if (end_of_records) DBUG_RETURN(NESTED_LOOP_OK); join->first_record=1; - VOID(test_if_group_changed(join->group_fields)); + (void) test_if_group_changed(join->group_fields); } if (idx < (int) join->send_group_parts) { @@ -12664,7 +12664,7 @@ end_write_group(JOIN *join, JOIN_TAB *join_tab __attribute__((unused)), if (end_of_records) DBUG_RETURN(NESTED_LOOP_OK); join->first_record=1; - VOID(test_if_group_changed(join->group_fields)); + (void) test_if_group_changed(join->group_fields); } if (idx < (int) join->send_group_parts) { diff --git a/sql/sql_servers.cc b/sql/sql_servers.cc index be86d1150b7..e5fe06ce39b 100644 --- a/sql/sql_servers.cc +++ b/sql/sql_servers.cc @@ -664,8 +664,8 @@ delete_server_record_in_cache(LEX_SERVER_OPTIONS *server_options) server->server_name, server->server_name_length)); - VOID(my_hash_delete(&servers_cache, (uchar*) server)); - + my_hash_delete(&servers_cache, (uchar*) server); + error= 0; end: @@ -771,7 +771,7 @@ int update_server_record_in_cache(FOREIGN_SERVER *existing, /* delete the existing server struct from the server cache */ - VOID(my_hash_delete(&servers_cache, (uchar*)existing)); + my_hash_delete(&servers_cache, (uchar*)existing); /* Insert the altered server struct into the server cache diff --git a/sql/sql_show.cc b/sql/sql_show.cc index 7b7f5741d5a..babadc34842 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -495,7 +495,7 @@ find_files(THD *thd, List *files, const char *db, DBUG_PRINT("info",("found: %d files", files->elements)); my_dirend(dirp); - VOID(ha_find_files(thd, db, path, wild, dir, files)); + (void) ha_find_files(thd, db, path, wild, dir, files); DBUG_RETURN(FIND_FILES_OK); } @@ -936,7 +936,7 @@ append_identifier(THD *thd, String *packet, const char *name, uint length) it's a keyword */ - VOID(packet->reserve(length*2 + 2)); + (void) packet->reserve(length*2 + 2); quote_char= (char) q; packet->append("e_char, 1, system_charset_info); @@ -1755,7 +1755,7 @@ void mysqld_list_processes(THD *thd,const char *user, bool verbose) Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF)) DBUG_VOID_RETURN; - VOID(pthread_mutex_lock(&LOCK_thread_count)); // For unlink from list + pthread_mutex_lock(&LOCK_thread_count); // For unlink from list if (!thd->killed) { I_List_iterator it(threads); @@ -1808,7 +1808,7 @@ void mysqld_list_processes(THD *thd,const char *user, bool verbose) } } } - VOID(pthread_mutex_unlock(&LOCK_thread_count)); + pthread_mutex_unlock(&LOCK_thread_count); thread_info *thd_info; time_t now= my_time(0); @@ -1847,7 +1847,7 @@ int fill_schema_processlist(THD* thd, TABLE_LIST* tables, COND* cond) user= thd->security_ctx->master_access & PROCESS_ACL ? NullS : thd->security_ctx->priv_user; - VOID(pthread_mutex_lock(&LOCK_thread_count)); + pthread_mutex_lock(&LOCK_thread_count); if (!thd->killed) { @@ -1922,13 +1922,13 @@ int fill_schema_processlist(THD* thd, TABLE_LIST* tables, COND* cond) if (schema_table_store_record(thd, table)) { - VOID(pthread_mutex_unlock(&LOCK_thread_count)); + pthread_mutex_unlock(&LOCK_thread_count); DBUG_RETURN(1); } } } - VOID(pthread_mutex_unlock(&LOCK_thread_count)); + pthread_mutex_unlock(&LOCK_thread_count); DBUG_RETURN(0); } @@ -2285,7 +2285,7 @@ void calc_sum_of_all_status(STATUS_VAR *to) DBUG_ENTER("calc_sum_of_all_status"); /* Ensure that thread id not killed during loop */ - VOID(pthread_mutex_lock(&LOCK_thread_count)); // For unlink from list + pthread_mutex_lock(&LOCK_thread_count); // For unlink from list I_List_iterator it(threads); THD *tmp; @@ -2297,7 +2297,7 @@ void calc_sum_of_all_status(STATUS_VAR *to) while ((tmp= it++)) add_to_status(to, &tmp->status_var); - VOID(pthread_mutex_unlock(&LOCK_thread_count)); + pthread_mutex_unlock(&LOCK_thread_count); DBUG_VOID_RETURN; } @@ -2852,9 +2852,9 @@ make_table_name_list(THD *thd, List *table_names, LEX *lex, Check that table is relevant in current transaction. (used for ndb engine, see ndbcluster_find_files(), ha_ndbcluster.cc) */ - VOID(ha_find_files(thd, db_name->str, path, + (void) ha_find_files(thd, db_name->str, path, lookup_field_vals->table_value.str, 0, - table_names)); + table_names); } return 0; } diff --git a/sql/sql_string.cc b/sql/sql_string.cc index a0ea75a0b0a..40040ab0934 100644 --- a/sql/sql_string.cc +++ b/sql/sql_string.cc @@ -120,7 +120,7 @@ bool String::set_real(double num,uint decimals, CHARSET_INFO *cs) int decpt,sign; char *pos,*to; - VOID(fconvert(num,(int) decimals,&decpt,&sign,buff+1)); + (void) fconvert(num,(int) decimals,&decpt,&sign,buff+1); if (!my_isdigit(&my_charset_latin1, buff[1])) { // Nan or Inf pos=buff+1; diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 150a896103c..dc0c876e882 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -493,9 +493,9 @@ uint build_table_filename(char *buff, size_t bufflen, const char *db, if (flags & FN_IS_TMP) // FN_FROM_IS_TMP | FN_TO_IS_TMP strnmov(tbbuff, table_name, sizeof(tbbuff)); else - VOID(tablename_to_filename(table_name, tbbuff, sizeof(tbbuff))); + (void) tablename_to_filename(table_name, tbbuff, sizeof(tbbuff)); - VOID(tablename_to_filename(db, dbbuff, sizeof(dbbuff))); + (void) tablename_to_filename(db, dbbuff, sizeof(dbbuff)); char *end = buff + bufflen; /* Don't add FN_ROOTDIR if mysql_data_home already includes it */ @@ -695,7 +695,7 @@ static bool write_ddl_log_header() sql_print_error("Error writing ddl log header"); DBUG_RETURN(TRUE); } - VOID(sync_ddl_log()); + (void) sync_ddl_log(); DBUG_RETURN(error); } @@ -763,7 +763,7 @@ static uint read_ddl_log_header() global_ddl_log.first_free= NULL; global_ddl_log.first_used= NULL; global_ddl_log.num_entries= 0; - VOID(pthread_mutex_init(&LOCK_gdl, MY_MUTEX_INIT_FAST)); + pthread_mutex_init(&LOCK_gdl, MY_MUTEX_INIT_FAST); global_ddl_log.do_release= true; DBUG_RETURN(entry_no); } @@ -845,7 +845,7 @@ static bool init_ddl_log() global_ddl_log.inited= TRUE; if (write_ddl_log_header()) { - VOID(my_close(global_ddl_log.file_id, MYF(MY_WME))); + (void) my_close(global_ddl_log.file_id, MYF(MY_WME)); global_ddl_log.inited= FALSE; DBUG_RETURN(TRUE); } @@ -922,7 +922,7 @@ static int execute_ddl_log_action(THD *thd, DDL_LOG_ENTRY *ddl_log_entry) } #ifdef WITH_PARTITION_STORAGE_ENGINE strxmov(to_path, ddl_log_entry->name, par_ext, NullS); - VOID(my_delete(to_path, MYF(MY_WME))); + (void) my_delete(to_path, MYF(MY_WME)); #endif } else @@ -935,7 +935,7 @@ static int execute_ddl_log_action(THD *thd, DDL_LOG_ENTRY *ddl_log_entry) } if ((deactivate_ddl_log_entry(ddl_log_entry->entry_pos))) break; - VOID(sync_ddl_log()); + (void) sync_ddl_log(); error= FALSE; if (ddl_log_entry->action_type == DDL_LOG_DELETE_ACTION) break; @@ -959,7 +959,7 @@ static int execute_ddl_log_action(THD *thd, DDL_LOG_ENTRY *ddl_log_entry) #ifdef WITH_PARTITION_STORAGE_ENGINE strxmov(to_path, ddl_log_entry->name, par_ext, NullS); strxmov(from_path, ddl_log_entry->from_name, par_ext, NullS); - VOID(my_rename(from_path, to_path, MYF(MY_WME))); + (void) my_rename(from_path, to_path, MYF(MY_WME)); #endif } else @@ -970,7 +970,7 @@ static int execute_ddl_log_action(THD *thd, DDL_LOG_ENTRY *ddl_log_entry) } if ((deactivate_ddl_log_entry(ddl_log_entry->entry_pos))) break; - VOID(sync_ddl_log()); + (void) sync_ddl_log(); error= FALSE; break; } @@ -1099,7 +1099,7 @@ bool write_ddl_log_entry(DDL_LOG_ENTRY *ddl_log_entry, } if (write_header && !error) { - VOID(sync_ddl_log()); + (void) sync_ddl_log(); if (write_ddl_log_header()) error= TRUE; } @@ -1156,7 +1156,7 @@ bool write_execute_ddl_log_entry(uint first_entry, any log entries before, we are only here to write the execute entry to indicate it is done. */ - VOID(sync_ddl_log()); + (void) sync_ddl_log(); file_entry_buf[DDL_LOG_ENTRY_TYPE_POS]= (char)DDL_LOG_EXECUTE_CODE; } else @@ -1180,7 +1180,7 @@ bool write_execute_ddl_log_entry(uint first_entry, release_ddl_log_memory_entry(*active_entry); DBUG_RETURN(TRUE); } - VOID(sync_ddl_log()); + (void) sync_ddl_log(); if (write_header) { if (write_ddl_log_header()) @@ -1372,7 +1372,7 @@ static void close_ddl_log() DBUG_ENTER("close_ddl_log"); if (global_ddl_log.file_id >= 0) { - VOID(my_close(global_ddl_log.file_id, MYF(MY_WME))); + (void) my_close(global_ddl_log.file_id, MYF(MY_WME)); global_ddl_log.file_id= (File) -1; } DBUG_VOID_RETURN; @@ -1432,7 +1432,7 @@ void execute_ddl_log_recovery() } close_ddl_log(); create_ddl_log_file_name(file_name); - VOID(my_delete(file_name, MYF(0))); + (void) my_delete(file_name, MYF(0)); global_ddl_log.recovery_phase= FALSE; delete thd; /* Remember that we don't have a THD */ @@ -1474,7 +1474,7 @@ void release_ddl_log() close_ddl_log(); global_ddl_log.inited= 0; pthread_mutex_unlock(&LOCK_gdl); - VOID(pthread_mutex_destroy(&LOCK_gdl)); + pthread_mutex_destroy(&LOCK_gdl); global_ddl_log.do_release= false; DBUG_VOID_RETURN; } @@ -1653,7 +1653,7 @@ bool mysql_write_frm(ALTER_PARTITION_PARAM_TYPE *lpt, uint flags) completing this we write a new phase to the log entry that will deactivate it. */ - VOID(pthread_mutex_lock(&LOCK_open)); + pthread_mutex_lock(&LOCK_open); if (my_delete(frm_name, MYF(MY_WME)) || #ifdef WITH_PARTITION_STORAGE_ENGINE lpt->table->file->ha_create_handler_files(path, shadow_path, @@ -1706,11 +1706,11 @@ bool mysql_write_frm(ALTER_PARTITION_PARAM_TYPE *lpt, uint flags) #endif err: - VOID(pthread_mutex_unlock(&LOCK_open)); + pthread_mutex_unlock(&LOCK_open); #ifdef WITH_PARTITION_STORAGE_ENGINE deactivate_ddl_log_entry(part_info->frm_log_entry->entry_pos); part_info->frm_log_entry= NULL; - VOID(sync_ddl_log()); + (void) sync_ddl_log(); #endif } @@ -3870,7 +3870,7 @@ bool mysql_create_table_no_lock(THD *thd, goto err; } - VOID(pthread_mutex_lock(&LOCK_open)); + pthread_mutex_lock(&LOCK_open); if (!internal_tmp_table && !(create_info->options & HA_LEX_CREATE_TMP_TABLE)) { if (!access(path,F_OK)) @@ -3987,7 +3987,7 @@ bool mysql_create_table_no_lock(THD *thd, write_create_table_bin_log(thd, create_info, internal_tmp_table); error= FALSE; unlock_and_end: - VOID(pthread_mutex_unlock(&LOCK_open)); + pthread_mutex_unlock(&LOCK_open); err: thd_proc_info(thd, "After create"); @@ -4241,7 +4241,7 @@ void wait_while_table_is_used(THD *thd, TABLE *table, safe_mutex_assert_owner(&LOCK_open); - VOID(table->file->extra(function)); + (void) table->file->extra(function); /* Mark all tables that are in use as 'old' */ mysql_lock_abort(thd, table, TRUE); /* end threads waiting on lock */ @@ -4323,7 +4323,7 @@ static int prepare_for_restore(THD* thd, TABLE_LIST* table, char* table_name= table->table_name; char* db= table->db; - VOID(tablename_to_filename(table->table_name, uname, sizeof(uname) - 1)); + tablename_to_filename(table->table_name, uname, sizeof(uname) - 1); if (fn_format_relative_to_data_home(src_path, uname, backup_dir, reg_ext)) DBUG_RETURN(-1); // protect buffer overflow @@ -5336,12 +5336,12 @@ bool mysql_create_like_table(THD* thd, TABLE_LIST* table, TABLE_LIST* src_table, Also some engines (e.g. NDB cluster) require that LOCK_open should be held during the call to ha_create_table(). See bug #28614 for more info. */ - VOID(pthread_mutex_lock(&LOCK_open)); + pthread_mutex_lock(&LOCK_open); if (src_table->schema_table) { if (mysql_create_like_schema_frm(thd, src_table, dst_path, create_info)) { - VOID(pthread_mutex_unlock(&LOCK_open)); + pthread_mutex_unlock(&LOCK_open); goto err; } } @@ -5351,7 +5351,7 @@ bool mysql_create_like_table(THD* thd, TABLE_LIST* table, TABLE_LIST* src_table, my_error(ER_BAD_DB_ERROR,MYF(0),db); else my_error(ER_CANT_CREATE_FILE,MYF(0),dst_path,my_errno); - VOID(pthread_mutex_unlock(&LOCK_open)); + pthread_mutex_unlock(&LOCK_open); goto err; } @@ -5380,7 +5380,7 @@ bool mysql_create_like_table(THD* thd, TABLE_LIST* table, TABLE_LIST* src_table, if (thd->variables.keep_files_on_create) create_info->options|= HA_CREATE_KEEP_FILES; err= ha_create_table(thd, dst_path, db, table_name, create_info, 1); - VOID(pthread_mutex_unlock(&LOCK_open)); + pthread_mutex_unlock(&LOCK_open); if (create_info->options & HA_LEX_CREATE_TMP_TABLE) { @@ -5454,13 +5454,13 @@ binlog: of this function. */ table->table= name_lock; - VOID(pthread_mutex_lock(&LOCK_open)); + pthread_mutex_lock(&LOCK_open); if (reopen_name_locked_table(thd, table, FALSE)) { - VOID(pthread_mutex_unlock(&LOCK_open)); + pthread_mutex_unlock(&LOCK_open); goto err; } - VOID(pthread_mutex_unlock(&LOCK_open)); + pthread_mutex_unlock(&LOCK_open); int result __attribute__((unused))= store_create_info(thd, table, &query, @@ -6563,7 +6563,7 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name, if (wait_if_global_read_lock(thd,0,1)) DBUG_RETURN(TRUE); - VOID(pthread_mutex_lock(&LOCK_open)); + pthread_mutex_lock(&LOCK_open); if (lock_table_names(thd, table_list)) { error= 1; @@ -6746,17 +6746,17 @@ view_err: while the fact that the table is still open gives us protection from concurrent DDL statements. */ - VOID(pthread_mutex_lock(&LOCK_open)); + pthread_mutex_lock(&LOCK_open); wait_while_table_is_used(thd, table, HA_EXTRA_FORCE_REOPEN); - VOID(pthread_mutex_unlock(&LOCK_open)); + pthread_mutex_unlock(&LOCK_open); DBUG_EXECUTE_IF("sleep_alter_enable_indexes", my_sleep(6000000);); error= table->file->ha_enable_indexes(HA_KEY_SWITCH_NONUNIQ_SAVE); /* COND_refresh will be signaled in close_thread_tables() */ break; case DISABLE: - VOID(pthread_mutex_lock(&LOCK_open)); + pthread_mutex_lock(&LOCK_open); wait_while_table_is_used(thd, table, HA_EXTRA_FORCE_REOPEN); - VOID(pthread_mutex_unlock(&LOCK_open)); + pthread_mutex_unlock(&LOCK_open); error=table->file->ha_disable_indexes(HA_KEY_SWITCH_NONUNIQ_SAVE); /* COND_refresh will be signaled in close_thread_tables() */ break; @@ -6773,7 +6773,7 @@ view_err: table->alias); } - VOID(pthread_mutex_lock(&LOCK_open)); + pthread_mutex_lock(&LOCK_open); /* Unlike to the above case close_cached_table() below will remove ALL instances of TABLE from table cache (it will also remove table lock @@ -6812,8 +6812,8 @@ view_err: else if (Table_triggers_list::change_table_name(thd, db, table_name, new_db, new_alias)) { - VOID(mysql_rename_table(old_db_type, new_db, new_alias, db, - table_name, 0)); + (void) mysql_rename_table(old_db_type, new_db, new_alias, db, + table_name, 0); error= -1; } } @@ -6839,7 +6839,7 @@ view_err: } if (name_lock) unlink_open_table(thd, name_lock, FALSE); - VOID(pthread_mutex_unlock(&LOCK_open)); + pthread_mutex_unlock(&LOCK_open); table_list->table= NULL; // For query cache query_cache_invalidate3(thd, table_list, 0); DBUG_RETURN(error); @@ -7200,9 +7200,9 @@ view_err: } else { - VOID(pthread_mutex_lock(&LOCK_open)); + pthread_mutex_lock(&LOCK_open); wait_while_table_is_used(thd, table, HA_EXTRA_FORCE_REOPEN); - VOID(pthread_mutex_unlock(&LOCK_open)); + pthread_mutex_unlock(&LOCK_open); thd_proc_info(thd, "manage keys"); alter_table_manage_keys(table, table->file->indexes_are_disabled(), alter_info->keys_onoff); @@ -7332,11 +7332,11 @@ view_err: intern_close_table(new_table); my_free(new_table,MYF(0)); } - VOID(pthread_mutex_lock(&LOCK_open)); + pthread_mutex_lock(&LOCK_open); if (error) { - VOID(quick_rm_table(new_db_type, new_db, tmp_name, FN_IS_TMP)); - VOID(pthread_mutex_unlock(&LOCK_open)); + (void) quick_rm_table(new_db_type, new_db, tmp_name, FN_IS_TMP); + pthread_mutex_unlock(&LOCK_open); goto err; } @@ -7391,7 +7391,7 @@ view_err: FN_TO_IS_TMP)) { error=1; - VOID(quick_rm_table(new_db_type, new_db, tmp_name, FN_IS_TMP)); + (void) quick_rm_table(new_db_type, new_db, tmp_name, FN_IS_TMP); } else if (mysql_rename_table(new_db_type, new_db, tmp_name, new_db, new_alias, FN_FROM_IS_TMP) || @@ -7404,10 +7404,10 @@ view_err: { /* Try to get everything back. */ error=1; - VOID(quick_rm_table(new_db_type,new_db,new_alias, 0)); - VOID(quick_rm_table(new_db_type, new_db, tmp_name, FN_IS_TMP)); - VOID(mysql_rename_table(old_db_type, db, old_name, db, alias, - FN_FROM_IS_TMP)); + (void) quick_rm_table(new_db_type,new_db,new_alias, 0); + (void) quick_rm_table(new_db_type, new_db, tmp_name, FN_IS_TMP); + (void) mysql_rename_table(old_db_type, db, old_name, db, alias, + FN_FROM_IS_TMP); } if (error) @@ -7459,7 +7459,7 @@ view_err: } } - VOID(quick_rm_table(old_db_type, db, old_name, FN_IS_TMP)); + (void) quick_rm_table(old_db_type, db, old_name, FN_IS_TMP); if (thd->locked_tables && new_name == table_name && new_db == db) { @@ -7469,7 +7469,7 @@ view_err: if (error) goto err_with_placeholders; } - VOID(pthread_mutex_unlock(&LOCK_open)); + pthread_mutex_unlock(&LOCK_open); thd_proc_info(thd, "end"); @@ -7537,10 +7537,8 @@ err1: close_temporary_table(thd, new_table, 1, 1); } else - VOID(quick_rm_table(new_db_type, new_db, tmp_name, - create_info->frm_only - ? FN_IS_TMP | FRM_ONLY - : FN_IS_TMP)); + (void) quick_rm_table(new_db_type, new_db, tmp_name, + create_info->frm_only ? FN_IS_TMP | FRM_ONLY : FN_IS_TMP); err: /* @@ -7593,7 +7591,7 @@ err_with_placeholders: unlink_open_table(thd, table, FALSE); if (name_lock) unlink_open_table(thd, name_lock, FALSE); - VOID(pthread_mutex_unlock(&LOCK_open)); + pthread_mutex_unlock(&LOCK_open); DBUG_RETURN(TRUE); } /* mysql_alter_table */ diff --git a/sql/sql_test.cc b/sql/sql_test.cc index 6c0cb08cc79..d9beb77f546 100644 --- a/sql/sql_test.cc +++ b/sql/sql_test.cc @@ -80,7 +80,7 @@ void print_cached_tables(void) compile_time_assert(TL_WRITE_ONLY+1 == array_elements(lock_descriptions)); /* purecov: begin tested */ - VOID(pthread_mutex_lock(&LOCK_open)); + pthread_mutex_lock(&LOCK_open); puts("DB Table Version Thread Open Lock"); for (idx=unused=0 ; idx < open_cache.records ; idx++) @@ -116,7 +116,7 @@ void print_cached_tables(void) if (my_hash_check(&open_cache)) printf("Error: File hash table is corrupted\n"); fflush(stdout); - VOID(pthread_mutex_unlock(&LOCK_open)); + pthread_mutex_unlock(&LOCK_open); /* purecov: end */ return; } @@ -155,7 +155,7 @@ void TEST_filesort(SORT_FIELD *sortorder,uint s_length) } out.append('\0'); // Purify doesn't like c_ptr() DBUG_LOCK_FILE; - VOID(fputs("\nInfo about FILESORT\n",DBUG_FILE)); + (void) fputs("\nInfo about FILESORT\n",DBUG_FILE); fprintf(DBUG_FILE,"Sortorder: %s\n",out.ptr()); DBUG_UNLOCK_FILE; DBUG_VOID_RETURN; @@ -169,7 +169,7 @@ TEST_join(JOIN *join) DBUG_ENTER("TEST_join"); DBUG_LOCK_FILE; - VOID(fputs("\nInfo about JOIN\n",DBUG_FILE)); + (void) fputs("\nInfo about JOIN\n",DBUG_FILE); for (i=0 ; i < join->tables ; i++) { JOIN_TAB *tab=join->join_tab+i; @@ -195,17 +195,17 @@ TEST_join(JOIN *join) tab->select->quick->dbug_dump(18, FALSE); } else - VOID(fputs(" select used\n",DBUG_FILE)); + (void) fputs(" select used\n",DBUG_FILE); } if (tab->ref.key_parts) { - VOID(fputs(" refs: ",DBUG_FILE)); + (void) fputs(" refs: ",DBUG_FILE); for (ref=0 ; ref < tab->ref.key_parts ; ref++) { Item *item=tab->ref.items[ref]; fprintf(DBUG_FILE,"%s ", item->full_name()); } - VOID(fputc('\n',DBUG_FILE)); + (void) fputc('\n',DBUG_FILE); } } DBUG_UNLOCK_FILE; @@ -355,7 +355,7 @@ static void push_locks_into_array(DYNAMIC_ARRAY *ar, THR_LOCK_DATA *data, table_lock_info.lock_text=text; // lock_type is also obtainable from THR_LOCK_DATA table_lock_info.type=table->reginfo.lock_type; - VOID(push_dynamic(ar,(uchar*) &table_lock_info)); + (void) push_dynamic(ar,(uchar*) &table_lock_info); } } } @@ -380,13 +380,13 @@ static void display_table_locks(void) LIST *list; DYNAMIC_ARRAY saved_table_locks; - VOID(my_init_dynamic_array(&saved_table_locks,sizeof(TABLE_LOCK_INFO),open_cache.records + 20,50)); - VOID(pthread_mutex_lock(&THR_LOCK_lock)); + (void) my_init_dynamic_array(&saved_table_locks,sizeof(TABLE_LOCK_INFO),open_cache.records + 20,50); + pthread_mutex_lock(&THR_LOCK_lock); for (list= thr_lock_thread_list; list; list= list_rest(list)) { THR_LOCK *lock=(THR_LOCK*) list->data; - VOID(pthread_mutex_lock(&lock->mutex)); + pthread_mutex_lock(&lock->mutex); push_locks_into_array(&saved_table_locks, lock->write.data, FALSE, "Locked - write"); push_locks_into_array(&saved_table_locks, lock->write_wait.data, TRUE, @@ -395,9 +395,9 @@ static void display_table_locks(void) "Locked - read"); push_locks_into_array(&saved_table_locks, lock->read_wait.data, TRUE, "Waiting - read"); - VOID(pthread_mutex_unlock(&lock->mutex)); + pthread_mutex_unlock(&lock->mutex); } - VOID(pthread_mutex_unlock(&THR_LOCK_lock)); + pthread_mutex_unlock(&THR_LOCK_lock); if (!saved_table_locks.elements) goto end; qsort((uchar*) dynamic_element(&saved_table_locks,0,TABLE_LOCK_INFO *),saved_table_locks.elements,sizeof(TABLE_LOCK_INFO),(qsort_cmp) dl_compare); @@ -462,7 +462,7 @@ void mysql_print_status() calc_sum_of_all_status(&tmp); printf("\nStatus information:\n\n"); - VOID(my_getwd(current_dir, sizeof(current_dir),MYF(0))); + (void) my_getwd(current_dir, sizeof(current_dir),MYF(0)); printf("Current dir: %s\n", current_dir); printf("Running threads: %d Stack size: %ld\n", thread_count, (long) my_thread_stack_size); diff --git a/sql/sql_trigger.cc b/sql/sql_trigger.cc index d5c03d902e0..ecbb6473ec4 100644 --- a/sql/sql_trigger.cc +++ b/sql/sql_trigger.cc @@ -387,7 +387,7 @@ bool mysql_create_or_drop_trigger(THD *thd, TABLE_LIST *tables, bool create) !(need_start_waiting= !wait_if_global_read_lock(thd, 0, 1))) DBUG_RETURN(TRUE); - VOID(pthread_mutex_lock(&LOCK_open)); + pthread_mutex_lock(&LOCK_open); if (!create) { @@ -510,7 +510,7 @@ end: write_bin_log(thd, TRUE, stmt_query.ptr(), stmt_query.length()); } - VOID(pthread_mutex_unlock(&LOCK_open)); + pthread_mutex_unlock(&LOCK_open); if (need_start_waiting) start_waiting_global_read_lock(thd); diff --git a/sql/sql_update.cc b/sql/sql_update.cc index 4ab46107f2c..da8b2d046bb 100644 --- a/sql/sql_update.cc +++ b/sql/sql_update.cc @@ -782,7 +782,7 @@ int mysql_update(THD *thd, end_read_record(&info); delete select; thd_proc_info(thd, "end"); - VOID(table->file->extra(HA_EXTRA_NO_IGNORE_DUP_KEY)); + (void) table->file->extra(HA_EXTRA_NO_IGNORE_DUP_KEY); /* Invalidate the table in the query cache if something changed. @@ -1857,7 +1857,7 @@ void multi_update::abort() todo/fixme: do_update() is never called with the arg 1. should it change the signature to become argless? */ - VOID(do_updates()); + (void) do_updates(); } } if (thd->transaction.stmt.modified_non_trans_table) diff --git a/sql/sql_view.cc b/sql/sql_view.cc index 9abbadb8c6b..83341a53c3e 100644 --- a/sql/sql_view.cc +++ b/sql/sql_view.cc @@ -620,7 +620,7 @@ bool mysql_create_view(THD *thd, TABLE_LIST *views, res= TRUE; goto err; } - VOID(pthread_mutex_lock(&LOCK_open)); + pthread_mutex_lock(&LOCK_open); res= mysql_register_view(thd, view, mode); if (mysql_bin_log.is_open()) @@ -666,7 +666,7 @@ bool mysql_create_view(THD *thd, TABLE_LIST *views, buff.ptr(), buff.length(), FALSE, FALSE, errcode); } - VOID(pthread_mutex_unlock(&LOCK_open)); + pthread_mutex_unlock(&LOCK_open); if (mode != VIEW_CREATE_NEW) query_cache_invalidate3(thd, view, 0); start_waiting_global_read_lock(thd); @@ -1579,7 +1579,7 @@ bool mysql_drop_view(THD *thd, TABLE_LIST *views, enum_drop_mode drop_mode) bool something_wrong= FALSE; DBUG_ENTER("mysql_drop_view"); - VOID(pthread_mutex_lock(&LOCK_open)); + pthread_mutex_lock(&LOCK_open); for (view= views; view; view= view->next_local) { TABLE_SHARE *share; @@ -1656,7 +1656,7 @@ bool mysql_drop_view(THD *thd, TABLE_LIST *views, enum_drop_mode drop_mode) write_bin_log(thd, !something_wrong, thd->query(), thd->query_length()); } - VOID(pthread_mutex_unlock(&LOCK_open)); + pthread_mutex_unlock(&LOCK_open); if (something_wrong) { diff --git a/sql/table.cc b/sql/table.cc index 22b4b2f9b5e..7ea04ed3e15 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -753,7 +753,7 @@ static int open_binary_frm(THD *thd, TABLE_SHARE *share, uchar *head, /* Read keyinformation */ key_info_length= (uint) uint2korr(head+28); - VOID(my_seek(file,(ulong) uint2korr(head+6),MY_SEEK_SET,MYF(0))); + my_seek(file,(ulong) uint2korr(head+6),MY_SEEK_SET,MYF(0)); if (read_string(file,(uchar**) &disk_buff,key_info_length)) goto err; /* purecov: inspected */ if (disk_buff[0] & 0x80) @@ -1030,7 +1030,7 @@ static int open_binary_frm(THD *thd, TABLE_SHARE *share, uchar *head, record_offset, MYF(MY_NABP))) goto err; /* purecov: inspected */ - VOID(my_seek(file,pos,MY_SEEK_SET,MYF(0))); + my_seek(file,pos,MY_SEEK_SET,MYF(0)); if (my_read(file, head,288,MYF(MY_NABP))) goto err; #ifdef HAVE_CRYPTED_FRM @@ -2059,7 +2059,7 @@ ulong get_form_pos(File file, uchar *head, TYPELIB *save_names) if (names) { length=uint2korr(head+4); - VOID(my_seek(file,64L,MY_SEEK_SET,MYF(0))); + my_seek(file,64L,MY_SEEK_SET,MYF(0)); if (!(buf= (uchar*) my_malloc((size_t) length+a_length+names*4, MYF(MY_WME))) || my_read(file, buf+a_length, (size_t) (length+names*4), @@ -2138,17 +2138,17 @@ ulong make_new_entry(File file, uchar *fileinfo, TYPELIB *formnames, while (endpos > maxlength) { - VOID(my_seek(file,(ulong) (endpos-bufflength),MY_SEEK_SET,MYF(0))); + my_seek(file,(ulong) (endpos-bufflength),MY_SEEK_SET,MYF(0)); if (my_read(file, buff, bufflength, MYF(MY_NABP+MY_WME))) DBUG_RETURN(0L); - VOID(my_seek(file,(ulong) (endpos-bufflength+IO_SIZE),MY_SEEK_SET, - MYF(0))); + my_seek(file,(ulong) (endpos-bufflength+IO_SIZE),MY_SEEK_SET, + MYF(0)); if ((my_write(file, buff,bufflength,MYF(MY_NABP+MY_WME)))) DBUG_RETURN(0); endpos-=bufflength; bufflength=IO_SIZE; } bzero(buff,IO_SIZE); /* Null new block */ - VOID(my_seek(file,(ulong) maxlength,MY_SEEK_SET,MYF(0))); + my_seek(file,(ulong) maxlength,MY_SEEK_SET,MYF(0)); if (my_write(file,buff,bufflength,MYF(MY_NABP+MY_WME))) DBUG_RETURN(0L); maxlength+=IO_SIZE; /* Fix old ref */ @@ -2164,11 +2164,11 @@ ulong make_new_entry(File file, uchar *fileinfo, TYPELIB *formnames, if (n_length == 1 ) { /* First name */ length++; - VOID(strxmov((char*) buff,"/",newname,"/",NullS)); + (void) strxmov((char*) buff,"/",newname,"/",NullS); } else - VOID(strxmov((char*) buff,newname,"/",NullS)); /* purecov: inspected */ - VOID(my_seek(file,63L+(ulong) n_length,MY_SEEK_SET,MYF(0))); + (void) strxmov((char*) buff,newname,"/",NullS); /* purecov: inspected */ + my_seek(file,63L+(ulong) n_length,MY_SEEK_SET,MYF(0)); if (my_write(file, buff, (size_t) length+1,MYF(MY_NABP+MY_WME)) || (names && my_write(file,(uchar*) (*formnames->type_names+n_length-1), names*4, MYF(MY_NABP+MY_WME))) || @@ -2177,7 +2177,7 @@ ulong make_new_entry(File file, uchar *fileinfo, TYPELIB *formnames, int2store(fileinfo+8,names+1); int2store(fileinfo+4,n_length+length); - VOID(my_chsize(file, newpos, 0, MYF(MY_WME)));/* Append file with '\0' */ + (void) my_chsize(file, newpos, 0, MYF(MY_WME));/* Append file with '\0' */ DBUG_RETURN(newpos); } /* make_new_entry */ @@ -2531,8 +2531,8 @@ File create_frm(THD *thd, const char *name, const char *db, { if (my_write(file,fill, IO_SIZE, MYF(MY_WME | MY_NABP))) { - VOID(my_close(file,MYF(0))); - VOID(my_delete(name,MYF(0))); + (void) my_close(file,MYF(0)); + (void) my_delete(name,MYF(0)); return(-1); } } @@ -2569,8 +2569,8 @@ int rename_file_ext(const char * from,const char * to,const char * ext) { char from_b[FN_REFLEN],to_b[FN_REFLEN]; - VOID(strxmov(from_b,from,ext,NullS)); - VOID(strxmov(to_b,to,ext,NullS)); + (void) strxmov(from_b,from,ext,NullS); + (void) strxmov(to_b,to,ext,NullS); return (my_rename(from_b,to_b,MYF(MY_WME))); } diff --git a/sql/tztime.cc b/sql/tztime.cc index 93ff614b10b..9c49c286662 100644 --- a/sql/tztime.cc +++ b/sql/tztime.cc @@ -1595,7 +1595,7 @@ my_tz_init(THD *org_thd, const char *default_tzname, my_bool bootstrap) goto end; } init_sql_alloc(&tz_storage, 32 * 1024, 0); - VOID(pthread_mutex_init(&tz_LOCK, MY_MUTEX_INIT_FAST)); + pthread_mutex_init(&tz_LOCK, MY_MUTEX_INIT_FAST); tz_inited= 1; /* Add 'SYSTEM' time zone to tz_names hash */ @@ -1773,7 +1773,7 @@ void my_tz_free() if (tz_inited) { tz_inited= 0; - VOID(pthread_mutex_destroy(&tz_LOCK)); + pthread_mutex_destroy(&tz_LOCK); my_hash_free(&offset_tzs); my_hash_free(&tz_names); free_root(&tz_storage, MYF(0)); @@ -2262,7 +2262,7 @@ my_tz_find(THD *thd, const String *name) if (!name) DBUG_RETURN(0); - VOID(pthread_mutex_lock(&tz_LOCK)); + pthread_mutex_lock(&tz_LOCK); if (!str_to_offset(name->ptr(), name->length(), &offset)) { @@ -2305,7 +2305,7 @@ my_tz_find(THD *thd, const String *name) } } - VOID(pthread_mutex_unlock(&tz_LOCK)); + pthread_mutex_unlock(&tz_LOCK); DBUG_RETURN(result_tz); } diff --git a/sql/udf_example.c b/sql/udf_example.c index 4e3dd82c467..73256bb5529 100644 --- a/sql/udf_example.c +++ b/sql/udf_example.c @@ -767,14 +767,14 @@ char *lookup(UDF_INIT *initid __attribute__((unused)), UDF_ARGS *args, return 0; } #else - VOID(pthread_mutex_lock(&LOCK_hostname)); + pthread_mutex_lock(&LOCK_hostname); if (!(hostent= gethostbyname((char*) name_buff))) { - VOID(pthread_mutex_unlock(&LOCK_hostname)); + pthread_mutex_unlock(&LOCK_hostname); *null_value= 1; return 0; } - VOID(pthread_mutex_unlock(&LOCK_hostname)); + pthread_mutex_unlock(&LOCK_hostname); #endif memcpy_fixed((char*) &in,(char*) *hostent->h_addr_list, sizeof(in.s_addr)); *res_length= (ulong) (strmov(result, inet_ntoa(in)) - result); @@ -871,14 +871,14 @@ char *reverse_lookup(UDF_INIT *initid __attribute__((unused)), UDF_ARGS *args, return 0; } #else - VOID(pthread_mutex_lock(&LOCK_hostname)); + pthread_mutex_lock(&LOCK_hostname); if (!(hp= gethostbyaddr((char*) &taddr, sizeof(taddr), AF_INET))) { - VOID(pthread_mutex_unlock(&LOCK_hostname)); + pthread_mutex_unlock(&LOCK_hostname); *null_value= 1; return 0; } - VOID(pthread_mutex_unlock(&LOCK_hostname)); + pthread_mutex_unlock(&LOCK_hostname); #endif *res_length=(ulong) (strmov(result,hp->h_name) - result); return result; diff --git a/sql/uniques.cc b/sql/uniques.cc index 7b6b628f924..f7c290ae61d 100644 --- a/sql/uniques.cc +++ b/sql/uniques.cc @@ -66,8 +66,8 @@ Unique::Unique(qsort_cmp2 comp_func, void * comp_func_fixed_arg, */ max_elements= (ulong) (max_in_memory_size / ALIGN_SIZE(sizeof(TREE_ELEMENT)+size)); - VOID(open_cached_file(&file, mysql_tmpdir,TEMP_PREFIX, DISK_BUFFER_SIZE, - MYF(MY_WME))); + (void) open_cached_file(&file, mysql_tmpdir,TEMP_PREFIX, DISK_BUFFER_SIZE, + MYF(MY_WME)); } diff --git a/sql/unireg.cc b/sql/unireg.cc index f08c64a3182..8328cf735b5 100644 --- a/sql/unireg.cc +++ b/sql/unireg.cc @@ -199,7 +199,7 @@ bool mysql_create_frm(THD *thd, const char *file_name, key_buff_length= uint4korr(fileinfo+47); keybuff=(uchar*) my_malloc(key_buff_length, MYF(0)); key_info_length= pack_keys(keybuff, keys, key_info, data_offset); - VOID(get_form_pos(file,fileinfo,&formnames)); + (void) get_form_pos(file,fileinfo,&formnames); if (!(filepos=make_new_entry(file,fileinfo,&formnames,""))) goto err; maxlength=(uint) next_io_size((ulong) (uint2korr(forminfo)+1000)); @@ -262,9 +262,9 @@ bool mysql_create_frm(THD *thd, const char *file_name, my_pwrite(file, keybuff, key_info_length, (ulong) uint2korr(fileinfo+6),MYF_RW)) goto err; - VOID(my_seek(file, + my_seek(file, (ulong) uint2korr(fileinfo+6)+ (ulong) key_buff_length, - MY_SEEK_SET,MYF(0))); + MY_SEEK_SET,MYF(0)); if (make_empty_rec(thd,file,ha_legacy_type(create_info->db_type), create_info->table_options, create_fields,reclength, data_offset, db_file)) @@ -310,7 +310,7 @@ bool mysql_create_frm(THD *thd, const char *file_name, } } - VOID(my_seek(file,filepos,MY_SEEK_SET,MYF(0))); + my_seek(file,filepos,MY_SEEK_SET,MYF(0)); if (my_write(file, forminfo, 288, MYF_RW) || my_write(file, screen_buff, info_length, MYF_RW) || pack_fields(file, create_fields, data_offset)) @@ -324,7 +324,7 @@ bool mysql_create_frm(THD *thd, const char *file_name, if (!crypted || my_pwrite(file,&tmp,1,26,MYF_RW)) // Mark crypted goto err; uint read_length=uint2korr(forminfo)-256; - VOID(my_seek(file,filepos+256,MY_SEEK_SET,MYF(0))); + my_seek(file,filepos+256,MY_SEEK_SET,MYF(0)); if (read_string(file,(uchar**) &disk_buff,read_length)) goto err; crypted->encode(disk_buff,read_length); @@ -371,7 +371,7 @@ err: my_free(screen_buff, MYF(0)); my_free(keybuff, MYF(0)); err2: - VOID(my_close(file,MYF(MY_WME))); + (void) my_close(file,MYF(MY_WME)); err3: my_delete(file_name,MYF(0)); DBUG_RETURN(1); @@ -425,7 +425,7 @@ int rea_create_table(THD *thd, const char *path, DBUG_RETURN(0); err_handler: - VOID(file->ha_create_handler_files(path, NULL, CHF_DELETE_FLAG, create_info)); + (void) file->ha_create_handler_files(path, NULL, CHF_DELETE_FLAG, create_info); my_delete(frm_name, MYF(0)); DBUG_RETURN(1); } /* rea_create_table */ diff --git a/storage/archive/ha_archive.cc b/storage/archive/ha_archive.cc index 1cb9b8bba80..a341843662f 100644 --- a/storage/archive/ha_archive.cc +++ b/storage/archive/ha_archive.cc @@ -175,7 +175,7 @@ int archive_db_init(void *p) if (my_hash_init(&archive_open_tables, table_alias_charset, 32, 0, 0, (my_hash_get_key) archive_get_key, 0, 0)) { - VOID(pthread_mutex_destroy(&archive_mutex)); + pthread_mutex_destroy(&archive_mutex); } else { @@ -199,7 +199,7 @@ error: int archive_db_done(void *p) { my_hash_free(&archive_open_tables); - VOID(pthread_mutex_destroy(&archive_mutex)); + pthread_mutex_destroy(&archive_mutex); return 0; } @@ -346,7 +346,7 @@ ARCHIVE_SHARE *ha_archive::get_share(const char *table_name, int *rc) /* We will use this lock for rows. */ - VOID(pthread_mutex_init(&share->mutex,MY_MUTEX_INIT_FAST)); + pthread_mutex_init(&share->mutex,MY_MUTEX_INIT_FAST); /* We read the meta file, but do not mark it dirty. Since we are not @@ -363,7 +363,7 @@ ARCHIVE_SHARE *ha_archive::get_share(const char *table_name, int *rc) share->crashed= archive_tmp.dirty; azclose(&archive_tmp); - VOID(my_hash_insert(&archive_open_tables, (uchar*) share)); + (void) my_hash_insert(&archive_open_tables, (uchar*) share); thr_lock_init(&share->lock); } share->use_count++; @@ -396,7 +396,7 @@ int ha_archive::free_share() { my_hash_delete(&archive_open_tables, (uchar*) share); thr_lock_delete(&share->lock); - VOID(pthread_mutex_destroy(&share->mutex)); + pthread_mutex_destroy(&share->mutex); /* We need to make sure we don't reset the crashed state. If we open a crashed file, wee need to close it as crashed unless @@ -1493,7 +1493,7 @@ int ha_archive::info(uint flag) { MY_STAT file_stat; // Stat information for the data file - VOID(my_stat(share->data_file_name, &file_stat, MYF(MY_WME))); + (void) my_stat(share->data_file_name, &file_stat, MYF(MY_WME)); stats.data_file_length= file_stat.st_size; stats.create_time= (ulong) file_stat.st_ctime; diff --git a/storage/blackhole/ha_blackhole.cc b/storage/blackhole/ha_blackhole.cc index 27e4c919911..6aa090263d5 100644 --- a/storage/blackhole/ha_blackhole.cc +++ b/storage/blackhole/ha_blackhole.cc @@ -377,7 +377,7 @@ static int blackhole_init(void *p) blackhole_hton->create= blackhole_create_handler; blackhole_hton->flags= HTON_CAN_RECREATE; - VOID(pthread_mutex_init(&blackhole_mutex, MY_MUTEX_INIT_FAST)); + pthread_mutex_init(&blackhole_mutex, MY_MUTEX_INIT_FAST); (void) my_hash_init(&blackhole_open_tables, system_charset_info,32,0,0, (my_hash_get_key) blackhole_get_key, (my_hash_free_key) blackhole_free_key, 0); diff --git a/storage/csv/ha_tina.cc b/storage/csv/ha_tina.cc index 9cc0f1e607b..5348b5b9331 100644 --- a/storage/csv/ha_tina.cc +++ b/storage/csv/ha_tina.cc @@ -110,7 +110,7 @@ static int tina_init_func(void *p) handlerton *tina_hton; tina_hton= (handlerton *)p; - VOID(pthread_mutex_init(&tina_mutex,MY_MUTEX_INIT_FAST)); + pthread_mutex_init(&tina_mutex,MY_MUTEX_INIT_FAST); (void) my_hash_init(&tina_open_tables,system_charset_info,32,0,0, (my_hash_get_key) tina_get_key,0,0); tina_hton->state= SHOW_OPTION_YES; @@ -236,7 +236,7 @@ static int read_meta_file(File meta_file, ha_rows *rows) DBUG_ENTER("ha_tina::read_meta_file"); - VOID(my_seek(meta_file, 0, MY_SEEK_SET, MYF(0))); + my_seek(meta_file, 0, MY_SEEK_SET, MYF(0)); if (my_read(meta_file, (uchar*)meta_buffer, META_BUFFER_SIZE, 0) != META_BUFFER_SIZE) DBUG_RETURN(HA_ERR_CRASHED_ON_USAGE); @@ -305,7 +305,7 @@ static int write_meta_file(File meta_file, ha_rows rows, bool dirty) ptr+= 3*sizeof(ulonglong); *ptr= (uchar)dirty; - VOID(my_seek(meta_file, 0, MY_SEEK_SET, MYF(0))); + my_seek(meta_file, 0, MY_SEEK_SET, MYF(0)); if (my_write(meta_file, (uchar *)meta_buffer, META_BUFFER_SIZE, 0) != META_BUFFER_SIZE) DBUG_RETURN(-1); diff --git a/storage/csv/transparent_file.cc b/storage/csv/transparent_file.cc index 841c3efc476..3d7afae85d4 100644 --- a/storage/csv/transparent_file.cc +++ b/storage/csv/transparent_file.cc @@ -35,7 +35,7 @@ void Transparent_file::init_buff(File filedes_arg) filedes= filedes_arg; /* read the beginning of the file */ lower_bound= 0; - VOID(my_seek(filedes, 0, MY_SEEK_SET, MYF(0))); + my_seek(filedes, 0, MY_SEEK_SET, MYF(0)); if (filedes && buff) upper_bound= my_read(filedes, buff, buff_size, MYF(0)); } @@ -85,7 +85,7 @@ char Transparent_file::get_value(my_off_t offset) if ((lower_bound <= offset) && (((my_off_t) offset) < upper_bound)) return buff[offset - lower_bound]; - VOID(my_seek(filedes, offset, MY_SEEK_SET, MYF(0))); + my_seek(filedes, offset, MY_SEEK_SET, MYF(0)); /* read appropriate portion of the file */ if ((bytes_read= my_read(filedes, buff, buff_size, MYF(0))) == MY_FILE_ERROR) diff --git a/storage/example/ha_example.cc b/storage/example/ha_example.cc index 9bc666663c3..743c7423b80 100644 --- a/storage/example/ha_example.cc +++ b/storage/example/ha_example.cc @@ -132,7 +132,7 @@ static int example_init_func(void *p) DBUG_ENTER("example_init_func"); example_hton= (handlerton *)p; - VOID(pthread_mutex_init(&example_mutex,MY_MUTEX_INIT_FAST)); + pthread_mutex_init(&example_mutex,MY_MUTEX_INIT_FAST); (void) my_hash_init(&example_open_tables,system_charset_info,32,0,0, (my_hash_get_key) example_get_key,0,0); diff --git a/storage/federated/ha_federated.cc b/storage/federated/ha_federated.cc index 05be8b27a8b..c582adc43e6 100644 --- a/storage/federated/ha_federated.cc +++ b/storage/federated/ha_federated.cc @@ -465,7 +465,7 @@ int federated_db_init(void *p) DBUG_RETURN(FALSE); } - VOID(pthread_mutex_destroy(&federated_mutex)); + pthread_mutex_destroy(&federated_mutex); error: DBUG_RETURN(TRUE); } @@ -484,7 +484,7 @@ error: int federated_done(void *p) { my_hash_free(&federated_open_tables); - VOID(pthread_mutex_destroy(&federated_mutex)); + pthread_mutex_destroy(&federated_mutex); return 0; } @@ -1562,7 +1562,7 @@ static int free_share(FEDERATED_SHARE *share) { my_hash_delete(&federated_open_tables, (uchar*) share); thr_lock_delete(&share->lock); - VOID(pthread_mutex_destroy(&share->mutex)); + pthread_mutex_destroy(&share->mutex); free_root(&mem_root, MYF(0)); } pthread_mutex_unlock(&federated_mutex); diff --git a/storage/heap/hp_clear.c b/storage/heap/hp_clear.c index babfcbd6f41..9c04684e269 100644 --- a/storage/heap/hp_clear.c +++ b/storage/heap/hp_clear.c @@ -31,8 +31,8 @@ void hp_clear(HP_SHARE *info) DBUG_ENTER("hp_clear"); if (info->block.levels) - VOID(hp_free_level(&info->block,info->block.levels,info->block.root, - (uchar*) 0)); + (void) hp_free_level(&info->block,info->block.levels,info->block.root, + (uchar*) 0); info->block.levels=0; hp_clear_keys(info); info->records= info->deleted= 0; @@ -94,7 +94,7 @@ void hp_clear_keys(HP_SHARE *info) { HP_BLOCK *block= &keyinfo->block; if (block->levels) - VOID(hp_free_level(block,block->levels,block->root,(uchar*) 0)); + (void) hp_free_level(block,block->levels,block->root,(uchar*) 0); block->levels=0; block->last_allocated=0; keyinfo->hash_buckets= 0; diff --git a/storage/heap/hp_create.c b/storage/heap/hp_create.c index b6814fc1614..1440cbc0e98 100644 --- a/storage/heap/hp_create.c +++ b/storage/heap/hp_create.c @@ -194,7 +194,7 @@ int heap_create(const char *name, uint keys, HP_KEYDEF *keydef, } #ifdef THREAD thr_lock_init(&share->lock); - VOID(pthread_mutex_init(&share->intern_lock,MY_MUTEX_INIT_FAST)); + pthread_mutex_init(&share->intern_lock,MY_MUTEX_INIT_FAST); #endif if (!create_info->internal_table) { @@ -298,7 +298,7 @@ void hp_free(HP_SHARE *share) hp_clear(share); /* Remove blocks from memory */ #ifdef THREAD thr_lock_delete(&share->lock); - VOID(pthread_mutex_destroy(&share->intern_lock)); + pthread_mutex_destroy(&share->intern_lock); #endif my_free((uchar*) share->name, MYF(0)); my_free((uchar*) share, MYF(0)); diff --git a/storage/heap/hp_test1.c b/storage/heap/hp_test1.c index b1b55098a78..911e3a285a2 100644 --- a/storage/heap/hp_test1.c +++ b/storage/heap/hp_test1.c @@ -91,7 +91,7 @@ int main(int argc, char **argv) printf("- Removing records\n"); for (i=1 ; i<=10 ; i++) { - if (i == remove_ant) { VOID(heap_close(file)) ; return (0) ; } + if (i == remove_ant) { (void) heap_close(file); return (0) ; } sprintf((char*) key,"%6d",(j=(int) ((rand() & 32767)/32767.*25))); if ((error = heap_rkey(file,record,0,key,6,HA_READ_KEY_EXACT))) { diff --git a/storage/heap/hp_test2.c b/storage/heap/hp_test2.c index 5c548b6be74..8216c7360b4 100644 --- a/storage/heap/hp_test2.c +++ b/storage/heap/hp_test2.c @@ -609,7 +609,7 @@ end: return(0); err: printf("Got error: %d when using heap-database\n",my_errno); - VOID(heap_close(file)); + (void) heap_close(file); return(1); } /* main */ diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc index da41f3c7bbc..a36fc3b981e 100644 --- a/storage/innobase/handler/ha_innodb.cc +++ b/storage/innobase/handler/ha_innodb.cc @@ -902,7 +902,7 @@ innobase_mysql_prepare_print_arbitrary_thd(void) /*============================================*/ { ut_ad(!mutex_own(&kernel_mutex)); - VOID(pthread_mutex_lock(&LOCK_thread_count)); + pthread_mutex_lock(&LOCK_thread_count); } /*************************************************************//** @@ -916,7 +916,7 @@ innobase_mysql_end_print_arbitrary_thd(void) /*========================================*/ { ut_ad(!mutex_own(&kernel_mutex)); - VOID(pthread_mutex_unlock(&LOCK_thread_count)); + pthread_mutex_unlock(&LOCK_thread_count); } /*************************************************************//** diff --git a/storage/myisam/ft_eval.c b/storage/myisam/ft_eval.c index de01510fdd7..f4faabe7919 100644 --- a/storage/myisam/ft_eval.c +++ b/storage/myisam/ft_eval.c @@ -236,8 +236,8 @@ static void print_error(int exit_code, const char *fmt,...) va_start(args,fmt); fprintf(stderr,"%s: error: ",my_progname); - VOID(vfprintf(stderr, fmt, args)); - VOID(fputc('\n',stderr)); + (void) vfprintf(stderr, fmt, args); + (void) fputc('\n',stderr); fflush(stderr); va_end(args); exit(exit_code); diff --git a/storage/myisam/ha_myisam.cc b/storage/myisam/ha_myisam.cc index 612d02bbcd3..cb8333767f8 100644 --- a/storage/myisam/ha_myisam.cc +++ b/storage/myisam/ha_myisam.cc @@ -721,11 +721,11 @@ int ha_myisam::open(const char *name, int mode, uint test_if_locked) } if (test_if_locked & (HA_OPEN_IGNORE_IF_LOCKED | HA_OPEN_TMP_TABLE)) - VOID(mi_extra(file, HA_EXTRA_NO_WAIT_LOCK, 0)); + (void) mi_extra(file, HA_EXTRA_NO_WAIT_LOCK, 0); info(HA_STATUS_NO_LOCK | HA_STATUS_VARIABLE | HA_STATUS_CONST); if (!(test_if_locked & HA_OPEN_WAIT_IF_LOCKED)) - VOID(mi_extra(file, HA_EXTRA_WAIT_LOCK, 0)); + (void) mi_extra(file, HA_EXTRA_WAIT_LOCK, 0); if (!table->s->db_record_offset) int_table_flags|=HA_REC_NOT_IN_SEQ; if (file->s->options & (HA_OPTION_CHECKSUM | HA_OPTION_COMPRESS_RECORD)) @@ -916,8 +916,8 @@ int ha_myisam::restore(THD* thd, HA_CHECK_OPT *check_opt) const char* errmsg; DBUG_ENTER("restore"); - VOID(tablename_to_filename(table->s->table_name.str, table_name, - sizeof(table_name))); + (void) tablename_to_filename(table->s->table_name.str, table_name, + sizeof(table_name)); if (fn_format_relative_to_data_home(src_path, table_name, backup_dir, MI_NAME_DEXT)) @@ -959,8 +959,8 @@ int ha_myisam::backup(THD* thd, HA_CHECK_OPT *check_opt) const char *errmsg; DBUG_ENTER("ha_myisam::backup"); - VOID(tablename_to_filename(table->s->table_name.str, table_name, - sizeof(table_name))); + (void) tablename_to_filename(table->s->table_name.str, table_name, + sizeof(table_name)); if (fn_format_relative_to_data_home(dst_path, table_name, backup_dir, reg_ext)) diff --git a/storage/myisam/mi_changed.c b/storage/myisam/mi_changed.c index 7422f995dd0..049974e4a65 100644 --- a/storage/myisam/mi_changed.c +++ b/storage/myisam/mi_changed.c @@ -25,7 +25,7 @@ int mi_is_changed(MI_INFO *info) DBUG_ENTER("mi_is_changed"); if (fast_mi_readinfo(info)) DBUG_RETURN(-1); - VOID(_mi_writeinfo(info,0)); + (void) _mi_writeinfo(info,0); result=(int) info->data_changed; info->data_changed=0; DBUG_PRINT("exit",("result: %d",result)); diff --git a/storage/myisam/mi_check.c b/storage/myisam/mi_check.c index c10cfdd0c9b..8ff803b58a0 100644 --- a/storage/myisam/mi_check.c +++ b/storage/myisam/mi_check.c @@ -1184,8 +1184,8 @@ int chk_data_link(MI_CHECK *param, MI_INFO *info,int extend) goto err; start_recpos=pos; splits++; - VOID(_mi_pack_get_block_info(info, &info->bit_buff, &block_info, - &info->rec_buff, -1, start_recpos)); + (void) _mi_pack_get_block_info(info, &info->bit_buff, &block_info, + &info->rec_buff, -1, start_recpos); pos=block_info.filepos+block_info.rec_len; if (block_info.rec_len < (uint) info->s->min_pack_length || block_info.rec_len > (uint) info->s->max_pack_length) @@ -1222,7 +1222,7 @@ int chk_data_link(MI_CHECK *param, MI_INFO *info,int extend) records++; if (param->testflag & T_WRITE_LOOP && records % WRITE_COUNT == 0) { - printf("%s\r", llstr(records,llbuff)); VOID(fflush(stdout)); + printf("%s\r", llstr(records,llbuff)); (void) fflush(stdout); } /* Check if keys match the record */ @@ -1275,7 +1275,7 @@ int chk_data_link(MI_CHECK *param, MI_INFO *info,int extend) } if (param->testflag & T_WRITE_LOOP) { - VOID(fputs(" \r",stdout)); VOID(fflush(stdout)); + (void) fputs(" \r",stdout); (void) fflush(stdout); } if (records != info->state->records) { @@ -1551,8 +1551,8 @@ int mi_repair(MI_CHECK *param, register MI_INFO *info, DBUG_ASSERT(param->use_buffers < SIZE_T_MAX); if (!param->using_global_keycache) - VOID(init_key_cache(dflt_key_cache, param->key_cache_block_size, - (size_t) param->use_buffers, 0, 0)); + (void) init_key_cache(dflt_key_cache, param->key_cache_block_size, + param->use_buffers, 0, 0); if (init_io_cache(¶m->read_cache,info->dfile, (uint) param->read_buffer_length, @@ -1645,8 +1645,8 @@ int mi_repair(MI_CHECK *param, register MI_INFO *info, llstr(info->dupp_key_pos,llbuff2)); if (param->testflag & T_VERBOSE) { - VOID(_mi_make_key(info,(uint) info->errkey,info->lastkey, - sort_param.record,0L)); + (void) _mi_make_key(info,(uint) info->errkey,info->lastkey, + sort_param.record,0L); _mi_print_key(stdout,share->keyinfo[info->errkey].seg,info->lastkey, USE_WHOLE_KEY); } @@ -1668,7 +1668,7 @@ int mi_repair(MI_CHECK *param, register MI_INFO *info, if (param->testflag & T_WRITE_LOOP) { - VOID(fputs(" \r",stdout)); VOID(fflush(stdout)); + (void) fputs(" \r",stdout); (void) fflush(stdout); } if (my_chsize(share->kfile,info->state->key_file_length,0,MYF(0))) { @@ -1750,9 +1750,9 @@ err: llstr(sort_param.start_recpos,llbuff)); if (new_file >= 0) { - VOID(my_close(new_file,MYF(0))); - VOID(my_raid_delete(param->temp_filename,info->s->base.raid_chunks, - MYF(MY_WME))); + (void) my_close(new_file,MYF(0)); + (void) my_raid_delete(param->temp_filename,info->s->base.raid_chunks, + MYF(MY_WME)); info->rec_cache.file=-1; /* don't flush data to new_file, it's closed */ } mi_mark_crashed_on_repair(info); @@ -1762,9 +1762,9 @@ err: my_free(mi_get_rec_buff_ptr(info, sort_param.record), MYF(MY_ALLOW_ZERO_PTR)); my_free(sort_info.buff,MYF(MY_ALLOW_ZERO_PTR)); - VOID(end_io_cache(¶m->read_cache)); + (void) end_io_cache(¶m->read_cache); info->opt_flag&= ~(READ_CACHE_USED | WRITE_CACHE_USED); - VOID(end_io_cache(&info->rec_cache)); + (void) end_io_cache(&info->rec_cache); got_error|=flush_blocks(param, share->key_cache, share->kfile); if (!got_error && param->testflag & T_UNPACK) { @@ -1991,9 +1991,9 @@ int mi_sort_index(MI_CHECK *param, register MI_INFO *info, char * name) /* Put same locks as old file */ share->r_locks= share->w_locks= share->tot_locks= 0; (void) _mi_writeinfo(info,WRITEINFO_UPDATE_KEYFILE); - VOID(my_close(share->kfile,MYF(MY_WME))); + (void) my_close(share->kfile,MYF(MY_WME)); share->kfile = -1; - VOID(my_close(new_file,MYF(MY_WME))); + (void) my_close(new_file,MYF(MY_WME)); if (change_to_newfile(share->index_file_name,MI_NAME_IEXT,INDEX_TMP_EXT,0, MYF(0)) || mi_open_keyfile(share)) @@ -2017,9 +2017,9 @@ int mi_sort_index(MI_CHECK *param, register MI_INFO *info, char * name) DBUG_RETURN(0); err: - VOID(my_close(new_file,MYF(MY_WME))); + (void) my_close(new_file,MYF(MY_WME)); err2: - VOID(my_delete(param->temp_filename,MYF(MY_WME))); + (void) my_delete(param->temp_filename,MYF(MY_WME)); DBUG_RETURN(-1); } /* mi_sort_index */ @@ -2176,7 +2176,7 @@ int filecopy(MI_CHECK *param, File to,File from,my_off_t start, buff=tmp_buff; buff_length=IO_SIZE; } - VOID(my_seek(from,start,MY_SEEK_SET,MYF(0))); + my_seek(from,start,MY_SEEK_SET,MYF(0)); while (length > buff_length) { if (my_read(from,(uchar*) buff,buff_length,MYF(MY_NABP)) || @@ -2486,7 +2486,7 @@ int mi_repair_by_sort(MI_CHECK *param, register MI_INFO *info, if (param->testflag & T_WRITE_LOOP) { - VOID(fputs(" \r",stdout)); VOID(fflush(stdout)); + (void) fputs(" \r",stdout); (void) fflush(stdout); } if (rep_quick && del+sort_info.dupp != info->state->del) @@ -2539,7 +2539,7 @@ int mi_repair_by_sort(MI_CHECK *param, register MI_INFO *info, err: got_error|= flush_blocks(param, share->key_cache, share->kfile); - VOID(end_io_cache(&info->rec_cache)); + (void) end_io_cache(&info->rec_cache); if (!got_error) { /* Replace the actual file with the temporary file */ @@ -2561,9 +2561,9 @@ err: mi_check_print_error(param,"%d when fixing table",my_errno); if (new_file >= 0) { - VOID(my_close(new_file,MYF(0))); - VOID(my_raid_delete(param->temp_filename,share->base.raid_chunks, - MYF(MY_WME))); + (void) my_close(new_file,MYF(0)); + (void) my_raid_delete(param->temp_filename,share->base.raid_chunks, + MYF(MY_WME)); if (info->dfile == new_file) /* Retry with key cache */ if (unlikely(mi_open_datafile(info, share, name, -1))) param->retry_repair= 0; /* Safety */ @@ -2581,7 +2581,7 @@ err: my_free((uchar*) sort_info.key_block,MYF(MY_ALLOW_ZERO_PTR)); my_free((uchar*) sort_info.ft_buf, MYF(MY_ALLOW_ZERO_PTR)); my_free(sort_info.buff,MYF(MY_ALLOW_ZERO_PTR)); - VOID(end_io_cache(¶m->read_cache)); + (void) end_io_cache(¶m->read_cache); info->opt_flag&= ~(READ_CACHE_USED | WRITE_CACHE_USED); if (!got_error && (param->testflag & T_UNPACK)) { @@ -3068,7 +3068,7 @@ err: the share by remove_io_thread() or it was not yet started (if the error happend before creating the thread). */ - VOID(end_io_cache(&info->rec_cache)); + (void) end_io_cache(&info->rec_cache); /* Destroy the new data cache in case of non-quick repair. All slave threads did either detach from the share by remove_io_thread() @@ -3076,7 +3076,7 @@ err: creating the threads). */ if (!rep_quick) - VOID(end_io_cache(&new_data_cache)); + (void) end_io_cache(&new_data_cache); if (!got_error) { /* Replace the actual file with the temporary file */ @@ -3098,9 +3098,9 @@ err: mi_check_print_error(param,"%d when fixing table",my_errno); if (new_file >= 0) { - VOID(my_close(new_file,MYF(0))); - VOID(my_raid_delete(param->temp_filename,share->base.raid_chunks, - MYF(MY_WME))); + (void) my_close(new_file,MYF(0)); + (void) my_raid_delete(param->temp_filename,share->base.raid_chunks, + MYF(MY_WME)); if (info->dfile == new_file) /* Retry with key cache */ if (unlikely(mi_open_datafile(info, share, name, -1))) param->retry_repair= 0; /* Safety */ @@ -3120,7 +3120,7 @@ err: my_free((uchar*) sort_info.key_block,MYF(MY_ALLOW_ZERO_PTR)); my_free((uchar*) sort_param,MYF(MY_ALLOW_ZERO_PTR)); my_free(sort_info.buff,MYF(MY_ALLOW_ZERO_PTR)); - VOID(end_io_cache(¶m->read_cache)); + (void) end_io_cache(¶m->read_cache); info->opt_flag&= ~(READ_CACHE_USED | WRITE_CACHE_USED); if (!got_error && (param->testflag & T_UNPACK)) { @@ -3774,7 +3774,7 @@ int sort_write_record(MI_SORT_PARAM *sort_param) { char llbuff[22]; printf("%s\r", llstr(info->state->records,llbuff)); - VOID(fflush(stdout)); + (void) fflush(stdout); } } DBUG_RETURN(0); @@ -4048,7 +4048,7 @@ static int sort_insert_key(MI_SORT_PARAM *sort_param, key_block->end_pos+=t_length; if (a_length <= keyinfo->block_length) { - VOID(_mi_move_key(keyinfo,key_block->lastkey,key)); + (void) _mi_move_key(keyinfo,key_block->lastkey,key); key_block->last_length=a_length-t_length; DBUG_RETURN(0); } @@ -4327,7 +4327,7 @@ int recreate_table(MI_CHECK *param, MI_INFO **org_info, char *filename) set_if_bigger(file_length,tmp_length); set_if_bigger(file_length,(ulonglong) share.base.max_data_file_length); - VOID(mi_close(*org_info)); + (void) mi_close(*org_info); bzero((char*) &create_info,sizeof(create_info)); create_info.max_rows=max(max_records,share.base.records); create_info.reloc_rows=share.base.reloc; @@ -4368,7 +4368,7 @@ int recreate_table(MI_CHECK *param, MI_INFO **org_info, char *filename) } /* We are modifing */ (*org_info)->s->options&= ~HA_OPTION_READ_ONLY_DATA; - VOID(_mi_readinfo(*org_info,F_WRLCK,0)); + (void) _mi_readinfo(*org_info,F_WRLCK,0); (*org_info)->state->records=info.state->records; if (share.state.create_time) (*org_info)->s->state.create_time=share.state.create_time; diff --git a/storage/myisam/mi_close.c b/storage/myisam/mi_close.c index 2066d092e1f..f94c8f3558d 100644 --- a/storage/myisam/mi_close.c +++ b/storage/myisam/mi_close.c @@ -93,13 +93,13 @@ int mi_close(register MI_INFO *info) } #ifdef THREAD thr_lock_delete(&share->lock); - VOID(pthread_mutex_destroy(&share->intern_lock)); + pthread_mutex_destroy(&share->intern_lock); { int i,keys; keys = share->state.header.keys; - VOID(rwlock_destroy(&share->mmap_lock)); + (void) rwlock_destroy(&share->mmap_lock); for(i=0; ikey_root_lock[i])); + (void) rwlock_destroy(&share->key_root_lock[i]); } } #endif diff --git a/storage/myisam/mi_create.c b/storage/myisam/mi_create.c index 0b4d781379c..7733fd5db17 100644 --- a/storage/myisam/mi_create.c +++ b/storage/myisam/mi_create.c @@ -838,7 +838,7 @@ err: save_errno=my_errno; switch (errpos) { case 3: - VOID(my_close(dfile,MYF(0))); + (void) my_close(dfile,MYF(0)); /* fall through */ case 2: /* QQ: Tõnu should add a call to my_raid_delete() here */ @@ -848,7 +848,7 @@ err: MYF(0)); /* fall through */ case 1: - VOID(my_close(file,MYF(0))); + (void) my_close(file,MYF(0)); if (! (flags & HA_DONT_TOUCH_DATA)) my_delete_with_symlink(fn_format(filename,name,"",MI_NAME_IEXT, MY_UNPACK_FILENAME | MY_APPEND_EXT), diff --git a/storage/myisam/mi_dbug.c b/storage/myisam/mi_dbug.c index 07c314c43e6..45882eda6af 100644 --- a/storage/myisam/mi_dbug.c +++ b/storage/myisam/mi_dbug.c @@ -30,12 +30,12 @@ void _mi_print_key(FILE *stream, register HA_KEYSEG *keyseg, const uchar *end; const uchar *key_end=key+length; - VOID(fputs("Key: \"",stream)); + (void) fputs("Key: \"",stream); flag=0; for (; keyseg->type && key < key_end ;keyseg++) { if (flag++) - VOID(putc('-',stream)); + (void) putc('-',stream); end= key+ keyseg->length; if (keyseg->flag & HA_NULL_PART) { @@ -51,7 +51,7 @@ void _mi_print_key(FILE *stream, register HA_KEYSEG *keyseg, case HA_KEYTYPE_BINARY: if (!(keyseg->flag & HA_SPACE_PACK) && keyseg->length == 1) { /* packed binary digit */ - VOID(fprintf(stream,"%d",(uint) *key++)); + (void) fprintf(stream,"%d",(uint) *key++); break; } /* fall through */ @@ -59,58 +59,58 @@ void _mi_print_key(FILE *stream, register HA_KEYSEG *keyseg, case HA_KEYTYPE_NUM: if (keyseg->flag & HA_SPACE_PACK) { - VOID(fprintf(stream,"%.*s",(int) *key,key+1)); + (void) fprintf(stream,"%.*s",(int) *key,key+1); key+= (int) *key+1; } else { - VOID(fprintf(stream,"%.*s",(int) keyseg->length,key)); + (void) fprintf(stream,"%.*s",(int) keyseg->length,key); key=end; } break; case HA_KEYTYPE_INT8: - VOID(fprintf(stream,"%d",(int) *((signed char*) key))); + (void) fprintf(stream,"%d",(int) *((signed char*) key)); key=end; break; case HA_KEYTYPE_SHORT_INT: s_1= mi_sint2korr(key); - VOID(fprintf(stream,"%d",(int) s_1)); + (void) fprintf(stream,"%d",(int) s_1); key=end; break; case HA_KEYTYPE_USHORT_INT: { ushort u_1; u_1= mi_uint2korr(key); - VOID(fprintf(stream,"%u",(uint) u_1)); + (void) fprintf(stream,"%u",(uint) u_1); key=end; break; } case HA_KEYTYPE_LONG_INT: l_1=mi_sint4korr(key); - VOID(fprintf(stream,"%ld",l_1)); + (void) fprintf(stream,"%ld",l_1); key=end; break; case HA_KEYTYPE_ULONG_INT: l_1=mi_sint4korr(key); - VOID(fprintf(stream,"%lu",(ulong) l_1)); + (void) fprintf(stream,"%lu",(ulong) l_1); key=end; break; case HA_KEYTYPE_INT24: - VOID(fprintf(stream,"%ld",(long) mi_sint3korr(key))); + (void) fprintf(stream,"%ld",(long) mi_sint3korr(key)); key=end; break; case HA_KEYTYPE_UINT24: - VOID(fprintf(stream,"%lu",(ulong) mi_uint3korr(key))); + (void) fprintf(stream,"%lu",(ulong) mi_uint3korr(key)); key=end; break; case HA_KEYTYPE_FLOAT: mi_float4get(f_1,key); - VOID(fprintf(stream,"%g",(double) f_1)); + (void) fprintf(stream,"%g",(double) f_1); key=end; break; case HA_KEYTYPE_DOUBLE: mi_float8get(d_1,key); - VOID(fprintf(stream,"%g",d_1)); + (void) fprintf(stream,"%g",d_1); key=end; break; #ifdef HAVE_LONG_LONG @@ -118,7 +118,7 @@ void _mi_print_key(FILE *stream, register HA_KEYSEG *keyseg, { char buff[21]; longlong2str(mi_sint8korr(key),buff,-10); - VOID(fprintf(stream,"%s",buff)); + (void) fprintf(stream,"%s",buff); key=end; break; } @@ -126,7 +126,7 @@ void _mi_print_key(FILE *stream, register HA_KEYSEG *keyseg, { char buff[21]; longlong2str(mi_sint8korr(key),buff,10); - VOID(fprintf(stream,"%s",buff)); + (void) fprintf(stream,"%s",buff); key=end; break; } @@ -152,14 +152,14 @@ void _mi_print_key(FILE *stream, register HA_KEYSEG *keyseg, The following command sometimes gives a warning from valgrind. Not yet sure if the bug is in valgrind, glibc or mysqld */ - VOID(fprintf(stream,"%.*s",(int) tmp_length,key)); + (void) fprintf(stream,"%.*s",(int) tmp_length,key); key+=tmp_length; break; } default: break; /* This never happens */ } } - VOID(fputs("\"\n",stream)); + (void) fputs("\"\n",stream); return; } /* print_key */ diff --git a/storage/myisam/mi_delete.c b/storage/myisam/mi_delete.c index 904ce4b2247..9314148cd8c 100644 --- a/storage/myisam/mi_delete.c +++ b/storage/myisam/mi_delete.c @@ -101,7 +101,7 @@ int mi_delete(MI_INFO *info,const uchar *record) mi_sizestore(lastpos,info->lastpos); myisam_log_command(MI_LOG_DELETE,info,(uchar*) lastpos,sizeof(lastpos),0); - VOID(_mi_writeinfo(info,WRITEINFO_UPDATE_KEYFILE)); + (void) _mi_writeinfo(info,WRITEINFO_UPDATE_KEYFILE); allow_break(); /* Allow SIGHUP & SIGINT */ if (info->invalidator != 0) { @@ -120,7 +120,7 @@ err: mi_print_error(info->s, HA_ERR_CRASHED); mi_mark_crashed(info); /* mark table crashed */ } - VOID(_mi_writeinfo(info,WRITEINFO_UPDATE_KEYFILE)); + (void) _mi_writeinfo(info,WRITEINFO_UPDATE_KEYFILE); info->update|=HA_STATE_WRITTEN; /* Buffer changed */ allow_break(); /* Allow SIGHUP & SIGINT */ my_errno=save_errno; diff --git a/storage/myisam/mi_delete_all.c b/storage/myisam/mi_delete_all.c index e2bbb04ab3c..cbf5abf7ef5 100644 --- a/storage/myisam/mi_delete_all.c +++ b/storage/myisam/mi_delete_all.c @@ -60,7 +60,7 @@ int mi_delete_all_rows(MI_INFO *info) if (my_chsize(info->dfile, 0, 0, MYF(MY_WME)) || my_chsize(share->kfile, share->base.keystart, 0, MYF(MY_WME)) ) goto err; - VOID(_mi_writeinfo(info,WRITEINFO_UPDATE_KEYFILE)); + (void) _mi_writeinfo(info,WRITEINFO_UPDATE_KEYFILE); #ifdef HAVE_MMAP /* Map again */ if (share->file_map) @@ -72,7 +72,7 @@ int mi_delete_all_rows(MI_INFO *info) err: { int save_errno=my_errno; - VOID(_mi_writeinfo(info,WRITEINFO_UPDATE_KEYFILE)); + (void) _mi_writeinfo(info,WRITEINFO_UPDATE_KEYFILE); info->update|=HA_STATE_WRITTEN; /* Buffer changed */ allow_break(); /* Allow SIGHUP & SIGINT */ DBUG_RETURN(my_errno=save_errno); diff --git a/storage/myisam/mi_dynrec.c b/storage/myisam/mi_dynrec.c index 79f1ea0e4e5..1de0fef876d 100644 --- a/storage/myisam/mi_dynrec.c +++ b/storage/myisam/mi_dynrec.c @@ -115,7 +115,7 @@ void mi_remap_file(MI_INFO *info, my_off_t size) { if (info->s->file_map) { - VOID(my_munmap((char*) info->s->file_map, + (void) (my_munmap((char*) info->s->file_map, (size_t) info->s->mmaped_length)); mi_dynmap_file(info, size); } @@ -1515,7 +1515,7 @@ int _mi_read_dynamic_record(MI_INFO *info, my_off_t filepos, uchar *buf) panic: my_errno=HA_ERR_WRONG_IN_RECORD; err: - VOID(_mi_writeinfo(info,0)); + (void) _mi_writeinfo(info,0); DBUG_RETURN(-1); } @@ -1831,7 +1831,7 @@ int _mi_read_rnd_dynamic_record(MI_INFO *info, uchar *buf, block_info.filepos + block_info.data_len && flush_io_cache(&info->rec_cache)) goto err; - /* VOID(my_seek(info->dfile,filepos,MY_SEEK_SET,MYF(0))); */ + /* my_seek(info->dfile,filepos,MY_SEEK_SET,MYF(0)); */ if (my_read(info->dfile,(uchar*) to,block_info.data_len,MYF(MY_NABP))) { if (my_errno == -1) @@ -1865,7 +1865,7 @@ panic: my_errno=HA_ERR_WRONG_IN_RECORD; /* Something is fatal wrong */ err: save_errno=my_errno; - VOID(_mi_writeinfo(info,0)); + (void) _mi_writeinfo(info,0); DBUG_RETURN(my_errno=save_errno); } @@ -1884,7 +1884,7 @@ uint _mi_get_block_info(MI_BLOCK_INFO *info, File file, my_off_t filepos) pointer set to the end of the header after this function. my_pread() may leave the file pointer untouched. */ - VOID(my_seek(file,filepos,MY_SEEK_SET,MYF(0))); + my_seek(file,filepos,MY_SEEK_SET,MYF(0)); if (my_read(file, header, sizeof(info->header),MYF(0)) != sizeof(info->header)) goto err; diff --git a/storage/myisam/mi_info.c b/storage/myisam/mi_info.c index 91e7ca659e4..a454a4ade9b 100644 --- a/storage/myisam/mi_info.c +++ b/storage/myisam/mi_info.c @@ -43,7 +43,7 @@ int mi_status(MI_INFO *info, register MI_ISAMINFO *x, uint flag) if (!(flag & HA_STATUS_NO_LOCK)) { pthread_mutex_lock(&share->intern_lock); - VOID(_mi_readinfo(info,F_RDLCK,0)); + (void) _mi_readinfo(info,F_RDLCK,0); fast_mi_writeinfo(info); pthread_mutex_unlock(&share->intern_lock); } diff --git a/storage/myisam/mi_locking.c b/storage/myisam/mi_locking.c index 8a5866ae763..687962af42a 100644 --- a/storage/myisam/mi_locking.c +++ b/storage/myisam/mi_locking.c @@ -173,12 +173,12 @@ int mi_lock_database(MI_INFO *info, int lock_type) if (mi_state_info_read_dsk(share->kfile, &share->state, 1)) { error=my_errno; - VOID(my_lock(share->kfile,F_UNLCK,0L,F_TO_EOF,MYF(MY_SEEK_NOT_DONE))); + (void) my_lock(share->kfile,F_UNLCK,0L,F_TO_EOF,MYF(MY_SEEK_NOT_DONE)); my_errno=error; break; } } - VOID(_mi_test_if_changed(info)); + (void) _mi_test_if_changed(info); share->r_locks++; share->tot_locks++; info->lock_type=lock_type; @@ -217,15 +217,15 @@ int mi_lock_database(MI_INFO *info, int lock_type) if (mi_state_info_read_dsk(share->kfile, &share->state, 1)) { error=my_errno; - VOID(my_lock(share->kfile,F_UNLCK,0L,F_TO_EOF, - info->lock_wait | MY_SEEK_NOT_DONE)); + (void) my_lock(share->kfile,F_UNLCK,0L,F_TO_EOF, + info->lock_wait | MY_SEEK_NOT_DONE); my_errno=error; break; } } } } - VOID(_mi_test_if_changed(info)); + (void) _mi_test_if_changed(info); info->lock_type=lock_type; info->invalidator=info->s->invalidator; @@ -412,14 +412,14 @@ int _mi_readinfo(register MI_INFO *info, int lock_type, int check_keybuffer) if (mi_state_info_read_dsk(share->kfile, &share->state, 1)) { int error=my_errno ? my_errno : -1; - VOID(my_lock(share->kfile,F_UNLCK,0L,F_TO_EOF, - MYF(MY_SEEK_NOT_DONE))); + (void) my_lock(share->kfile,F_UNLCK,0L,F_TO_EOF, + MYF(MY_SEEK_NOT_DONE)); my_errno=error; DBUG_RETURN(1); } } if (check_keybuffer) - VOID(_mi_test_if_changed(info)); + (void) _mi_test_if_changed(info); info->invalidator=info->s->invalidator; } else if (lock_type == F_WRLCK && info->lock_type == F_RDLCK) @@ -487,7 +487,7 @@ int _mi_test_if_changed(register MI_INFO *info) { /* Keyfile has changed */ DBUG_PRINT("info",("index file changed")); if (share->state.process != share->this_process) - VOID(flush_key_blocks(share->key_cache, share->kfile, FLUSH_RELEASE)); + (void) flush_key_blocks(share->key_cache, share->kfile, FLUSH_RELEASE); share->last_process=share->state.process; info->last_unique= share->state.unique; info->last_loop= share->state.update_count; diff --git a/storage/myisam/mi_log.c b/storage/myisam/mi_log.c index 8b9ca038fec..14e496e79b7 100644 --- a/storage/myisam/mi_log.c +++ b/storage/myisam/mi_log.c @@ -88,8 +88,8 @@ void _myisam_log(enum myisam_log_commands command, MI_INFO *info, pthread_mutex_lock(&THR_LOCK_myisam); error=my_lock(myisam_log_file,F_WRLCK,0L,F_TO_EOF,MYF(MY_SEEK_NOT_DONE)); - VOID(my_write(myisam_log_file,buff,sizeof(buff),MYF(0))); - VOID(my_write(myisam_log_file,buffert,length,MYF(0))); + (void) my_write(myisam_log_file,buff,sizeof(buff),MYF(0)); + (void) my_write(myisam_log_file,buffert,length,MYF(0)); if (!error) error=my_lock(myisam_log_file,F_UNLCK,0L,F_TO_EOF,MYF(MY_SEEK_NOT_DONE)); pthread_mutex_unlock(&THR_LOCK_myisam); @@ -111,9 +111,9 @@ void _myisam_log_command(enum myisam_log_commands command, MI_INFO *info, mi_int2store(buff+7,result); pthread_mutex_lock(&THR_LOCK_myisam); error=my_lock(myisam_log_file,F_WRLCK,0L,F_TO_EOF,MYF(MY_SEEK_NOT_DONE)); - VOID(my_write(myisam_log_file,buff,sizeof(buff),MYF(0))); + (void) my_write(myisam_log_file,buff,sizeof(buff),MYF(0)); if (buffert) - VOID(my_write(myisam_log_file,buffert,length,MYF(0))); + (void) my_write(myisam_log_file,buffert,length,MYF(0)); if (!error) error=my_lock(myisam_log_file,F_UNLCK,0L,F_TO_EOF,MYF(MY_SEEK_NOT_DONE)); pthread_mutex_unlock(&THR_LOCK_myisam); @@ -142,8 +142,8 @@ void _myisam_log_record(enum myisam_log_commands command, MI_INFO *info, mi_int4store(buff+17,length); pthread_mutex_lock(&THR_LOCK_myisam); error=my_lock(myisam_log_file,F_WRLCK,0L,F_TO_EOF,MYF(MY_SEEK_NOT_DONE)); - VOID(my_write(myisam_log_file, buff,sizeof(buff),MYF(0))); - VOID(my_write(myisam_log_file, record,info->s->base.reclength,MYF(0))); + (void) my_write(myisam_log_file, buff,sizeof(buff),MYF(0)); + (void) my_write(myisam_log_file, record,info->s->base.reclength,MYF(0)); if (info->s->base.blobs) { MI_BLOB *blob,*end; @@ -154,7 +154,7 @@ void _myisam_log_record(enum myisam_log_commands command, MI_INFO *info, { memcpy_fixed((uchar*) &pos, record+blob->offset+blob->pack_length, sizeof(char*)); - VOID(my_write(myisam_log_file,pos,blob->length,MYF(0))); + (void) my_write(myisam_log_file,pos,blob->length,MYF(0)); } } if (!error) diff --git a/storage/myisam/mi_open.c b/storage/myisam/mi_open.c index 9117d76de24..b97470c0aa6 100644 --- a/storage/myisam/mi_open.c +++ b/storage/myisam/mi_open.c @@ -181,7 +181,7 @@ MI_INFO *mi_open(const char *name, int mode, uint open_flags) end_pos=disk_cache+info_length; errpos=2; - VOID(my_seek(kfile,0L,MY_SEEK_SET,MYF(0))); + my_seek(kfile,0L,MY_SEEK_SET,MYF(0)); if (!(open_flags & HA_OPEN_TMP_TABLE)) { if ((lock_error=my_lock(kfile,F_RDLCK,0L,F_TO_EOF, @@ -482,7 +482,7 @@ MI_INFO *mi_open(const char *name, int mode, uint open_flags) if (! lock_error) { - VOID(my_lock(kfile,F_UNLCK,0L,F_TO_EOF,MYF(MY_SEEK_NOT_DONE))); + (void) my_lock(kfile,F_UNLCK,0L,F_TO_EOF,MYF(MY_SEEK_NOT_DONE)); lock_error=1; /* Database unlocked */ } @@ -522,10 +522,10 @@ MI_INFO *mi_open(const char *name, int mode, uint open_flags) share->is_log_table= FALSE; #ifdef THREAD thr_lock_init(&share->lock); - VOID(pthread_mutex_init(&share->intern_lock,MY_MUTEX_INIT_FAST)); + pthread_mutex_init(&share->intern_lock,MY_MUTEX_INIT_FAST); for (i=0; ikey_root_lock[i], NULL)); - VOID(my_rwlock_init(&share->mmap_lock, NULL)); + (void) my_rwlock_init(&share->key_root_lock[i], NULL); + (void) my_rwlock_init(&share->mmap_lock, NULL); if (!thr_lock_inited) { /* Probably a single threaded program; Don't use concurrent inserts */ @@ -670,7 +670,7 @@ err: my_free((uchar*) m_info,MYF(0)); /* fall through */ case 5: - VOID(my_close(info.dfile,MYF(0))); + (void) my_close(info.dfile,MYF(0)); if (old_info) break; /* Don't remove open table */ /* fall through */ @@ -679,13 +679,13 @@ err: /* fall through */ case 3: if (! lock_error) - VOID(my_lock(kfile, F_UNLCK, 0L, F_TO_EOF, MYF(MY_SEEK_NOT_DONE))); + (void) my_lock(kfile, F_UNLCK, 0L, F_TO_EOF, MYF(MY_SEEK_NOT_DONE)); /* fall through */ case 2: my_afree(disk_cache); /* fall through */ case 1: - VOID(my_close(kfile,MYF(0))); + (void) my_close(kfile,MYF(0)); /* fall through */ case 0: default: diff --git a/storage/myisam/mi_packrec.c b/storage/myisam/mi_packrec.c index 5ef9aa7f88f..887a8254979 100644 --- a/storage/myisam/mi_packrec.c +++ b/storage/myisam/mi_packrec.c @@ -1373,7 +1373,7 @@ uint _mi_pack_get_block_info(MI_INFO *myisam, MI_BIT_BUFF *bit_buff, We can't use my_pread() here because mi_read_rnd_pack_record assumes position is ok */ - VOID(my_seek(file,filepos,MY_SEEK_SET,MYF(0))); + my_seek(file,filepos,MY_SEEK_SET,MYF(0)); if (my_read(file, header,ref_length,MYF(MY_NABP))) return BLOCK_FATAL_ERROR; DBUG_DUMP("header",(uchar*) header,ref_length); @@ -1516,8 +1516,8 @@ my_bool _mi_memmap_file(MI_INFO *info) void _mi_unmap_file(MI_INFO *info) { - VOID(my_munmap((char*) info->s->file_map, - (size_t) info->s->mmaped_length + MEMMAP_EXTRA_MARGIN)); + (void) my_munmap((char*) info->s->file_map, + (size_t) info->s->mmaped_length + MEMMAP_EXTRA_MARGIN); } diff --git a/storage/myisam/mi_panic.c b/storage/myisam/mi_panic.c index 74c93761b61..02dfb239cc0 100644 --- a/storage/myisam/mi_panic.c +++ b/storage/myisam/mi_panic.c @@ -103,7 +103,7 @@ int mi_panic(enum ha_panic_function flag) } if (flag == HA_PANIC_CLOSE) { - VOID(mi_log(0)); /* Close log if neaded */ + (void) mi_log(0); /* Close log if neaded */ ft_free_stopwords(); } pthread_mutex_unlock(&THR_LOCK_myisam); diff --git a/storage/myisam/mi_rsame.c b/storage/myisam/mi_rsame.c index 8093498483f..08c482acc9b 100644 --- a/storage/myisam/mi_rsame.c +++ b/storage/myisam/mi_rsame.c @@ -50,9 +50,9 @@ int mi_rsame(MI_INFO *info, uchar *record, int inx) info->lastpos); if (info->s->concurrent_insert) rw_rdlock(&info->s->key_root_lock[inx]); - VOID(_mi_search(info,info->s->keyinfo+inx,info->lastkey, USE_WHOLE_KEY, + (void) _mi_search(info,info->s->keyinfo+inx,info->lastkey, USE_WHOLE_KEY, SEARCH_SAME, - info->s->state.key_root[inx])); + info->s->state.key_root[inx]); if (info->s->concurrent_insert) rw_unlock(&info->s->key_root_lock[inx]); } diff --git a/storage/myisam/mi_statrec.c b/storage/myisam/mi_statrec.c index e3771560c01..74fca5902f5 100644 --- a/storage/myisam/mi_statrec.c +++ b/storage/myisam/mi_statrec.c @@ -282,7 +282,7 @@ int _mi_read_rnd_static_record(MI_INFO *info, uchar *buf, info->s->base.pack_reclength - info->s->base.reclength); } if (locked) - VOID(_mi_writeinfo(info,0)); /* Unlock keyfile */ + (void) _mi_writeinfo(info,0); /* Unlock keyfile */ if (!error) { if (!buf[0]) diff --git a/storage/myisam/mi_test1.c b/storage/myisam/mi_test1.c index f218bf4e77f..d4b8dea9ede 100644 --- a/storage/myisam/mi_test1.c +++ b/storage/myisam/mi_test1.c @@ -161,7 +161,7 @@ static int run_test(const char *filename) row_count=deleted=0; for (i=49 ; i>=1 ; i-=2 ) { - if (insert_count-- == 0) { VOID(mi_close(file)) ; exit(0) ; } + if (insert_count-- == 0) { (void) mi_close(file); exit(0) ; } j=i%25 +1; create_record(record,j); error=mi_write(file,record); @@ -225,7 +225,7 @@ static int run_test(const char *filename) found=0; while ((error=mi_rrnd(file,read_record,pos)) == 0) { - if (update_count-- == 0) { VOID(mi_close(file)) ; exit(0) ; } + if (update_count-- == 0) { (void) mi_close(file); exit(0) ; } memcpy(record,read_record,rec_length); update_record(record); if (mi_update(file,read_record,record)) @@ -252,7 +252,7 @@ static int run_test(const char *filename) for (i=0 ; i <= 10 ; i++) { /* testing */ - if (remove_count-- == 0) { VOID(mi_close(file)) ; exit(0) ; } + if (remove_count-- == 0) { (void) mi_close(file); exit(0) ; } j=i*2; if (!flags[j]) continue; diff --git a/storage/myisam/mi_test2.c b/storage/myisam/mi_test2.c index 23c58638166..860626b84a9 100644 --- a/storage/myisam/mi_test2.c +++ b/storage/myisam/mi_test2.c @@ -862,7 +862,7 @@ reads: %10lu\n", err: printf("got error: %d when using MyISAM-database\n",my_errno); if (file) - VOID(mi_close(file)); + (void) mi_close(file); return(1); } /* main */ diff --git a/storage/myisam/mi_test3.c b/storage/myisam/mi_test3.c index 5bdc33b8518..6871658e486 100644 --- a/storage/myisam/mi_test3.c +++ b/storage/myisam/mi_test3.c @@ -109,7 +109,7 @@ int main(int argc,char **argv) sleep(1); return 0; } - VOID(rnd(1)); + (void) rnd(1); } for (i=0 ; i < forks ; i++) diff --git a/storage/myisam/mi_update.c b/storage/myisam/mi_update.c index a18bb5f1443..b538bcd0bb1 100644 --- a/storage/myisam/mi_update.c +++ b/storage/myisam/mi_update.c @@ -178,7 +178,7 @@ int mi_update(register MI_INFO *info, const uchar *oldrec, uchar *newrec) mi_update() must always pass !0 value as operation, since even if there is no index change there could be data change. */ - VOID(_mi_writeinfo(info, WRITEINFO_UPDATE_KEYFILE)); + (void) _mi_writeinfo(info, WRITEINFO_UPDATE_KEYFILE); allow_break(); /* Allow SIGHUP & SIGINT */ if (info->invalidator != 0) { @@ -229,7 +229,7 @@ err: err_end: myisam_log_record(MI_LOG_UPDATE,info,newrec,info->lastpos,my_errno); - VOID(_mi_writeinfo(info,WRITEINFO_UPDATE_KEYFILE)); + (void) _mi_writeinfo(info,WRITEINFO_UPDATE_KEYFILE); allow_break(); /* Allow SIGHUP & SIGINT */ if (save_errno == HA_ERR_KEY_NOT_FOUND) { diff --git a/storage/myisam/mi_write.c b/storage/myisam/mi_write.c index 624c31e57ff..b9bc84aa6ad 100644 --- a/storage/myisam/mi_write.c +++ b/storage/myisam/mi_write.c @@ -155,7 +155,7 @@ int mi_write(MI_INFO *info, uchar *record) info->state->records++; info->lastpos=filepos; myisam_log_record(MI_LOG_WRITE,info,record,filepos,0); - VOID(_mi_writeinfo(info, WRITEINFO_UPDATE_KEYFILE)); + (void) _mi_writeinfo(info, WRITEINFO_UPDATE_KEYFILE); if (info->invalidator != 0) { DBUG_PRINT("info", ("invalidator... '%s' (update)", info->filename)); @@ -232,7 +232,7 @@ err: err2: save_errno=my_errno; myisam_log_record(MI_LOG_WRITE,info,record,filepos,my_errno); - VOID(_mi_writeinfo(info,WRITEINFO_UPDATE_KEYFILE)); + (void) _mi_writeinfo(info,WRITEINFO_UPDATE_KEYFILE); allow_break(); /* Allow SIGHUP & SIGINT */ DBUG_RETURN(my_errno=save_errno); } /* mi_write */ diff --git a/storage/myisam/myisamchk.c b/storage/myisam/myisamchk.c index 611fb6325c8..7df043ce801 100644 --- a/storage/myisam/myisamchk.c +++ b/storage/myisam/myisamchk.c @@ -99,8 +99,8 @@ int main(int argc, char **argv) int new_error=myisamchk(&check_param, *(argv++)); if ((check_param.testflag & T_REP_ANY) != T_REP) check_param.testflag&= ~T_REP; - VOID(fflush(stdout)); - VOID(fflush(stderr)); + (void) fflush(stdout); + (void) fflush(stderr); if ((check_param.error_printed | check_param.warning_printed) && (check_param.testflag & T_FORCE_CREATE) && (!(check_param.testflag & (T_REP | T_REP_BY_SORT | T_SORT_RECORDS | @@ -112,15 +112,15 @@ int main(int argc, char **argv) check_param.testflag&= ~T_EXTEND; /* Don't needed */ error|=myisamchk(&check_param, argv[-1]); check_param.testflag= old_testflag; - VOID(fflush(stdout)); - VOID(fflush(stderr)); + (void) fflush(stdout); + (void) fflush(stderr); } else error|=new_error; if (argc && (!(check_param.testflag & T_SILENT) || check_param.testflag & T_INFO)) { puts("\n---------\n"); - VOID(fflush(stdout)); + (void) fflush(stdout); } } if (check_param.total_files > 1) @@ -762,9 +762,9 @@ static void get_options(register int *argc,register char ***argv) if ((check_param.testflag & T_UNPACK) && (check_param.testflag & (T_QUICK | T_SORT_RECORDS))) { - VOID(fprintf(stderr, + (void) fprintf(stderr, "%s: --unpack can't be used with --quick or --sort-records\n", - my_progname_short)); + my_progname_short); exit(1); } if ((check_param.testflag & T_READONLY) && @@ -772,9 +772,9 @@ static void get_options(register int *argc,register char ***argv) (T_REP_ANY | T_STATISTICS | T_AUTO_INC | T_SORT_RECORDS | T_SORT_INDEX | T_FORCE_CREATE))) { - VOID(fprintf(stderr, + (void) fprintf(stderr, "%s: Can't use --readonly when repairing or sorting\n", - my_progname_short)); + my_progname_short); exit(1); } @@ -928,9 +928,9 @@ static int myisamchk(MI_CHECK *param, char * filename) param->language= set_collation->number; if (recreate_table(param, &info,filename)) { - VOID(fprintf(stderr, + (void) fprintf(stderr, "MyISAM-table '%s' is not fixed because of errors\n", - filename)); + filename); return(-1); } recreate=1; @@ -1030,7 +1030,7 @@ static int myisamchk(MI_CHECK *param, char * filename) #ifndef TO_BE_REMOVED if (param->out_flag & O_NEW_DATA) { /* Change temp file to org file */ - VOID(my_close(info->dfile,MYF(MY_WME))); /* Close new file */ + (void) my_close(info->dfile,MYF(MY_WME)); /* Close new file */ error|=change_to_newfile(filename,MI_NAME_DEXT,DATA_TMP_EXT, raid_chunks, MYF(0)); @@ -1101,23 +1101,23 @@ static int myisamchk(MI_CHECK *param, char * filename) !(param->testflag & (T_FAST | T_FORCE_CREATE))) { if (param->testflag & (T_EXTEND | T_MEDIUM)) - VOID(init_key_cache(dflt_key_cache,opt_key_cache_block_size, - (size_t) param->use_buffers, 0, 0)); - VOID(init_io_cache(¶m->read_cache,datafile, + (void) init_key_cache(dflt_key_cache,opt_key_cache_block_size, + param->use_buffers, 0, 0); + (void) init_io_cache(¶m->read_cache,datafile, (uint) param->read_buffer_length, READ_CACHE, (param->start_check_pos ? param->start_check_pos : share->pack.header_length), 1, - MYF(MY_WME))); + MYF(MY_WME)); lock_memory(param); if ((info->s->options & (HA_OPTION_PACK_RECORD | HA_OPTION_COMPRESS_RECORD)) || (param->testflag & (T_EXTEND | T_MEDIUM))) error|=chk_data_link(param, info, param->testflag & T_EXTEND); error|=flush_blocks(param, share->key_cache, share->kfile); - VOID(end_io_cache(¶m->read_cache)); + (void) end_io_cache(¶m->read_cache); } if (!error) { @@ -1150,7 +1150,7 @@ static int myisamchk(MI_CHECK *param, char * filename) (state_updated ? UPDATE_STAT : 0) | ((param->testflag & T_SORT_RECORDS) ? UPDATE_SORT : 0))); - VOID(lock_file(param, share->kfile,0L,F_UNLCK,"indexfile",filename)); + (void) lock_file(param, share->kfile,0L,F_UNLCK,"indexfile",filename); info->update&= ~HA_STATE_CHANGED; } mi_lock_database(info, F_UNLCK); @@ -1171,30 +1171,30 @@ end2: error|=change_to_newfile(filename,MI_NAME_IEXT,INDEX_TMP_EXT,0, MYF(0)); } - VOID(fflush(stdout)); VOID(fflush(stderr)); + (void) fflush(stdout); (void) fflush(stderr); if (param->error_printed) { if (param->testflag & (T_REP_ANY | T_SORT_RECORDS | T_SORT_INDEX)) { - VOID(fprintf(stderr, + (void) fprintf(stderr, "MyISAM-table '%s' is not fixed because of errors\n", - filename)); + filename); if (param->testflag & T_REP_ANY) - VOID(fprintf(stderr, - "Try fixing it by using the --safe-recover (-o), the --force (-f) option or by not using the --quick (-q) flag\n")); + (void) fprintf(stderr, + "Try fixing it by using the --safe-recover (-o), the --force (-f) option or by not using the --quick (-q) flag\n"); } else if (!(param->error_printed & 2) && !(param->testflag & T_FORCE_CREATE)) - VOID(fprintf(stderr, + (void) fprintf(stderr, "MyISAM-table '%s' is corrupted\nFix it using switch \"-r\" or \"-o\"\n", - filename)); + filename); } else if (param->warning_printed && ! (param->testflag & (T_REP_ANY | T_SORT_RECORDS | T_SORT_INDEX | T_FORCE_CREATE))) - VOID(fprintf(stderr, "MyISAM-table '%s' is usable but should be fixed\n", - filename)); - VOID(fflush(stderr)); + (void) fprintf(stderr, "MyISAM-table '%s' is usable but should be fixed\n", + filename); + (void) fflush(stderr); DBUG_RETURN(error); } /* myisamchk */ @@ -1321,7 +1321,7 @@ static void descript(MI_CHECK *param, register MI_INFO *info, char * name) printf("Key Start Len Index Type"); if (param->testflag & T_VERBOSE) printf(" Rec/key Root Blocksize"); - VOID(putchar('\n')); + (void) putchar('\n'); for (key=keyseg_nr=0, keyinfo= &share->keyinfo[0] ; key < share->base.keys; @@ -1360,7 +1360,7 @@ static void descript(MI_CHECK *param, register MI_INFO *info, char * name) printf("%11lu %12s %10d", share->state.rec_per_key_part[keyseg_nr++], buff,keyinfo->block_length); - VOID(putchar('\n')); + (void) putchar('\n'); while ((++keyseg)->type != HA_KEYTYPE_END) { pos=buff; @@ -1379,7 +1379,7 @@ static void descript(MI_CHECK *param, register MI_INFO *info, char * name) (long) keyseg->start+1,keyseg->length,buff); if (param->testflag & T_VERBOSE) printf("%11lu", share->state.rec_per_key_part[keyseg_nr++]); - VOID(putchar('\n')); + (void) putchar('\n'); } keyseg++; } @@ -1417,7 +1417,7 @@ static void descript(MI_CHECK *param, register MI_INFO *info, char * name) printf("\nField Start Length Nullpos Nullbit Type"); if (share->options & HA_OPTION_COMPRESS_RECORD) printf(" Huff tree Bits"); - VOID(putchar('\n')); + (void) putchar('\n'); start=1; for (field=0 ; field < share->base.fields ; field++) { @@ -1456,7 +1456,7 @@ static void descript(MI_CHECK *param, register MI_INFO *info, char * name) (uint) (share->rec[field].huff_tree-share->decode_trees)+1, share->rec[field].huff_tree->quick_table_bits); } - VOID(putchar('\n')); + (void) putchar('\n'); start+=share->rec[field].length; } } @@ -1604,7 +1604,7 @@ static int mi_sort_records(MI_CHECK *param, goto err; } - VOID(my_close(info->dfile,MYF(MY_WME))); + (void) my_close(info->dfile,MYF(MY_WME)); param->out_flag|=O_NEW_DATA; /* Data in new file */ info->dfile=new_file; /* Use new datafile */ info->state->del=0; @@ -1618,14 +1618,14 @@ static int mi_sort_records(MI_CHECK *param, if (param->testflag & T_WRITE_LOOP) { - VOID(fputs(" \r",stdout)); VOID(fflush(stdout)); + (void) fputs(" \r",stdout); (void) fflush(stdout); } got_error=0; err: if (got_error && new_file >= 0) { - VOID(end_io_cache(&info->rec_cache)); + (void) end_io_cache(&info->rec_cache); (void) my_close(new_file,MYF(MY_WME)); (void) my_raid_delete(param->temp_filename, share->base.raid_chunks, MYF(MY_WME)); @@ -1637,7 +1637,7 @@ err: my_free(mi_get_rec_buff_ptr(info, sort_param.record), MYF(MY_ALLOW_ZERO_PTR)); info->opt_flag&= ~(READ_CACHE_USED | WRITE_CACHE_USED); - VOID(end_io_cache(&info->rec_cache)); + (void) end_io_cache(&info->rec_cache); my_free(sort_info.buff,MYF(MY_ALLOW_ZERO_PTR)); sort_info.buff=0; share->state.sortkey=sort_key; @@ -1761,8 +1761,8 @@ void mi_check_print_info(MI_CHECK *param __attribute__((unused)), va_list args; va_start(args,fmt); - VOID(vfprintf(stdout, fmt, args)); - VOID(fputc('\n',stdout)); + (void) vfprintf(stdout, fmt, args); + (void) fputc('\n',stdout); va_end(args); } @@ -1784,8 +1784,8 @@ void mi_check_print_warning(MI_CHECK *param, const char *fmt,...) param->warning_printed=1; va_start(args,fmt); fprintf(stderr,"%s: warning: ",my_progname_short); - VOID(vfprintf(stderr, fmt, args)); - VOID(fputc('\n',stderr)); + (void) vfprintf(stderr, fmt, args); + (void) fputc('\n',stderr); fflush(stderr); va_end(args); DBUG_VOID_RETURN; @@ -1809,8 +1809,8 @@ void mi_check_print_error(MI_CHECK *param, const char *fmt,...) param->error_printed|=1; va_start(args,fmt); fprintf(stderr,"%s: error: ",my_progname_short); - VOID(vfprintf(stderr, fmt, args)); - VOID(fputc('\n',stderr)); + (void) vfprintf(stderr, fmt, args); + (void) fputc('\n',stderr); fflush(stderr); va_end(args); DBUG_VOID_RETURN; diff --git a/storage/myisam/myisamlog.c b/storage/myisam/myisamlog.c index fafb5140a5e..622fd1a34a3 100644 --- a/storage/myisam/myisamlog.c +++ b/storage/myisam/myisamlog.c @@ -121,7 +121,7 @@ int main(int argc, char **argv) if (re_open_count) printf("Had to do %d re-open because of too few possibly open files\n", re_open_count); - VOID(mi_panic(HA_PANIC_CLOSE)); + (void) mi_panic(HA_PANIC_CLOSE); my_free_open_file_info(); my_end(test_info ? MY_CHECK_ERROR | MY_GIVE_INFO : MY_CHECK_ERROR); exit(error); @@ -292,8 +292,8 @@ static void get_options(register int *argc, register char ***argv) } return; err: - VOID(fprintf(stderr,"option \"%c\" used without or with wrong argument\n", - option)); + (void) fprintf(stderr,"option \"%c\" used without or with wrong argument\n", + option); exit(1); } @@ -332,8 +332,8 @@ static int examine_log(char * file_name, char **table_names) bzero((uchar*) com_count,sizeof(com_count)); init_tree(&tree,0,0,sizeof(file_info),(qsort_cmp2) file_info_compare,1, (tree_element_free) file_info_free, NULL); - VOID(init_key_cache(dflt_key_cache,KEY_CACHE_BLOCK_SIZE,KEY_CACHE_SIZE, - 0, 0)); + (void) init_key_cache(dflt_key_cache,KEY_CACHE_BLOCK_SIZE,KEY_CACHE_SIZE, + 0, 0); files_open=0; access_time=0; while (access_time++ != number_of_commands && @@ -412,8 +412,8 @@ static int examine_log(char * file_name, char **table_names) } open_param.name=file_info.name; open_param.max_id=0; - VOID(tree_walk(&tree,(tree_walk_action) test_if_open,(void*) &open_param, - left_root_right)); + (void) tree_walk(&tree,(tree_walk_action) test_if_open,(void*) &open_param, + left_root_right); file_info.id=open_param.max_id+1; /* * In the line below +10 is added to accomodate '<' and '>' chars @@ -458,7 +458,7 @@ static int examine_log(char * file_name, char **table_names) files_open++; file_info.closed=0; } - VOID(tree_insert(&tree, (uchar*) &file_info, 0, tree.custom_arg)); + (void) tree_insert(&tree, (uchar*) &file_info, 0, tree.custom_arg); if (file_info.used) { if (verbose && !record_pos_file) @@ -477,7 +477,7 @@ static int examine_log(char * file_name, char **table_names) { if (!curr_file_info->closed) files_open--; - VOID(tree_delete(&tree, (uchar*) curr_file_info, 0, tree.custom_arg)); + (void) tree_delete(&tree, (uchar*) curr_file_info, 0, tree.custom_arg); } break; case MI_LOG_EXTRA: @@ -493,10 +493,10 @@ static int examine_log(char * file_name, char **table_names) if (mi_extra(curr_file_info->isam, extra_command, 0) != (int) result) { fflush(stdout); - VOID(fprintf(stderr, + (void) fprintf(stderr, "Warning: error %d, expected %d on command %s at %s\n", my_errno,result,command_name[command], - llstr(isamlog_filepos,llbuff))); + llstr(isamlog_filepos,llbuff)); fflush(stderr); } } @@ -641,39 +641,39 @@ static int examine_log(char * file_name, char **table_names) break; default: fflush(stdout); - VOID(fprintf(stderr, + (void) fprintf(stderr, "Error: found unknown command %d in logfile, aborted\n", - command)); + command); fflush(stderr); goto end; } } end_key_cache(dflt_key_cache,1); delete_tree(&tree); - VOID(end_io_cache(&cache)); - VOID(my_close(file,MYF(0))); + (void) end_io_cache(&cache); + (void) my_close(file,MYF(0)); if (write_file && my_fclose(write_file,MYF(MY_WME))) DBUG_RETURN(1); DBUG_RETURN(0); err: fflush(stdout); - VOID(fprintf(stderr,"Got error %d when reading from logfile\n",my_errno)); + (void) fprintf(stderr,"Got error %d when reading from logfile\n",my_errno); fflush(stderr); goto end; com_err: fflush(stdout); - VOID(fprintf(stderr,"Got error %d, expected %d on command %s at %s\n", + (void) fprintf(stderr,"Got error %d, expected %d on command %s at %s\n", my_errno,result,command_name[command], - llstr(isamlog_filepos,llbuff))); + llstr(isamlog_filepos,llbuff)); fflush(stderr); end: end_key_cache(dflt_key_cache, 1); delete_tree(&tree); - VOID(end_io_cache(&cache)); - VOID(my_close(file,MYF(0))); + (void) end_io_cache(&cache); + (void) my_close(file,MYF(0)); if (write_file) - VOID(my_fclose(write_file,MYF(MY_WME))); + (void) my_fclose(write_file,MYF(MY_WME)); DBUG_RETURN(1); } @@ -757,7 +757,7 @@ static void file_info_free(struct file_info *fileinfo) if (update) { if (!fileinfo->closed) - VOID(mi_close(fileinfo->isam)); + (void) mi_close(fileinfo->isam); if (fileinfo->record) my_free(fileinfo->record,MYF(0)); } @@ -775,8 +775,8 @@ static int close_some_file(TREE *tree) access_param.min_accessed=LONG_MAX; access_param.found=0; - VOID(tree_walk(tree,(tree_walk_action) test_when_accessed, - (void*) &access_param,left_root_right)); + (void) tree_walk(tree,(tree_walk_action) test_when_accessed, + (void*) &access_param,left_root_right); if (!access_param.found) return 1; /* No open file that is possibly to close */ if (mi_close(access_param.found->isam)) @@ -815,7 +815,7 @@ static int find_record_with_key(struct file_info *file_info, uchar *record) if (mi_is_key_active(info->s->state.key_map, key) && info->s->keyinfo[key].flag & HA_NOSAME) { - VOID(_mi_make_key(info,key,tmp_key,record,0L)); + (void) _mi_make_key(info,key,tmp_key,record,0L); return mi_rkey(info,file_info->record,(int) key,tmp_key,0, HA_READ_KEY_EXACT); } diff --git a/storage/myisam/myisampack.c b/storage/myisam/myisampack.c index 908c32e48d3..8adfcfd6fb2 100644 --- a/storage/myisam/myisampack.c +++ b/storage/myisam/myisampack.c @@ -238,8 +238,8 @@ int main(int argc, char **argv) } if (ok && isamchk_neaded && !silent) puts("Remember to run myisamchk -rq on compressed tables"); - VOID(fflush(stdout)); - VOID(fflush(stderr)); + (void) fflush(stdout); + (void) fflush(stderr); free_defaults(default_argv); my_end(verbose ? MY_CHECK_ERROR | MY_GIVE_INFO : MY_CHECK_ERROR); exit(error ? 2 : 0); @@ -291,8 +291,8 @@ static struct my_option my_long_options[] = static void print_version(void) { - VOID(printf("%s Ver 1.23 for %s on %s\n", - my_progname, SYSTEM_TYPE, MACHINE_TYPE)); + printf("%s Ver 1.23 for %s on %s\n", + my_progname, SYSTEM_TYPE, MACHINE_TYPE); NETWARE_SET_SCREEN_MODE(1); } @@ -309,7 +309,7 @@ static void usage(void) puts("afterwards to update the keys."); puts("You should give the .MYI file as the filename argument."); - VOID(printf("\nUsage: %s [OPTIONS] filename...\n", my_progname)); + printf("\nUsage: %s [OPTIONS] filename...\n", my_progname); my_print_help(my_long_options); print_defaults("my", load_default_groups); my_print_variables(my_long_options); @@ -407,7 +407,7 @@ static MI_INFO *open_isam_file(char *name,int mode) (opt_wait ? HA_OPEN_WAIT_IF_LOCKED : HA_OPEN_ABORT_IF_LOCKED)))) { - VOID(fprintf(stderr, "%s gave error %d on open\n", name, my_errno)); + (void) fprintf(stderr, "%s gave error %d on open\n", name, my_errno); DBUG_RETURN(0); } share=isam_file->s; @@ -415,8 +415,8 @@ static MI_INFO *open_isam_file(char *name,int mode) { if (!force_pack) { - VOID(fprintf(stderr, "%s is already compressed\n", name)); - VOID(mi_close(isam_file)); + (void) fprintf(stderr, "%s is already compressed\n", name); + (void) mi_close(isam_file); DBUG_RETURN(0); } if (verbose) @@ -427,11 +427,11 @@ static MI_INFO *open_isam_file(char *name,int mode) (share->state.state.records <= 1 || share->state.state.data_file_length < 1024)) { - VOID(fprintf(stderr, "%s is too small to compress\n", name)); - VOID(mi_close(isam_file)); + (void) fprintf(stderr, "%s is too small to compress\n", name); + (void) mi_close(isam_file); DBUG_RETURN(0); } - VOID(mi_lock_database(isam_file,F_WRLCK)); + (void) mi_lock_database(isam_file,F_WRLCK); DBUG_RETURN(isam_file); } @@ -473,8 +473,8 @@ static my_bool open_isam_files(PACK_MRG_INFO *mrg, char **names, uint count) return 0; diff_file: - VOID(fprintf(stderr, "%s: Tables '%s' and '%s' are not identical\n", - my_progname, names[j], names[j+1])); + (void) fprintf(stderr, "%s: Tables '%s' and '%s' are not identical\n", + my_progname, names[j], names[j+1]); error: while (i--) mi_close(mrg->file[i]); @@ -506,16 +506,16 @@ static int compress(PACK_MRG_INFO *mrg,char *result_table) /* Create temporary or join file */ if (backup) - VOID(fn_format(org_name,isam_file->filename,"",MI_NAME_DEXT,2)); + (void) fn_format(org_name,isam_file->filename,"",MI_NAME_DEXT,2); else - VOID(fn_format(org_name,isam_file->filename,"",MI_NAME_DEXT,2+4+16)); + (void) fn_format(org_name,isam_file->filename,"",MI_NAME_DEXT,2+4+16); if (!test_only && result_table) { /* Make a new indexfile based on first file in list */ uint length; uchar *buff; strmov(org_name,result_table); /* Fix error messages */ - VOID(fn_format(new_name,result_table,"",MI_NAME_IEXT,2)); + (void) fn_format(new_name,result_table,"",MI_NAME_IEXT,2); if ((join_isam_file=my_create(new_name,0,tmpfile_createflag,MYF(MY_WME))) < 0) goto err; @@ -530,12 +530,12 @@ static int compress(PACK_MRG_INFO *mrg,char *result_table) goto err; } my_free(buff,MYF(0)); - VOID(fn_format(new_name,result_table,"",MI_NAME_DEXT,2)); + (void) fn_format(new_name,result_table,"",MI_NAME_DEXT,2); } else if (!tmp_dir[0]) - VOID(make_new_name(new_name,org_name)); + (void) make_new_name(new_name,org_name); else - VOID(fn_format(new_name,org_name,tmp_dir,DATA_TMP_EXT,1+2+4)); + (void) fn_format(new_name,org_name,tmp_dir,DATA_TMP_EXT,1+2+4); if (!test_only && (new_file=my_create(new_name,0,tmpfile_createflag,MYF(MY_WME))) < 0) goto err; @@ -551,8 +551,8 @@ static int compress(PACK_MRG_INFO *mrg,char *result_table) (ulong) mrg->records)); if (write_loop || verbose) { - VOID(printf("Compressing %s: (%lu records)\n", - result_table ? new_name : org_name, (ulong) mrg->records)); + printf("Compressing %s: (%lu records)\n", + result_table ? new_name : org_name, (ulong) mrg->records); } trees=fields=share->base.fields; huff_counts=init_huff_count(isam_file,mrg->records); @@ -563,7 +563,7 @@ static int compress(PACK_MRG_INFO *mrg,char *result_table) */ DBUG_PRINT("info", ("- Calculating statistics")); if (write_loop || verbose) - VOID(printf("- Calculating statistics\n")); + printf("- Calculating statistics\n"); if (get_statistic(mrg,huff_counts)) goto err; NORMAL_SAFEMALLOC; @@ -613,7 +613,7 @@ static int compress(PACK_MRG_INFO *mrg,char *result_table) */ file_buffer.pos_in_file=HEAD_LENGTH; if (! test_only) - VOID(my_seek(new_file,file_buffer.pos_in_file,MY_SEEK_SET,MYF(0))); + my_seek(new_file,file_buffer.pos_in_file,MY_SEEK_SET,MYF(0)); /* Write field infos: field type, pack type, length bits, tree number. @@ -639,7 +639,7 @@ static int compress(PACK_MRG_INFO *mrg,char *result_table) */ DBUG_PRINT("info", ("- Compressing file")); if (write_loop || verbose) - VOID(printf("- Compressing file\n")); + printf("- Compressing file\n"); error=compress_isam_file(mrg,huff_counts); new_length=file_buffer.pos_in_file; if (!error && !test_only) @@ -666,9 +666,9 @@ static int compress(PACK_MRG_INFO *mrg,char *result_table) mrg->min_pack_length, mrg->max_pack_length, (ulong) (mrg->records ? (new_length/mrg->records) : 0))); if (verbose && mrg->records) - VOID(printf("Min record length: %6d Max length: %6d " + printf("Min record length: %6d Max length: %6d " "Mean total length: %6ld\n", mrg->min_pack_length, - mrg->max_pack_length, (ulong) (new_length/mrg->records))); + mrg->max_pack_length, (ulong) (new_length/mrg->records)); /* Close source and target file. */ if (!test_only) @@ -704,9 +704,9 @@ static int compress(PACK_MRG_INFO *mrg,char *result_table) error=my_rename(new_name,org_name,MYF(MY_WME)); if (!error) { - VOID(my_copystat(temp_name,org_name,MYF(MY_COPYTIME))); + (void) my_copystat(temp_name,org_name,MYF(MY_COPYTIME)); if (tmp_dir[0]) - VOID(my_delete(new_name,MYF(MY_WME))); + (void) my_delete(new_name,MYF(MY_WME)); } } } @@ -717,7 +717,7 @@ static int compress(PACK_MRG_INFO *mrg,char *result_table) error=my_copy(new_name,org_name, MYF(MY_WME | MY_HOLD_ORIGINAL_MODES | MY_COPYTIME)); if (!error) - VOID(my_delete(new_name,MYF(MY_WME))); + (void) my_delete(new_name,MYF(MY_WME)); } else error=my_redel(org_name,new_name,MYF(MY_WME | MY_COPYTIME)); @@ -731,16 +731,16 @@ static int compress(PACK_MRG_INFO *mrg,char *result_table) error|=my_close(join_isam_file,MYF(MY_WME)); if (error) { - VOID(fprintf(stderr, "Aborting: %s is not compressed\n", org_name)); - VOID(my_delete(new_name,MYF(MY_WME))); + (void) fprintf(stderr, "Aborting: %s is not compressed\n", org_name); + (void) my_delete(new_name,MYF(MY_WME)); DBUG_RETURN(-1); } if (write_loop || verbose) { if (old_length) - VOID(printf("%.4g%% \n", + printf("%.4g%% \n", (((longlong) (old_length - new_length)) * 100.0 / - (longlong) old_length))); + (longlong) old_length)); else puts("Empty file saved in compressed format"); } @@ -749,11 +749,11 @@ static int compress(PACK_MRG_INFO *mrg,char *result_table) err: free_counts_and_tree_and_queue(huff_trees,trees,huff_counts,fields); if (new_file >= 0) - VOID(my_close(new_file,MYF(0))); + (void) my_close(new_file,MYF(0)); if (join_isam_file >= 0) - VOID(my_close(join_isam_file,MYF(0))); + (void) my_close(join_isam_file,MYF(0)); mrg_close(mrg); - VOID(fprintf(stderr, "Aborted: %s is not compressed\n", org_name)); + (void) fprintf(stderr, "Aborted: %s is not compressed\n", org_name); DBUG_RETURN(-1); } @@ -1069,13 +1069,13 @@ static int get_statistic(PACK_MRG_INFO *mrg,HUFF_COUNTS *huff_counts) record_count++; if (write_loop && record_count % WRITE_COUNT == 0) { - VOID(printf("%lu\r", (ulong) record_count)); - VOID(fflush(stdout)); + printf("%lu\r", (ulong) record_count); + (void) fflush(stdout); } } else if (error != HA_ERR_RECORD_DELETED) { - VOID(fprintf(stderr, "Got error %d while reading rows", error)); + (void) fprintf(stderr, "Got error %d while reading rows", error); break; } @@ -1083,8 +1083,8 @@ static int get_statistic(PACK_MRG_INFO *mrg,HUFF_COUNTS *huff_counts) } if (write_loop) { - VOID(printf(" \r")); - VOID(fflush(stdout)); + printf(" \r"); + (void) fflush(stdout); } /* @@ -1096,8 +1096,8 @@ static int get_statistic(PACK_MRG_INFO *mrg,HUFF_COUNTS *huff_counts) DBUG_PRINT("info", ("Found the following number of incidents " "of the byte codes:")); if (verbose >= 2) - VOID(printf("Found the following number of incidents " - "of the byte codes:\n")); + printf("Found the following number of incidents " + "of the byte codes:\n"); for (count= huff_counts ; count < end_count; count++) { uint idx; @@ -1106,16 +1106,16 @@ static int get_statistic(PACK_MRG_INFO *mrg,HUFF_COUNTS *huff_counts) DBUG_PRINT("info", ("column: %3u", (uint) (count - huff_counts + 1))); if (verbose >= 2) - VOID(printf("column: %3u\n", (uint) (count - huff_counts + 1))); + printf("column: %3u\n", (uint) (count - huff_counts + 1)); if (count->tree_buff) { DBUG_PRINT("info", ("number of distinct values: %u", (uint) ((count->tree_pos - count->tree_buff) / count->field_length))); if (verbose >= 2) - VOID(printf("number of distinct values: %u\n", + printf("number of distinct values: %u\n", (uint) ((count->tree_pos - count->tree_buff) / - count->field_length))); + count->field_length)); } total_count= 0; for (idx= 0; idx < 256; idx++) @@ -1126,16 +1126,16 @@ static int get_statistic(PACK_MRG_INFO *mrg,HUFF_COUNTS *huff_counts) DBUG_PRINT("info", ("counts[0x%02x]: %12s", idx, llstr((longlong) count->counts[idx], llbuf))); if (verbose >= 2) - VOID(printf("counts[0x%02x]: %12s\n", idx, - llstr((longlong) count->counts[idx], llbuf))); + printf("counts[0x%02x]: %12s\n", idx, + llstr((longlong) count->counts[idx], llbuf)); } } DBUG_PRINT("info", ("total: %12s", llstr((longlong) total_count, llbuf))); if ((verbose >= 2) && total_count) { - VOID(printf("total: %12s\n", - llstr((longlong) total_count, llbuf))); + printf("total: %12s\n", + llstr((longlong) total_count, llbuf)); } } @@ -1352,7 +1352,7 @@ static void check_counts(HUFF_COUNTS *huff_counts, uint trees, field_count[FIELD_INTERVALL], field_count[FIELD_ZERO])); if (verbose) - VOID(printf("\nnormal: %3d empty-space: %3d " + printf("\nnormal: %3d empty-space: %3d " "empty-zero: %3d empty-fill: %3d\n" "pre-space: %3d end-space: %3d " "intervall-fields: %3d zero: %3d\n", @@ -1361,7 +1361,7 @@ static void check_counts(HUFF_COUNTS *huff_counts, uint trees, field_count[FIELD_SKIP_PRESPACE], field_count[FIELD_SKIP_ENDSPACE], field_count[FIELD_INTERVALL], - field_count[FIELD_ZERO])); + field_count[FIELD_ZERO]); DBUG_VOID_RETURN; } @@ -1876,7 +1876,7 @@ static uint join_same_trees(HUFF_COUNTS *huff_counts, uint trees) DBUG_PRINT("info", ("Original trees: %d After join: %d", trees, tree_number)); if (verbose) - VOID(printf("Original trees: %d After join: %d\n", trees, tree_number)); + printf("Original trees: %d After join: %d\n", trees, tree_number); return tree_number; /* Return trees left */ } @@ -2022,7 +2022,7 @@ static int write_header(PACK_MRG_INFO *mrg,uint head_length,uint trees, buff[27]= (uchar) mi_get_pointer_length((ulonglong) filelength,2); if (test_only) return 0; - VOID(my_seek(file_buffer.file,0L,MY_SEEK_SET,MYF(0))); + my_seek(file_buffer.file,0L,MY_SEEK_SET,MYF(0)); return my_write(file_buffer.file,(const uchar *) file_buffer.pos,HEAD_LENGTH, MYF(MY_WME | MY_NABP | MY_WAIT_IF_FULL)) != 0; } @@ -2055,24 +2055,24 @@ static void write_field_info(HUFF_COUNTS *counts, uint fields, uint trees) DBUG_PRINT("info", (" ")); if (verbose >= 2) { - VOID(printf("\n")); - VOID(printf("column types:\n")); - VOID(printf("FIELD_NORMAL 0\n")); - VOID(printf("FIELD_SKIP_ENDSPACE 1\n")); - VOID(printf("FIELD_SKIP_PRESPACE 2\n")); - VOID(printf("FIELD_SKIP_ZERO 3\n")); - VOID(printf("FIELD_BLOB 4\n")); - VOID(printf("FIELD_CONSTANT 5\n")); - VOID(printf("FIELD_INTERVALL 6\n")); - VOID(printf("FIELD_ZERO 7\n")); - VOID(printf("FIELD_VARCHAR 8\n")); - VOID(printf("FIELD_CHECK 9\n")); - VOID(printf("\n")); - VOID(printf("pack type as a set of flags:\n")); - VOID(printf("PACK_TYPE_SELECTED 1\n")); - VOID(printf("PACK_TYPE_SPACE_FIELDS 2\n")); - VOID(printf("PACK_TYPE_ZERO_FILL 4\n")); - VOID(printf("\n")); + printf("\n"); + printf("column types:\n"); + printf("FIELD_NORMAL 0\n"); + printf("FIELD_SKIP_ENDSPACE 1\n"); + printf("FIELD_SKIP_PRESPACE 2\n"); + printf("FIELD_SKIP_ZERO 3\n"); + printf("FIELD_BLOB 4\n"); + printf("FIELD_CONSTANT 5\n"); + printf("FIELD_INTERVALL 6\n"); + printf("FIELD_ZERO 7\n"); + printf("FIELD_VARCHAR 8\n"); + printf("FIELD_CHECK 9\n"); + printf("\n"); + printf("pack type as a set of flags:\n"); + printf("PACK_TYPE_SELECTED 1\n"); + printf("PACK_TYPE_SPACE_FIELDS 2\n"); + printf("PACK_TYPE_ZERO_FILL 4\n"); + printf("\n"); } for (i=0 ; i++ < fields ; counts++) { @@ -2089,10 +2089,10 @@ static void write_field_info(HUFF_COUNTS *counts, uint fields, uint trees) counts->max_zero_fill, counts->length_bits, counts->tree->tree_number, counts->field_length)); if (verbose >= 2) - VOID(printf("column: %3u type: %2u pack: %2u zero: %4u lbits: %2u " + printf("column: %3u type: %2u pack: %2u zero: %4u lbits: %2u " "tree: %2u length: %4u\n", i , counts->field_type, counts->pack_type, counts->max_zero_fill, counts->length_bits, - counts->tree->tree_number, counts->field_length)); + counts->tree->tree_number, counts->field_length); } flush_bits(); return; @@ -2127,7 +2127,7 @@ static my_off_t write_huff_tree(HUFF_TREE *huff_tree, uint trees) DBUG_PRINT("info", (" ")); if (verbose >= 2) - VOID(printf("\n")); + printf("\n"); tree_no= 0; intervall_length=0; for (elements=0; trees-- ; huff_tree++) @@ -2138,7 +2138,7 @@ static my_off_t write_huff_tree(HUFF_TREE *huff_tree, uint trees) tree_no++; DBUG_PRINT("info", (" ")); if (verbose >= 3) - VOID(printf("\n")); + printf("\n"); /* Count the total number of elements (byte codes or column values). */ elements+=huff_tree->elements; huff_tree->max_offset=2; @@ -2157,8 +2157,8 @@ static my_off_t write_huff_tree(HUFF_TREE *huff_tree, uint trees) */ if (huff_tree->max_offset >= IS_OFFSET) { /* This should be impossible */ - VOID(fprintf(stderr, "Tree offset got too big: %d, aborted\n", - huff_tree->max_offset)); + (void) fprintf(stderr, "Tree offset got too big: %d, aborted\n", + huff_tree->max_offset); my_afree((uchar*) packed_tree); return 0; } @@ -2197,19 +2197,19 @@ static my_off_t write_huff_tree(HUFF_TREE *huff_tree, uint trees) "bufflen" : "min_chr", huff_tree->counts->tree_buff ? int_length : huff_tree->min_chr, huff_tree->height)); if (verbose >= 2) - VOID(printf("tree: %2u elements: %4u char_bits: %2u offset_bits: %2u " + printf("tree: %2u elements: %4u char_bits: %2u offset_bits: %2u " "%s: %5u codelen: %2u\n", tree_no, huff_tree->elements, huff_tree->char_bits, huff_tree->offset_bits, huff_tree->counts->tree_buff ? "bufflen" : "min_chr", huff_tree->counts->tree_buff ? int_length : - huff_tree->min_chr, huff_tree->height)); + huff_tree->min_chr, huff_tree->height); /* Check that the code tree length matches the element count. */ length=(uint) (offset-packed_tree); if (length != huff_tree->elements*2-2) { - VOID(fprintf(stderr, "error: Huff-tree-length: %d != calc_length: %d\n", - length, huff_tree->elements * 2 - 2)); + (void) fprintf(stderr, "error: Huff-tree-length: %d != calc_length: %d\n", + length, huff_tree->elements * 2 - 2); errors++; break; } @@ -2226,10 +2226,10 @@ static my_off_t write_huff_tree(HUFF_TREE *huff_tree, uint trees) " -> " : "", (packed_tree[i] & IS_OFFSET) ? packed_tree[i] - IS_OFFSET + i : packed_tree[i])); if (verbose >= 3) - VOID(printf("tree[0x%04x]: %s0x%04x\n", + printf("tree[0x%04x]: %s0x%04x\n", i, (packed_tree[i] & IS_OFFSET) ? " -> " : "", (packed_tree[i] & IS_OFFSET) ? - packed_tree[i] - IS_OFFSET + i : packed_tree[i])); + packed_tree[i] - IS_OFFSET + i : packed_tree[i]); } flush_bits(); @@ -2251,9 +2251,9 @@ static my_off_t write_huff_tree(HUFF_TREE *huff_tree, uint trees) bindigits(huff_tree->code[i], huff_tree->code_len[i]))); if (verbose >= 3) - VOID(printf("code[0x%04x]: 0x%s bits: %2u bin: %s\n", i, + printf("code[0x%04x]: 0x%s bits: %2u bin: %s\n", i, hexdigits(huff_tree->code[i]), huff_tree->code_len[i], - bindigits(huff_tree->code[i], huff_tree->code_len[i]))); + bindigits(huff_tree->code[i], huff_tree->code_len[i])); /* Check that the encode table decodes correctly. */ code= 0; @@ -2266,9 +2266,9 @@ static my_off_t write_huff_tree(HUFF_TREE *huff_tree, uint trees) { if (! len) { - VOID(fflush(stdout)); - VOID(fprintf(stderr, "error: code 0x%s with %u bits not found\n", - hexdigits(huff_tree->code[i]), huff_tree->code_len[i])); + (void) fflush(stdout); + (void) fprintf(stderr, "error: code 0x%s with %u bits not found\n", + hexdigits(huff_tree->code[i]), huff_tree->code_len[i]); errors++; break; } @@ -2277,18 +2277,18 @@ static my_off_t write_huff_tree(HUFF_TREE *huff_tree, uint trees) bits++; if (bits > 8 * sizeof(code)) { - VOID(fflush(stdout)); - VOID(fprintf(stderr, "error: Huffman code too long: %u/%u\n", - bits, (uint) (8 * sizeof(code)))); + (void) fflush(stdout); + (void) fprintf(stderr, "error: Huffman code too long: %u/%u\n", + bits, (uint) (8 * sizeof(code))); errors++; break; } idx+= (uint) code & 1; if (idx >= length) { - VOID(fflush(stdout)); - VOID(fprintf(stderr, "error: illegal tree offset: %u/%u\n", - idx, length)); + (void) fflush(stdout); + (void) fprintf(stderr, "error: illegal tree offset: %u/%u\n", + idx, length); errors++; break; } @@ -2303,9 +2303,9 @@ static my_off_t write_huff_tree(HUFF_TREE *huff_tree, uint trees) DBUG_EXECUTE_IF("forcechkerr4", packed_tree[idx]++;); if (packed_tree[idx] != i) { - VOID(fflush(stdout)); - VOID(fprintf(stderr, "error: decoded value 0x%04x should be: 0x%04x\n", - packed_tree[idx], i)); + (void) fflush(stdout); + (void) fprintf(stderr, "error: decoded value 0x%04x should be: 0x%04x\n", + packed_tree[idx], i); errors++; break; } @@ -2322,19 +2322,19 @@ static my_off_t write_huff_tree(HUFF_TREE *huff_tree, uint trees) DBUG_PRINT("info", ("column_values[0x%04x]: 0x%02x", i, (uchar) huff_tree->counts->tree_buff[i])); if (verbose >= 3) - VOID(printf("column_values[0x%04x]: 0x%02x\n", - i, (uchar) huff_tree->counts->tree_buff[i])); + printf("column_values[0x%04x]: 0x%02x\n", + i, (uchar) huff_tree->counts->tree_buff[i]); } } flush_bits(); } DBUG_PRINT("info", (" ")); if (verbose >= 2) - VOID(printf("\n")); + printf("\n"); my_afree((uchar*) packed_tree); if (errors) { - VOID(fprintf(stderr, "Error: Generated decode trees are corrupt. Stop.\n")); + (void) fprintf(stderr, "Error: Generated decode trees are corrupt. Stop.\n"); return 0; } return elements; @@ -2756,8 +2756,8 @@ static int compress_isam_file(PACK_MRG_INFO *mrg, HUFF_COUNTS *huff_counts) record_count++; if (write_loop && record_count % WRITE_COUNT == 0) { - VOID(printf("%lu\r", (ulong) record_count)); - VOID(fflush(stdout)); + printf("%lu\r", (ulong) record_count); + (void) fflush(stdout); } } else if (error != HA_ERR_RECORD_DELETED) @@ -2767,11 +2767,11 @@ static int compress_isam_file(PACK_MRG_INFO *mrg, HUFF_COUNTS *huff_counts) error=0; else { - VOID(fprintf(stderr, "%s: Got error %d reading records\n", - my_progname, error)); + (void) fprintf(stderr, "%s: Got error %d reading records\n", + my_progname, error); } if (verbose >= 2) - VOID(printf("wrote %s records.\n", llstr((longlong) record_count, llbuf))); + printf("wrote %s records.\n", llstr((longlong) record_count, llbuf)); my_afree((uchar*) record); mrg->ref_length=max_pack_length; @@ -2901,7 +2901,7 @@ static void write_bits(register ulonglong value, register uint bits) if (bits != 8 * sizeof(value)) value&= (((ulonglong) 1) << bits) - 1; if (file_buffer.pos >= file_buffer.end) - VOID(flush_buffer(~ (ulong) 0)); + (void) flush_buffer(~ (ulong) 0); file_buffer.bits=(int) (BITS_SAVED - bits); file_buffer.bitbucket= value << (BITS_SAVED - bits); } @@ -2924,7 +2924,7 @@ static void flush_bits(void) *file_buffer.pos++= (uchar) (bit_buffer >> bits); } if (file_buffer.pos >= file_buffer.end) - VOID(flush_buffer(~ (ulong) 0)); + (void) flush_buffer(~ (ulong) 0); file_buffer.bits= BITS_SAVED; file_buffer.bitbucket= 0; } @@ -2974,7 +2974,7 @@ static int save_state(MI_INFO *isam_file,PACK_MRG_INFO *mrg,my_off_t new_length, share->changed=1; /* Force write of header */ share->state.open_count=0; share->global_changed=0; - VOID(my_chsize(share->kfile, share->base.keystart, 0, MYF(0))); + (void) my_chsize(share->kfile, share->base.keystart, 0, MYF(0)); if (share->base.keys) isamchk_neaded=1; DBUG_RETURN(mi_state_info_write(share->kfile,&share->state,1+2)); diff --git a/storage/myisam/sort.c b/storage/myisam/sort.c index b450d27de66..670b5f4a30f 100644 --- a/storage/myisam/sort.c +++ b/storage/myisam/sort.c @@ -970,7 +970,7 @@ merge_buffers(MI_SORT_PARAM *info, uint keys, IO_CACHE *from_file, uchar *base=buffpek->base; uint max_keys=buffpek->max_keys; - VOID(queue_remove(&queue,0)); + (void) queue_remove(&queue,0); /* Put room used by buffer to use in other buffer */ for (refpek= (BUFFPEK**) &queue_top(&queue); diff --git a/storage/myisammrg/myrg_close.c b/storage/myisammrg/myrg_close.c index 97216ed47fe..6f641019a73 100644 --- a/storage/myisammrg/myrg_close.c +++ b/storage/myisammrg/myrg_close.c @@ -58,7 +58,7 @@ int myrg_close(MYRG_INFO *info) pthread_mutex_lock(&THR_LOCK_open); myrg_open_list=list_delete(myrg_open_list,&info->open_list); pthread_mutex_unlock(&THR_LOCK_open); - VOID(pthread_mutex_destroy(&info->mutex)); + pthread_mutex_destroy(&info->mutex); my_free((uchar*) info,MYF(0)); if (error) { diff --git a/storage/myisammrg/myrg_create.c b/storage/myisammrg/myrg_create.c index eaed470daec..b030340e743 100644 --- a/storage/myisammrg/myrg_create.c +++ b/storage/myisammrg/myrg_create.c @@ -66,7 +66,7 @@ err: save_errno=my_errno ? my_errno : -1; switch (errpos) { case 1: - VOID(my_close(file,MYF(0))); + (void) my_close(file,MYF(0)); } DBUG_RETURN(my_errno=save_errno); } /* myrg_create */ diff --git a/storage/myisammrg/myrg_open.c b/storage/myisammrg/myrg_open.c index 7b310dc2eed..d6d1a68ca20 100644 --- a/storage/myisammrg/myrg_open.c +++ b/storage/myisammrg/myrg_open.c @@ -87,9 +87,9 @@ MYRG_INFO *myrg_open(const char *name, int mode, int handle_locking) if (!has_path(buff)) { - VOID(strmake(name_buff+dir_length,buff, - sizeof(name_buff)-1-dir_length)); - VOID(cleanup_dirname(buff,name_buff)); + (void) strmake(name_buff+dir_length,buff, + sizeof(name_buff)-1-dir_length); + (void) cleanup_dirname(buff,name_buff); } else fn_format(buff, buff, "", "", 0); @@ -167,9 +167,9 @@ MYRG_INFO *myrg_open(const char *name, int mode, int handle_locking) m_info->last_used_table=m_info->open_tables; m_info->children_attached= TRUE; - VOID(my_close(fd,MYF(0))); + (void) my_close(fd,MYF(0)); end_io_cache(&file); - VOID(pthread_mutex_init(&m_info->mutex, MY_MUTEX_INIT_FAST)); + pthread_mutex_init(&m_info->mutex, MY_MUTEX_INIT_FAST); m_info->open_list.data=(void*) m_info; pthread_mutex_lock(&THR_LOCK_open); myrg_open_list=list_add(myrg_open_list,&m_info->open_list); @@ -190,7 +190,7 @@ err: end_io_cache(&file); /* Fall through */ case 1: - VOID(my_close(fd,MYF(0))); + (void) my_close(fd,MYF(0)); } my_errno=save_errno; DBUG_RETURN (NULL); @@ -313,9 +313,9 @@ MYRG_INFO *myrg_parent_open(const char *parent_name, if (!has_path(child_name_buff)) { - VOID(strmake(parent_name_buff + dir_length, child_name_buff, - sizeof(parent_name_buff) - 1 - dir_length)); - VOID(cleanup_dirname(child_name_buff, parent_name_buff)); + (void) strmake(parent_name_buff + dir_length, child_name_buff, + sizeof(parent_name_buff) - 1 - dir_length); + (void) cleanup_dirname(child_name_buff, parent_name_buff); } else fn_format(child_name_buff, child_name_buff, "", "", 0); @@ -327,8 +327,8 @@ MYRG_INFO *myrg_parent_open(const char *parent_name, } end_io_cache(&file_cache); - VOID(my_close(fd, MYF(0))); - VOID(pthread_mutex_init(&m_info->mutex, MY_MUTEX_INIT_FAST)); + (void) my_close(fd, MYF(0)); + pthread_mutex_init(&m_info->mutex, MY_MUTEX_INIT_FAST); m_info->open_list.data= (void*) m_info; pthread_mutex_lock(&THR_LOCK_open); @@ -348,7 +348,7 @@ MYRG_INFO *myrg_parent_open(const char *parent_name, end_io_cache(&file_cache); /* Fall through */ case 1: - VOID(my_close(fd, MYF(0))); + (void) my_close(fd, MYF(0)); } my_errno= save_errno; DBUG_RETURN (NULL); diff --git a/strings/str_test.c b/strings/str_test.c index 3ddfca39419..e4358196f27 100644 --- a/strings/str_test.c +++ b/strings/str_test.c @@ -265,13 +265,13 @@ extern void dummy_functions(void); void dummy_functions(void) { - VOID(memchr(from,'a',5)); - VOID(memcmp(from,to,5)); - VOID(memcpy(from,to,5)); - VOID(memset(from,' ',5)); - VOID(strcmp(from,to)); - VOID(strcpy(from,to)); - VOID(strstr(from,to)); - VOID(strrchr(from,'a')); + (void) memchr(from,'a',5); + (void) memcmp(from,to,5); + (void) memcpy(from,to,5); + (void) memset(from,' ',5); + (void) strcmp(from,to); + (void) strcpy(from,to); + (void) strstr(from,to); + (void) strrchr(from,'a'); return; } diff --git a/tests/thread_test.c b/tests/thread_test.c index 8e1c58ebbec..760b72fc5d1 100644 --- a/tests/thread_test.c +++ b/tests/thread_test.c @@ -77,7 +77,7 @@ end: mysql_close(mysql); pthread_mutex_lock(&LOCK_thread_count); thread_count--; - VOID(pthread_cond_signal(&COND_thread_count)); /* Tell main we are ready */ + pthread_cond_signal(&COND_thread_count); /* Tell main we are ready */ pthread_mutex_unlock(&LOCK_thread_count); pthread_exit(0); return 0; From b4e9cc6988d04b10736056bb9958b8166715a567 Mon Sep 17 00:00:00 2001 From: Konstantin Osipov Date: Tue, 24 Nov 2009 21:55:16 +0300 Subject: [PATCH 22/23] Backport of: ------------------------------------------------------------ revno: 3559 committer: Davi Arnaut branch nick: mysql-pe timestamp: Fri 2009-08-28 15:23:16 -0300 message: Break down a large and obnoxious "if" statement. Multiple "if" statements makes it easy to understand and follow the code (specially in a debugger). --- sql/sql_base.cc | 38 ++++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/sql/sql_base.cc b/sql/sql_base.cc index 52e203f1130..8f31ef6999a 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -1680,20 +1680,42 @@ TABLE_LIST* unique_table(THD *thd, TABLE_LIST *table, TABLE_LIST *table_list, DBUG_PRINT("info", ("real table: %s.%s", d_name, t_name)); for (;;) { - if (((! (res= find_table_in_global_list(table_list, d_name, t_name))) && - (! (res= mysql_lock_have_duplicate(thd, table, table_list)))) || - ((!res->table || res->table != table->table) && - (!check_alias || !(lower_case_table_names ? - my_strcasecmp(files_charset_info, t_alias, res->alias) : - strcmp(t_alias, res->alias))) && - res->select_lex && !res->select_lex->exclude_from_table_unique_test && - !res->prelocking_placeholder)) + /* + Table is unique if it is present only once in the global list + of tables and once in the list of table locks. + */ + if (! (res= find_table_in_global_list(table_list, d_name, t_name)) && + ! (res= mysql_lock_have_duplicate(thd, table, table_list))) break; + + /* Skip if same underlying table. */ + if (res->table && (res->table == table->table)) + goto next; + + /* Skip if table alias does not match. */ + if (check_alias) + { + if (lower_case_table_names ? + my_strcasecmp(files_charset_info, t_alias, res->alias) : + strcmp(t_alias, res->alias)) + goto next; + } + + /* + Skip if marked to be excluded (could be a derived table) or if + entry is a prelocking placeholder. + */ + if (res->select_lex && + !res->select_lex->exclude_from_table_unique_test && + !res->prelocking_placeholder) + break; + /* If we found entry of this table or table of SELECT which already processed in derived table or top select of multi-update/multi-delete (exclude_from_table_unique_test) or prelocking placeholder. */ +next: table_list= res->next_global; DBUG_PRINT("info", ("found same copy of table or table which we should skip")); From 6e01be7552aa5c5fb854d30d5d8cb61c2729b292 Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Tue, 24 Nov 2009 16:36:31 -0700 Subject: [PATCH 23/23] WL#2373 Use cycle counter for timing --- configure.in | 62 ++ include/Makefile.am | 1 + include/my_rdtsc.h | 129 +++++ mysys/CMakeLists.txt | 5 +- mysys/Makefile.am | 10 +- mysys/my_rdtsc.c | 1004 +++++++++++++++++++++++++++++++++ mysys/my_timer_cycles.il | 38 ++ unittest/mysys/CMakeLists.txt | 35 ++ unittest/mysys/Makefile.am | 5 +- unittest/mysys/my_rdtsc-t.c | 229 ++++++++ 10 files changed, 1510 insertions(+), 8 deletions(-) create mode 100644 include/my_rdtsc.h create mode 100644 mysys/my_rdtsc.c create mode 100644 mysys/my_timer_cycles.il create mode 100644 unittest/mysys/CMakeLists.txt create mode 100644 unittest/mysys/my_rdtsc-t.c diff --git a/configure.in b/configure.in index db86eeaa779..b3dc1314f00 100644 --- a/configure.in +++ b/configure.in @@ -1,6 +1,21 @@ dnl -*- ksh -*- dnl Process this file with autoconf to produce a configure script. +# 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 + AC_PREREQ(2.52)dnl Minimum Autoconf version required. AC_INIT(sql/mysqld.cc) @@ -2916,7 +2931,54 @@ case $SYSTEM_TYPE in esac AC_SUBST(MAKE_BINARY_DISTRIBUTION_OPTIONS) +#-------------------------------------------------------------------- +# Support for WL#2373 (Use cycle counter for timing) +#-------------------------------------------------------------------- + +AC_CHECK_HEADERS(time.h) +AC_CHECK_HEADERS(sys/time.h) +AC_CHECK_HEADERS(sys/times.h) +AC_CHECK_HEADERS(asm/msr.h) +#msr.h has rdtscll() + +AC_CHECK_HEADERS(ia64intrin.h) + +AC_CHECK_FUNCS(times) +AC_CHECK_FUNCS(gettimeofday) +AC_CHECK_FUNCS(read_real_time) +# This should work on AIX. + +AC_CHECK_FUNCS(ftime) +# This is still a normal call for milliseconds. + +AC_CHECK_FUNCS(time) +# We can use time() on Macintosh if there is no ftime(). + +AC_CHECK_FUNCS(rdtscll) +# I doubt that we'll ever reach the check for this. + +# When compiling with Sun Studio C / C++ we need to include +# my_timer_cycles.il, an "inline templates" separate file, +# on the command line. It has assembly code, "rd %tick" for +# SPARC or "rdtsc" for x86. +RDTSC_SPARC_ASSEMBLY="" +case $CC_VERSION in + *Sun*C*) + RDTSC_SPARC_ASSEMBLY="my_timer_cycles.il" + ;; +esac +case $CXX_VERSION in + *Sun*C++*) + RDTSC_SPARC_ASSEMBLY="my_timer_cycles.il" + ;; +esac + +AC_SUBST([RDTSC_SPARC_ASSEMBLY]) + +#-------------------------------------------------------------------- # Output results +#-------------------------------------------------------------------- + if test -d "$srcdir/pstack" ; then AC_CONFIG_FILES(pstack/Makefile pstack/aout/Makefile) fi diff --git a/include/Makefile.am b/include/Makefile.am index 83a22f1beec..fff162474a5 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -38,6 +38,7 @@ noinst_HEADERS = config-win.h config-netware.h lf.h my_bit.h \ my_aes.h my_tree.h my_trie.h hash.h thr_alarm.h \ thr_lock.h t_ctype.h violite.h my_md5.h base64.h \ my_handler.h my_time.h service_versions.h \ + my_rdtsc.h \ my_vle.h my_user.h my_atomic.h atomic/nolock.h \ atomic/rwlock.h atomic/x86-gcc.h atomic/generic-msvc.h \ atomic/gcc_builtins.h my_libwrap.h my_stacktrace.h \ 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/mysys/CMakeLists.txt b/mysys/CMakeLists.txt index 757e37aa0a9..ae9406450ed 100755 --- a/mysys/CMakeLists.txt +++ b/mysys/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (C) 2006 MySQL AB +# 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 @@ -41,7 +41,8 @@ SET(MYSYS_SOURCES array.c charset-def.c charset.c checksum.c default.c default_ rijndael.c safemalloc.c sha1.c string.c thr_alarm.c thr_lock.c thr_mutex.c thr_rwlock.c tree.c typelib.c my_vle.c base64.c my_memmem.c my_getpagesize.c lf_alloc-pin.c lf_dynarray.c lf_hash.c - my_atomic.c my_getncpus.c) + my_atomic.c my_getncpus.c + my_rdtsc.c) IF(NOT SOURCE_SUBLIBS) ADD_LIBRARY(mysys ${MYSYS_SOURCES}) diff --git a/mysys/Makefile.am b/mysys/Makefile.am index 3b53fc1dd59..476b63d3ad5 100644 --- a/mysys/Makefile.am +++ b/mysys/Makefile.am @@ -16,7 +16,8 @@ MYSQLDATAdir = $(localstatedir) MYSQLSHAREdir = $(pkgdatadir) MYSQLBASEdir= $(prefix) -INCLUDES = @ZLIB_INCLUDES@ -I$(top_builddir)/include \ +INCLUDES = @ZLIB_INCLUDES@ @RDTSC_SPARC_ASSEMBLY@ \ + -I$(top_builddir)/include \ -I$(top_srcdir)/include -I$(srcdir) pkglib_LIBRARIES = libmysys.a LDADD = libmysys.a $(top_builddir)/strings/libmystrings.a $(top_builddir)/dbug/libdbug.a @@ -53,7 +54,8 @@ libmysys_a_SOURCES = my_init.c my_getwd.c mf_getdate.c my_mmap.c \ my_gethostbyname.c rijndael.c my_aes.c sha1.c \ my_handler.c my_netware.c my_largepage.c \ my_memmem.c stacktrace.c \ - my_windac.c my_access.c base64.c my_libwrap.c + my_windac.c my_access.c base64.c my_libwrap.c \ + my_rdtsc.c if NEED_THREAD # mf_keycache is used only in the server, so it is safe to leave the file @@ -65,7 +67,9 @@ endif EXTRA_DIST = thr_alarm.c thr_lock.c my_pthread.c my_thr_init.c \ thr_mutex.c thr_rwlock.c \ CMakeLists.txt mf_soundex.c \ - my_conio.c my_wincond.c my_winthread.c my_winerr.c my_winfile.c + my_conio.c my_wincond.c my_winthread.c my_winerr.c \ + my_winfile.c \ + my_timer_cycles.il libmysys_a_LIBADD = @THREAD_LOBJECTS@ # test_dir_DEPENDENCIES= $(LIBRARIES) # testhash_DEPENDENCIES= $(LIBRARIES) diff --git a/mysys/my_rdtsc.c b/mysys/my_rdtsc.c new file mode 100644 index 00000000000..4227498b92c --- /dev/null +++ b/mysys/my_rdtsc.c @@ -0,0 +1,1004 @@ +/* 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 + + Functions: + + my_timer_cycles ulonglong cycles + my_timer_nanoseconds ulonglong nanoseconds + my_timer_microseconds ulonglong "microseconds" + my_timer_milliseconds ulonglong milliseconds + my_timer_ticks ulonglong ticks + my_timer_init initialization / test + + We'll call the first 5 functions (the ones that return + a ulonglong) "my_timer_xxx" functions. + Each my_timer_xxx function returns a 64-bit timing value + since an arbitrary 'epoch' start. Since the only purpose + is to determine elapsed times, wall-clock time-of-day + is not known and not relevant. + + The my_timer_init function is necessary for initializing. + It returns information (underlying routine name, + frequency, resolution, overhead) about all my_timer_xxx + functions. A program should call my_timer_init once, + use the information to decide what my_timer_xxx function + to use, and subsequently call that function by function + pointer. + + A typical use would be: + my_timer_init() ... once, at program start + ... + time1= my_timer_xxx() ... time before start + [code that's timed] + time2= my_timer_xxx() ... time after end + elapsed_time= (time2 - time1) - overhead +*/ + +#include "my_global.h" +#include "my_rdtsc.h" + +#if defined(_WIN32) +#include +#include "windows.h" +#else +#include +#endif + +#if !defined(_WIN32) +#if TIME_WITH_SYS_TIME +#include +#include /* for clock_gettime */ +#else +#if HAVE_SYS_TIME_H +#include +#elif defined(HAVE_TIME_H) +#include +#endif +#endif +#endif + +#if defined(HAVE_ASM_MSR_H) && defined(HAVE_RDTSCLL) +#include /* for rdtscll */ +#endif + +#if defined(HAVE_SYS_TIMEB_H) && defined(HAVE_FTIME) +#include /* for ftime */ +#endif + +#if defined(HAVE_SYS_TIMES_H) && defined(HAVE_TIMES) +#include /* for times */ +#endif + +#if defined(__NETWARE__) +#include /* for NXGetTime */ +#endif + +#if defined(__INTEL_COMPILER) && defined(__ia64__) && defined(HAVE_IA64INTRIN_H) +#include /* for __GetReg */ +#endif + +#if defined(__APPLE__) && defined(__MACH__) +#include +#endif + +#if defined(__SUNPRO_CC) && defined(__sparcv9) && defined(_LP64) && !defined(__SunOS_5_7) +extern "C" ulonglong my_timer_cycles_il_sparc64(); +#elif defined(__SUNPRO_CC) && defined(__sparcv8plus) && defined(_ILP32) && !defined(__SunOS_5_7) +extern "C" ulonglong my_timer_cycles_il_sparc32(); +#elif defined(__SUNPRO_CC) && defined(__i386) && defined(_ILP32) +extern "C" ulonglong my_timer_cycles_il_i386(); +#elif defined(__SUNPRO_CC) && defined(__x86_64) && defined(_LP64) +extern "C" ulonglong my_timer_cycles_il_x86_64(); +#elif defined(__SUNPRO_C) && defined(__sparcv9) && defined(_LP64) && !defined(__SunOS_5_7) +ulonglong my_timer_cycles_il_sparc64(); +#elif defined(__SUNPRO_C) && defined(__sparcv8plus) && defined(_ILP32) && !defined(__SunOS_5_7) +ulonglong my_timer_cycles_il_sparc32(); +#elif defined(__SUNPRO_C) && defined(__i386) && defined(_ILP32) +ulonglong my_timer_cycles_il_i386(); +#elif defined(__SUNPRO_C) && defined(__x86_64) && defined(_LP64) +ulonglong my_timer_cycles_il_x86_64(); +#endif + +#if defined(__INTEL_COMPILER) +/* + icc warning #1011 is: + missing return statement at end of non-void function +*/ +#pragma warning (disable:1011) +#endif + +/* + For cycles, we depend on RDTSC for x86 platforms, + or on time buffer (which is not really a cycle count + but a separate counter with less than nanosecond + resolution) for most PowerPC platforms, or on + gethrtime which is okay for hpux and solaris, or on + clock_gettime(CLOCK_SGI_CYCLE) for Irix platforms, + or on read_real_time for aix platforms. There is + nothing for Alpha platforms, they would be tricky. +*/ + +ulonglong my_timer_cycles(void) +{ +#if defined(__GNUC__) && defined(__i386__) + /* This works much better if compiled with "gcc -O3". */ + ulonglong result; + __asm__ __volatile__ ("rdtsc" : "=A" (result)); + return result; +#elif defined(__SUNPRO_C) && defined(__i386) + __asm("rdtsc"); +#elif defined(__GNUC__) && defined(__x86_64__) + ulonglong result; + __asm__ __volatile__ ("rdtsc\n\t" \ + "shlq $32,%%rdx\n\t" \ + "orq %%rdx,%%rax" + : "=a" (result) :: "%edx"); + return result; +#elif defined(HAVE_ASM_MSR_H) && defined(HAVE_RDTSCLL) + { + ulonglong result; + rdtscll(result); + return result; + } +#elif defined(_WIN32) && defined(_M_IX86) + __asm {rdtsc}; +#elif defined(_WIN64) && defined(_M_X64) + /* For 64-bit Windows: unsigned __int64 __rdtsc(); */ + return __rdtsc(); +#elif defined(__INTEL_COMPILER) && defined(__ia64__) && defined(HAVE_IA64INTRIN_H) + return (ulonglong) __getReg(_IA64_REG_AR_ITC); /* (3116) */ +#elif defined(__GNUC__) && defined(__ia64__) + { + ulonglong result; + __asm __volatile__ ("mov %0=ar.itc" : "=r" (result)); + return result; + } +#elif defined(__GNUC__) && (defined(__powerpc__) || defined(__POWERPC__) || (defined(_POWER) && defined(_AIX52))) && (defined(__64BIT__) || defined(_ARCH_PPC64)) + { + ulonglong result; + __asm __volatile__ ("mftb %0" : "=r" (result)); + return result; + } +#elif defined(__GNUC__) && (defined(__powerpc__) || defined(__POWERPC__) || (defined(_POWER) && defined(_AIX52))) && (!defined(__64BIT__) && !defined(_ARCH_PPC64)) + { + /* + mftbu means "move from time-buffer-upper to result". + The loop is saying: x1=upper, x2=lower, x3=upper, + if x1!=x3 there was an overflow so repeat. + */ + unsigned int x1, x2, x3; + ulonglong result; + for (;;) + { + __asm __volatile__ ( "mftbu %0" : "=r"(x1) ); + __asm __volatile__ ( "mftb %0" : "=r"(x2) ); + __asm __volatile__ ( "mftbu %0" : "=r"(x3) ); + if (x1 == x3) break; + } + result = x1; + return ( result << 32 ) | x2; + } +#elif (defined(__SUNPRO_CC) || defined(__SUNPRO_C)) && defined(__sparcv9) && defined(_LP64) && !defined(__SunOS_5_7) + return (my_timer_cycles_il_sparc64()); +#elif (defined(__SUNPRO_CC) || defined(__SUNPRO_C)) && defined(__sparcv8plus) && defined(_ILP32) && !defined(__SunOS_5_7) + return (my_timer_cycles_il_sparc32()); +#elif (defined(__SUNPRO_CC) || defined(__SUNPRO_C)) && defined(__i386) && defined(_ILP32) + /* This is probably redundant for __SUNPRO_C. */ + return (my_timer_cycles_il_i386()); +#elif (defined(__SUNPRO_CC) || defined(__SUNPRO_C)) && defined(__x86_64) && defined(_LP64) + return (my_timer_cycles_il_x86_64()); +#elif defined(__GNUC__) && defined(__sparcv9) && defined(_LP64) && (__GNUC__>2) + { + ulonglong result; + __asm __volatile__ ("rd %%tick,%0" : "=r" (result)); + return result; + } +#elif defined(__GNUC__) && defined(__sparc__) && !defined(_LP64) && (__GNUC__>2) + { + union { + ulonglong wholeresult; + struct { + ulong high; + ulong low; + } splitresult; + } result; + __asm __volatile__ ("rd %%tick,%1; srlx %1,32,%0" : "=r" (result.splitresult.high), "=r" (result.splitresult.low)); + return result.wholeresult; + } +#elif defined(__sgi) && defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_SGI_CYCLE) + { + struct timespec tp; + clock_gettime(CLOCK_SGI_CYCLE, &tp); + return (ulonglong) tp.tv_sec * 1000000000 + (ulonglong) tp.tv_nsec; + } +#elif defined(HAVE_SYS_TIMES_H) && defined(HAVE_GETHRTIME) + /* gethrtime may appear as either cycle or nanosecond counter */ + return (ulonglong) gethrtime(); +#else + return 0; +#endif +} + +#if defined(__INTEL_COMPILER) +/* re-enable warning#1011 which was only for my_timer_cycles() */ +/* There may be an icc bug which means we must leave disabled. */ +#pragma warning (default:1011) +#endif + +/* + For nanoseconds, most platforms have nothing available that + (a) doesn't require bringing in a 40-kb librt.so library + (b) really has nanosecond resolution. +*/ + +ulonglong my_timer_nanoseconds(void) +{ +#if defined(HAVE_READ_REAL_TIME) + { + timebasestruct_t tr; + read_real_time(&tr, TIMEBASE_SZ); + return (ulonglong) tr.tb_high * 1000000000 + (ulonglong) tr.tb_low; + } +#elif defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_REALTIME) + { + struct timespec tp; + clock_gettime(CLOCK_REALTIME, &tp); + return (ulonglong) tp.tv_sec * 1000000000 + (ulonglong) tp.tv_nsec; + } +#elif defined(HAVE_SYS_TIMES_H) && defined(HAVE_GETHRTIME) + /* SunOS 5.10+, Solaris, HP-UX: hrtime_t gethrtime(void) */ + return (ulonglong) gethrtime(); +#elif defined(__NETWARE__) + { + NXTime_t tm; + NXGetTime(NX_SINCE_1970, NX_NSECONDS, &tm); + return (ulonglong) tm; + } +#elif defined(__APPLE__) && defined(__MACH__) + { + ulonglong tm; + static mach_timebase_info_data_t timebase_info= {0,0}; + if (timebase_info.denom == 0) + (void) mach_timebase_info(&timebase_info); + tm= mach_absolute_time(); + return (tm * timebase_info.numer) / timebase_info.denom; + } +#else + return 0; +#endif +} + +/* + For microseconds, gettimeofday() is available on + almost all platforms. On Windows we use + QueryPerformanceCounter which will usually tick over + 3.5 million times per second, and we don't throw + away the extra precision. (On Windows Server 2003 + the frequency is same as the cycle frequency.) +*/ + +ulonglong my_timer_microseconds(void) +{ +#if defined(HAVE_GETTIMEOFDAY) + { + static ulonglong last_value= 0; + struct timeval tv; + if (gettimeofday(&tv, NULL) == 0) + last_value= (ulonglong) tv.tv_sec * 1000000 + (ulonglong) tv.tv_usec; + else + { + /* + There are reports that gettimeofday(2) can have intermittent failures + on some platform, see for example Bug#36819. + We are not trying again or looping, just returning the best value possible + under the circumstances ... + */ + last_value++; + } + return last_value; + } +#elif defined(_WIN32) + { + /* QueryPerformanceCounter usually works with about 1/3 microsecond. */ + LARGE_INTEGER t_cnt; + + QueryPerformanceCounter(&t_cnt); + return (ulonglong) t_cnt.QuadPart; + } +#elif defined(__NETWARE__) + { + NXTime_t tm; + NXGetTime(NX_SINCE_1970, NX_USECONDS, &tm); + return (ulonglong) tm; + } +#else + return 0; +#endif +} + +/* + For milliseconds, we use ftime() if it's supported + or time()*1000 if it's not. With modern versions of + Windows and with HP Itanium, resolution is 10-15 + milliseconds. +*/ + +ulonglong my_timer_milliseconds(void) +{ +#if defined(HAVE_SYS_TIMEB_H) && defined(HAVE_FTIME) + /* ftime() is obsolete but maybe the platform is old */ + struct timeb ft; + ftime(&ft); + return (ulonglong)ft.time * 1000 + (ulonglong)ft.millitm; +#elif defined(HAVE_TIME) + return (ulonglong) time(NULL) * 1000; +#elif defined(_WIN32) + FILETIME ft; + GetSystemTimeAsFileTime( &ft ); + return ((ulonglong)ft.dwLowDateTime + + (((ulonglong)ft.dwHighDateTime) << 32))/10000; +#elif defined(__NETWARE__) + { + NXTime_t tm; + NXGetTime(NX_SINCE_1970, NX_MSECONDS, &tm); + return (ulonglong)tm; + } +#else + return 0; +#endif +} + +/* + For ticks, which we handle with times(), the frequency + is usually 100/second and the overhead is surprisingly + bad, sometimes even worse than gettimeofday's overhead. +*/ + +ulonglong my_timer_ticks(void) +{ +#if defined(HAVE_SYS_TIMES_H) && defined(HAVE_TIMES) + { + struct tms times_buf; + return (ulonglong) times(×_buf); + } +#elif defined(__NETWARE__) + { + NXTime_t tm; + NXGetTime(NX_SINCE_BOOT, NX_TICKS, &tm); + return (ulonglong) tm; + } +#elif defined(_WIN32) + return (ulonglong) GetTickCount(); +#else + return 0; +#endif +} + +/* + The my_timer_init() function and its sub-functions + have several loops which call timers. If there's + something wrong with a timer -- which has never + happened in tests -- we want the loop to end after + an arbitrary number of iterations, and my_timer_info + will show a discouraging result. The arbitrary + number is 1,000,000. +*/ +#define MY_TIMER_ITERATIONS 1000000 + +/* + Calculate overhead. Called from my_timer_init(). + Usually best_timer_overhead = cycles.overhead or + nanoseconds.overhead, so returned amount is in + cycles or nanoseconds. We repeat the calculation + ten times, so that we can disregard effects of + caching or interrupts. Result is quite consistent + for cycles, at least. But remember it's a minimum. +*/ + +static void my_timer_init_overhead(ulonglong *overhead, + ulonglong (*cycle_timer)(void), + ulonglong (*this_timer)(void), + ulonglong best_timer_overhead) +{ + ulonglong time1, time2; + int i; + + /* *overhead, least of 20 calculations - cycles.overhead */ + for (i= 0, *overhead= 1000000000; i < 20; ++i) + { + time1= cycle_timer(); + this_timer(); /* rather than 'time_tmp= timer();' */ + time2= cycle_timer() - time1; + if (*overhead > time2) + *overhead= time2; + } + *overhead-= best_timer_overhead; +} + +/* + Calculate Resolution. Called from my_timer_init(). + If a timer goes up by jumps, e.g. 1050, 1075, 1100, ... + then the best resolution is the minimum jump, e.g. 25. + If it's always divisible by 1000 then it's just a + result of multiplication of a lower-precision timer + result, e.g. nanoseconds are often microseconds * 1000. + If the minimum jump is less than an arbitrary passed + figure (a guess based on maximum overhead * 2), ignore. + Usually we end up with nanoseconds = 1 because it's too + hard to detect anything <= 100 nanoseconds. + Often GetTickCount() has resolution = 15. + We don't check with ticks because they take too long. +*/ +static ulonglong my_timer_init_resolution(ulonglong (*this_timer)(void), + ulonglong overhead_times_2) +{ + ulonglong time1, time2; + ulonglong best_jump; + int i, jumps, divisible_by_1000, divisible_by_1000000; + + divisible_by_1000= divisible_by_1000000= 0; + best_jump= 1000000; + for (i= jumps= 0; jumps < 3 && i < MY_TIMER_ITERATIONS * 10; ++i) + { + time1= this_timer(); + time2= this_timer(); + time2-= time1; + if (time2) + { + ++jumps; + if (!(time2 % 1000)) + { + ++divisible_by_1000; + if (!(time2 % 1000000)) + ++divisible_by_1000000; + } + if (best_jump > time2) + best_jump= time2; + /* For milliseconds, one jump is enough. */ + if (overhead_times_2 == 0) + break; + } + } + if (jumps == 3) + { + if (jumps == divisible_by_1000000) + return 1000000; + if (jumps == divisible_by_1000) + return 1000; + } + if (best_jump > overhead_times_2) + return best_jump; + return 1; +} + +/* + Calculate cycle frequency by seeing how many cycles pass + in a 200-microsecond period. I tried with 10-microsecond + periods originally, and the result was often very wrong. +*/ + +static ulonglong my_timer_init_frequency(MY_TIMER_INFO *mti) +{ + int i; + ulonglong time1, time2, time3, time4; + time1= my_timer_cycles(); + time2= my_timer_microseconds(); + time3= time2; /* Avoids a Microsoft/IBM compiler warning */ + for (i= 0; i < MY_TIMER_ITERATIONS; ++i) + { + time3= my_timer_microseconds(); + if (time3 - time2 > 200) break; + } + time4= my_timer_cycles() - mti->cycles.overhead; + time4-= mti->microseconds.overhead; + return (mti->microseconds.frequency * (time4 - time1)) / (time3 - time2); +} + +/* + Call my_timer_init before the first call to my_timer_xxx(). + If something must be initialized, it happens here. + Set: what routine is being used e.g. "asm_x86" + Set: function, overhead, actual frequency, resolution. +*/ + +void my_timer_init(MY_TIMER_INFO *mti) +{ + ulonglong (*best_timer)(void); + ulonglong best_timer_overhead; + ulonglong time1, time2; + int i; + + /* cycles */ + mti->cycles.frequency= 1000000000; +#if defined(__GNUC__) && defined(__i386__) + mti->cycles.routine= MY_TIMER_ROUTINE_ASM_X86; +#elif defined(__SUNPRO_C) && defined(__i386) + mti->cycles.routine= MY_TIMER_ROUTINE_ASM_X86; +#elif defined(__GNUC__) && defined(__x86_64__) + mti->cycles.routine= MY_TIMER_ROUTINE_ASM_X86_64; +#elif defined(HAVE_ASM_MSR_H) && defined(HAVE_RDTSCLL) + mti->cycles.routine= MY_TIMER_ROUTINE_RDTSCLL; +#elif defined(_WIN32) && defined(_M_IX86) + mti->cycles.routine= MY_TIMER_ROUTINE_ASM_X86_WIN; +#elif defined(_WIN64) && defined(_M_X64) + mti->cycles.routine= MY_TIMER_ROUTINE_RDTSC; +#elif defined(__INTEL_COMPILER) && defined(__ia64__) && defined(HAVE_IA64INTRIN_H) + mti->cycles.routine= MY_TIMER_ROUTINE_ASM_IA64; +#elif defined(__GNUC__) && defined(__ia64__) + mti->cycles.routine= MY_TIMER_ROUTINE_ASM_IA64; +#elif defined(__GNUC__) && (defined(__powerpc__) || defined(__POWERPC__) || (defined(_POWER) && defined(_AIX52))) && (defined(__64BIT__) || defined(_ARCH_PPC64)) + mti->cycles.routine= MY_TIMER_ROUTINE_ASM_PPC64; +#elif defined(__GNUC__) && (defined(__powerpc__) || defined(__POWERPC__) || (defined(_POWER) && defined(_AIX52))) && (!defined(__64BIT__) && !defined(_ARCH_PPC64)) + mti->cycles.routine= MY_TIMER_ROUTINE_ASM_PPC; +#elif (defined(__SUNPRO_CC) || defined(__SUNPRO_C)) && defined(__sparcv9) && defined(_LP64) && !defined(__SunOS_5_7) + mti->cycles.routine= MY_TIMER_ROUTINE_ASM_SUNPRO_SPARC64; +#elif (defined(__SUNPRO_CC) || defined(__SUNPRO_C)) && defined(__sparcv8plus) && defined(_ILP32) && !defined(__SunOS_5_7) + mti->cycles.routine= MY_TIMER_ROUTINE_ASM_SUNPRO_SPARC32; +#elif (defined(__SUNPRO_CC) || defined(__SUNPRO_C)) && defined(__i386) && defined(_ILP32) + mti->cycles.routine= MY_TIMER_ROUTINE_ASM_SUNPRO_I386; +#elif (defined(__SUNPRO_CC) || defined(__SUNPRO_C)) && defined(__x86_64) && defined(_LP64) + mti->cycles.routine= MY_TIMER_ROUTINE_ASM_SUNPRO_X86_64; +#elif defined(__GNUC__) && defined(__sparcv9) && defined(_LP64) && (__GNUC__>2) + mti->cycles.routine= MY_TIMER_ROUTINE_ASM_GCC_SPARC64; +#elif defined(__GNUC__) && defined(__sparc__) && !defined(_LP64) && (__GNUC__>2) + mti->cycles.routine= MY_TIMER_ROUTINE_ASM_GCC_SPARC32; +#elif defined(__sgi) && defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_SGI_CYCLE) + mti->cycles.routine= MY_TIMER_ROUTINE_SGI_CYCLE; +#elif defined(HAVE_SYS_TIMES_H) && defined(HAVE_GETHRTIME) + mti->cycles.routine= MY_TIMER_ROUTINE_GETHRTIME; +#else + mti->cycles.routine= 0; +#endif + + if (!mti->cycles.routine || !my_timer_cycles()) + { + mti->cycles.routine= 0; + mti->cycles.resolution= 0; + mti->cycles.frequency= 0; + mti->cycles.overhead= 0; + } + + /* nanoseconds */ + mti->nanoseconds.frequency= 1000000000; /* initial assumption */ +#if defined(HAVE_READ_REAL_TIME) + mti->nanoseconds.routine= MY_TIMER_ROUTINE_READ_REAL_TIME; +#elif defined(HAVE_CLOCK_GETTIME) + mti->nanoseconds.routine= MY_TIMER_ROUTINE_CLOCK_GETTIME; +#elif defined(HAVE_SYS_TIMES_H) && defined(HAVE_GETHRTIME) + mti->nanoseconds.routine= MY_TIMER_ROUTINE_GETHRTIME; +#elif defined(__NETWARE__) + mti->nanoseconds.routine= MY_TIMER_ROUTINE_NXGETTIME; +#elif defined(__APPLE__) && defined(__MACH__) + mti->nanoseconds.routine= MY_TIMER_ROUTINE_MACH_ABSOLUTE_TIME; +#else + mti->nanoseconds.routine= 0; +#endif + if (!mti->nanoseconds.routine || !my_timer_nanoseconds()) + { + mti->nanoseconds.routine= 0; + mti->nanoseconds.resolution= 0; + mti->nanoseconds.frequency= 0; + mti->nanoseconds.overhead= 0; + } + + /* microseconds */ + mti->microseconds.frequency= 1000000; /* initial assumption */ +#if defined(HAVE_GETTIMEOFDAY) + mti->microseconds.routine= MY_TIMER_ROUTINE_GETTIMEOFDAY; +#elif defined(_WIN32) + { + LARGE_INTEGER li; + /* Windows: typical frequency = 3579545, actually 1/3 microsecond. */ + if (!QueryPerformanceFrequency(&li)) + mti->microseconds.routine= 0; + else + { + mti->microseconds.frequency= li.QuadPart; + mti->microseconds.routine= MY_TIMER_ROUTINE_QUERYPERFORMANCECOUNTER; + } + } +#elif defined(__NETWARE__) + mti->microseconds.routine= MY_TIMER_ROUTINE_NXGETTIME; +#else + mti->microseconds.routine= 0; +#endif + if (!mti->microseconds.routine || !my_timer_microseconds()) + { + mti->microseconds.routine= 0; + mti->microseconds.resolution= 0; + mti->microseconds.frequency= 0; + mti->microseconds.overhead= 0; + } + + /* milliseconds */ + mti->milliseconds.frequency= 1000; /* initial assumption */ +#if defined(HAVE_SYS_TIMEB_H) && defined(HAVE_FTIME) + mti->milliseconds.routine= MY_TIMER_ROUTINE_FTIME; +#elif defined(_WIN32) + mti->milliseconds.routine= MY_TIMER_ROUTINE_GETSYSTEMTIMEASFILETIME; +#elif defined(__NETWARE__) + mti->milliseconds.routine= MY_TIMER_ROUTINE_NXGETTIME; +#elif defined(HAVE_TIME) + mti->milliseconds.routine= MY_TIMER_ROUTINE_TIME; +#else + mti->milliseconds.routine= 0; +#endif + if (!mti->milliseconds.routine || !my_timer_milliseconds()) + { + mti->milliseconds.routine= 0; + mti->milliseconds.resolution= 0; + mti->milliseconds.frequency= 0; + mti->milliseconds.overhead= 0; + } + + /* ticks */ + mti->ticks.frequency= 100; /* permanent assumption */ +#if defined(HAVE_SYS_TIMES_H) && defined(HAVE_TIMES) + mti->ticks.routine= MY_TIMER_ROUTINE_TIMES; +#elif defined(__NETWARE__) + mti->ticks.routine= MY_TIMER_ROUTINE_NXGETTIME; +#elif defined(_WIN32) + mti->ticks.routine= MY_TIMER_ROUTINE_GETTICKCOUNT; +#else + mti->ticks.routine= 0; +#endif + if (!mti->ticks.routine || !my_timer_ticks()) + { + mti->ticks.routine= 0; + mti->ticks.resolution= 0; + mti->ticks.frequency= 0; + mti->ticks.overhead= 0; + } + + /* + Calculate overhead in terms of the timer that + gives the best resolution: cycles or nanoseconds. + I doubt it ever will be as bad as microseconds. + */ + if (mti->cycles.routine) + best_timer= &my_timer_cycles; + else + { + if (mti->nanoseconds.routine) + { + best_timer= &my_timer_nanoseconds; + } + else + best_timer= &my_timer_microseconds; + } + + /* best_timer_overhead = least of 20 calculations */ + for (i= 0, best_timer_overhead= 1000000000; i < 20; ++i) + { + time1= best_timer(); + time2= best_timer() - time1; + if (best_timer_overhead > time2) + best_timer_overhead= time2; + } + if (mti->cycles.routine) + my_timer_init_overhead(&mti->cycles.overhead, + best_timer, + &my_timer_cycles, + best_timer_overhead); + if (mti->nanoseconds.routine) + my_timer_init_overhead(&mti->nanoseconds.overhead, + best_timer, + &my_timer_nanoseconds, + best_timer_overhead); + if (mti->microseconds.routine) + my_timer_init_overhead(&mti->microseconds.overhead, + best_timer, + &my_timer_microseconds, + best_timer_overhead); + if (mti->milliseconds.routine) + my_timer_init_overhead(&mti->milliseconds.overhead, + best_timer, + &my_timer_milliseconds, + best_timer_overhead); + if (mti->ticks.routine) + my_timer_init_overhead(&mti->ticks.overhead, + best_timer, + &my_timer_ticks, + best_timer_overhead); + +/* + Calculate resolution for nanoseconds or microseconds + or milliseconds, by seeing if it's always divisible + by 1000, and by noticing how much jumping occurs. + For ticks, just assume the resolution is 1. +*/ + if (mti->cycles.routine) + mti->cycles.resolution= 1; + if (mti->nanoseconds.routine) + mti->nanoseconds.resolution= + my_timer_init_resolution(&my_timer_nanoseconds, 20000); + if (mti->microseconds.routine) + mti->microseconds.resolution= + my_timer_init_resolution(&my_timer_microseconds, 20); + if (mti->milliseconds.routine) + { + if (mti->milliseconds.routine == MY_TIMER_ROUTINE_TIME) + mti->milliseconds.resolution= 1000; + else + mti->milliseconds.resolution= + my_timer_init_resolution(&my_timer_milliseconds, 0); + } + if (mti->ticks.routine) + mti->ticks.resolution= 1; + +/* + Calculate cycles frequency, + if we have both a cycles routine and a microseconds routine. + In tests, this usually results in a figure within 2% of + what "cat /proc/cpuinfo" says. + If the microseconds routine is QueryPerformanceCounter + (i.e. it's Windows), and the microseconds frequency is > + 500,000,000 (i.e. it's Windows Server so it uses RDTSC) + and the microseconds resolution is > 100 (i.e. dreadful), + then calculate cycles frequency = microseconds frequency. +*/ + if (mti->cycles.routine + && mti->microseconds.routine) + { + if (mti->microseconds.routine == + MY_TIMER_ROUTINE_QUERYPERFORMANCECOUNTER + && mti->microseconds.frequency > 500000000 + && mti->microseconds.resolution > 100) + mti->cycles.frequency= mti->microseconds.frequency; + else + { + ulonglong time1, time2; + time1= my_timer_init_frequency(mti); + /* Repeat once in case there was an interruption. */ + time2= my_timer_init_frequency(mti); + if (time1 < time2) mti->cycles.frequency= time1; + else mti->cycles.frequency= time2; + } + } + +/* + Calculate milliseconds frequency = + (cycles-frequency/#-of-cycles) * #-of-milliseconds, + if we have both a milliseconds routine and a cycles + routine. + This will be inaccurate if milliseconds resolution > 1. + This is probably only useful when testing new platforms. +*/ + if (mti->milliseconds.routine + && mti->milliseconds.resolution < 1000 + && mti->microseconds.routine + && mti->cycles.routine) + { + int i; + ulonglong time1, time2, time3, time4; + time1= my_timer_cycles(); + time2= my_timer_milliseconds(); + time3= time2; /* Avoids a Microsoft/IBM compiler warning */ + for (i= 0; i < MY_TIMER_ITERATIONS * 1000; ++i) + { + time3= my_timer_milliseconds(); + if (time3 - time2 > 10) break; + } + time4= my_timer_cycles(); + mti->milliseconds.frequency= + (mti->cycles.frequency * (time3 - time2)) / (time4 - time1); + } + +/* + Calculate ticks.frequency = + (cycles-frequency/#-of-cycles * #-of-ticks, + if we have both a ticks routine and a cycles + routine, + This is probably only useful when testing new platforms. +*/ + if (mti->ticks.routine + && mti->microseconds.routine + && mti->cycles.routine) + { + int i; + ulonglong time1, time2, time3, time4; + time1= my_timer_cycles(); + time2= my_timer_ticks(); + time3= time2; /* Avoids a Microsoft/IBM compiler warning */ + for (i= 0; i < MY_TIMER_ITERATIONS * 1000; ++i) + { + time3= my_timer_ticks(); + if (time3 - time2 > 10) break; + } + time4= my_timer_cycles(); + mti->ticks.frequency= + (mti->cycles.frequency * (time3 - time2)) / (time4 - time1); + } +} + +/* + Additional Comments + ------------------- + + This is for timing, i.e. finding out how long a piece of code + takes. If you want time of day matching a wall clock, the + my_timer_xxx functions won't help you. + + The best timer is the one with highest frequency, lowest + overhead, and resolution=1. The my_timer_info() routine will tell + you at runtime which timer that is. Usually it will be + my_timer_cycles() but be aware that, although it's best, + it has possible flaws and dangers. Depending on platform: + - The frequency might change. We don't test for this. It + happens on laptops for power saving, and on blade servers + for avoiding overheating. + - The overhead that my_timer_init() returns is the minimum. + In fact it could be slightly greater because of caching or + because you call the routine by address, as recommended. + It could be hugely greater if there's an interrupt. + - The x86 cycle counter, RDTSC doesn't "serialize". That is, + if there is out-of-order execution, rdtsc might be processed + after an instruction that logically follows it. + (We could force serialization, but that would be slower.) + - It is possible to set a flag which renders RDTSC + inoperative. Somebody responsible for the kernel + of the operating system would have to make this + decision. For the platforms we've tested with, there's + no such problem. + - With a multi-processor arrangement, it's possible + to get the cycle count from one processor in + thread X, and the cycle count from another processor + in thread Y. They may not always be in synch. + - You can't depend on a cycle counter being available for + all platforms. On Alphas, the + cycle counter is only 32-bit, so it would overflow quickly, + so we don't bother with it. On platforms that we haven't + tested, there might be some if/endif combination that we + didn't expect, or some assembler routine that we didn't + supply. + + The recommended way to use the timer routines is: + 1. Somewhere near the beginning of the program, call + my_timer_init(). This should only be necessary once, + although you can call it again if you think that the + frequency has changed. + 2. Determine the best timer based on frequency, resolution, + overhead -- all things that my_timer_init() returns. + Preserve the address of the timer and the my_timer_into + results in an easily-accessible place. + 3. Instrument the code section that you're monitoring, thus: + time1= my_timer_xxx(); + Instrumented code; + time2= my_timer_xxx(); + elapsed_time= (time2 - time1) - overhead; + If the timer is always on, then overhead is always there, + so don't subtract it. + 4. Save the elapsed time, or add it to a totaller. + 5. When all timing processes are complete, transfer the + saved / totalled elapsed time to permanent storage. + Optionally you can convert cycles to microseconds at + this point. (Don't do so every time you calculate + elapsed_time! That would waste time and lose precision!) + For converting cycles to microseconds, use the frequency + that my_timer_init() returns. You'll also need to convert + if the my_timer_microseconds() function is the Windows + function QueryPerformanceCounter(), since that's sometimes + a counter with precision slightly better than microseconds. + + Since we recommend calls by function pointer, we supply + no inline functions. + + Some comments on the many candidate routines for timing ... + + clock() -- We don't use because it would overflow frequently. + + clock_gettime() -- Often we don't use this even when it exists. + In configure.in, we use AC_CHECK_FUNCS(clock_gettime). Not + AC_CHECK_LIB(rc,clock_gettime) + AC_CHECK_FUNCS(clock_gettime) + If we had the above lines in configure.in, we'd have to use + /usr/lib/librt.so or /usr/lib64/librt.so when linking, and + the size of librt.so is 40KB. In tests, clock_gettime often + had resolution = 1000. + + ftime() -- A "man ftime" says: "This function is obsolete. + Don't use it." On every platform that we tested, if ftime() + was available, then so was gettimeofday(), and gettimeofday() + overhead was always at least as good as ftime() overhead. + + gettimeofday() -- available on most platforms, though not + on Windows. There is a hardware timer (sometimes a Programmable + Interrupt Timer or "PIT") (sometimes a "HPET") used for + interrupt generation. When it interrupts (a "tick" or "jiffy", + typically 1 centisecond) it sets xtime. For gettimeofday, a + Linux kernel routine usually gets xtime and then gets rdtsc + to get elapsed nanoseconds since the last tick. On Red Hat + Enterprise Linux 3, there was once a bug which caused the + resolution to be 1000, i.e. one centisecond. We never check + for time-zone change. + + getnstimeofday() -- something to watch for in future Linux + + do_gettimeofday() -- exists on Linux but not for "userland" + + get_cycles() -- a multi-platform function, worth watching + in future Linux versions. But we found platform-specific + functions which were better documented in operating-system + manuals. And get_cycles() can fail or return a useless + 32-bit number. It might be available on some platforms, + such as arm, which we didn't test. Using + "include " or "include " + can lead to autoconf or compile errors, depending on system. + + rdtsc, __rdtsc, rdtscll: available for x86 with Linux BSD, + Solaris, Windows. See "possible flaws and dangers" comments. + + times(): what we use for ticks. Should just read the last + (xtime) tick count, therefore should be fast, but usually + isn't. + + GetTickCount(): we use this for my_timer_ticks() on + Windows. Actually it really is a tick counter, so resolution + >= 10 milliseconds unless you have a very old Windows version. + With Windows 95 or 98 or ME, timeGetTime() has better resolution than + GetTickCount (1ms rather than 55ms). But with Windows NT or XP or 2000, + they're both getting from a variable in the Process Environment Block + (PEB), and the variable is set by the programmable interrupt timer, so + the resolution is the same (usually 10-15 milliseconds). Also timeGetTime + is slower on old machines: + http://www.doumo.jp/aon-java/jsp/postgretips/tips.jsp?tips=74. + Also timeGetTime requires linking winmm.lib, + Therefore we use GetTickCount. + It will overflow every 49 days because the return is 32-bit. + There is also a GetTickCount64 but it requires Vista or Windows Server 2008. + (As for GetSystemTimeAsFileTime, its precision is spurious, it + just reads the tick variable like the other functions do. + However, we don't expect it to overflow every 49 days, so we + will prefer it for my_timer_milliseconds().) + + QueryPerformanceCounter() we use this for my_timer_microseconds() + on Windows. 1-PIT-tick (often 1/3-microsecond). Usually reads + the PIT so it's slow. On some Windows variants, uses RDTSC. + + GetLocalTime() this is available on Windows but we don't use it. + + getclock(): documented for Alpha, but not found during tests. + + mach_absolute_time() and UpTime() are recommended for Apple. + Inititally they weren't tried, because asm_ppc seems to do the job. + But now we use mach_absolute_time for nanoseconds. + + Any clock-based timer can be affected by NPT (ntpd program), + which means: + - full-second correction can occur for leap second + - tiny corrections can occcur approimately every 11 minutes + (but I think they only affect the RTC which isn't the PIT). + + We define "precision" as "frequency" and "high precision" is + "frequency better than 1 microsecond". We define "resolution" + as a synonym for "granularity". We define "accuracy" as + "closeness to the truth" as established by some authoritative + clock, but we can't measure accuracy. + + Do not expect any of our timers to be monotonic; we + won't guarantee that they return constantly-increasing + unique numbers. + + We tested with AIX, Solaris (x86 + Sparc), Linux (x86 + + Itanium), Windows, 64-bit Windows, QNX, FreeBSD, HPUX, + Irix, Mac. We didn't test with NetWare or SCO. + +*/ + diff --git a/mysys/my_timer_cycles.il b/mysys/my_timer_cycles.il new file mode 100644 index 00000000000..2f3f776530b --- /dev/null +++ b/mysys/my_timer_cycles.il @@ -0,0 +1,38 @@ +/* Copyright (C) 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 */ + +/* Sun Studio SPARC inline templates for cycle timer */ +/* Sun Studio i386 and x86_64 inline templates for cycle timer */ +/* I didn't say ".volatile" or ".nonvolatile". */ + +.inline my_timer_cycles_il_sparc64,0 +rd %tick,%o0 +.end + +.inline my_timer_cycles_il_sparc32,0 +rd %tick,%o2 +srlx %o2,32,%o0 +sra %o2,0,%o1 +.end + +.inline my_timer_cycles_il_i386,0 +rdtsc +.end + +.inline my_timer_cycles_il_x86_64,0 +rdtsc +shlq $32,%rdx +orq %rdx,%rax +.end diff --git a/unittest/mysys/CMakeLists.txt b/unittest/mysys/CMakeLists.txt new file mode 100644 index 00000000000..a4c79afbf8b --- /dev/null +++ b/unittest/mysys/CMakeLists.txt @@ -0,0 +1,35 @@ +# Copyright (C) 2007 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 + +INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/zlib + ${CMAKE_SOURCE_DIR}/sql + ${CMAKE_SOURCE_DIR}/regex + ${CMAKE_SOURCE_DIR}/extra/yassl/include + ${CMAKE_SOURCE_DIR}/unittest/mytap) +ADD_EXECUTABLE(bitmap-t bitmap-t.c) +TARGET_LINK_LIBRARIES(bitmap-t mytap mysys dbug strings) + +ADD_EXECUTABLE(base64-t base64-t.c) +TARGET_LINK_LIBRARIES(base64-t mytap mysys dbug strings) + +ADD_EXECUTABLE(my_atomic-t my_atomic-t.c) +TARGET_LINK_LIBRARIES(my_atomic-t mytap mysys dbug strings) + +ADD_EXECUTABLE(lf-t lf-t.c) +TARGET_LINK_LIBRARIES(lf-t mytap mysys dbug strings) + +ADD_EXECUTABLE(my_rdtsc-t my_rdtsc-t.c) +TARGET_LINK_LIBRARIES(my_rdtsc-t mytap mysys dbug strings) + diff --git a/unittest/mysys/Makefile.am b/unittest/mysys/Makefile.am index d83b2909048..25b30e331b0 100644 --- a/unittest/mysys/Makefile.am +++ b/unittest/mysys/Makefile.am @@ -23,7 +23,7 @@ LDADD = $(top_builddir)/unittest/mytap/libmytap.a \ $(top_builddir)/dbug/libdbug.a \ $(top_builddir)/strings/libmystrings.a -noinst_PROGRAMS = bitmap-t base64-t lf-t my_vsnprintf-t +noinst_PROGRAMS = bitmap-t base64-t lf-t my_rdtsc-t my_vsnprintf-t if NEED_THREAD # my_atomic-t is used to check thread functions, so it is safe to @@ -32,5 +32,4 @@ if NEED_THREAD noinst_PROGRAMS += my_atomic-t endif -# Don't update the files from bitkeeper -%::SCCS/s.% +EXTRA_DIST = CMakeLists.txt diff --git a/unittest/mysys/my_rdtsc-t.c b/unittest/mysys/my_rdtsc-t.c new file mode 100644 index 00000000000..286ff29fbfc --- /dev/null +++ b/unittest/mysys/my_rdtsc-t.c @@ -0,0 +1,229 @@ +/* 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 + + When you run rdtsc3, it will print the contents of + "my_timer_info". The display indicates + what timer routine is best for a given platform. + + For example, this is the display on production.mysql.com, + a 2.8GHz Xeon with Linux 2.6.17, gcc 3.3.3: + + cycles nanoseconds microseconds milliseconds ticks +------------- ------------- ------------- ------------- ------------- + 1 11 13 18 17 + 2815019607 1000000000 1000000 1049 102 + 1 1000 1 1 1 + 88 4116 3888 4092 2044 + + The first line shows routines, e.g. 1 = MY_TIMER_ROUTINE_ASM_X86. + The second line shows frequencies, e.g. 2815019607 is nearly 2.8GHz. + The third line shows resolutions, e.g. 1000 = very poor resolution. + The fourth line shows overheads, e.g. ticks takes 2044 cycles. +*/ + +#include "my_global.h" +#include "my_rdtsc.h" +#include "tap.h" + +#define LOOP_COUNT 100 + +MY_TIMER_INFO myt; + +void test_init() +{ + my_timer_init(&myt); + + diag("----- Routine ---------------"); + diag("myt.cycles.routine : %13llu", myt.cycles.routine); + diag("myt.nanoseconds.routine : %13llu", myt.nanoseconds.routine); + diag("myt.microseconds.routine : %13llu", myt.microseconds.routine); + diag("myt.milliseconds.routine : %13llu", myt.milliseconds.routine); + diag("myt.ticks.routine : %13llu", myt.ticks.routine); + + diag("----- Frequency -------------"); + diag("myt.cycles.frequency : %13llu", myt.cycles.frequency); + diag("myt.nanoseconds.frequency : %13llu", myt.nanoseconds.frequency); + diag("myt.microseconds.frequency : %13llu", myt.microseconds.frequency); + diag("myt.milliseconds.frequency : %13llu", myt.milliseconds.frequency); + diag("myt.ticks.frequency : %13llu", myt.ticks.frequency); + + diag("----- Resolution ------------"); + diag("myt.cycles.resolution : %13llu", myt.cycles.resolution); + diag("myt.nanoseconds.resolution : %13llu", myt.nanoseconds.resolution); + diag("myt.microseconds.resolution : %13llu", myt.microseconds.resolution); + diag("myt.milliseconds.resolution : %13llu", myt.milliseconds.resolution); + diag("myt.ticks.resolution : %13llu", myt.ticks.resolution); + + diag("----- Overhead --------------"); + diag("myt.cycles.overhead : %13llu", myt.cycles.overhead); + diag("myt.nanoseconds.overhead : %13llu", myt.nanoseconds.overhead); + diag("myt.microseconds.overhead : %13llu", myt.microseconds.overhead); + diag("myt.milliseconds.overhead : %13llu", myt.milliseconds.overhead); + diag("myt.ticks.overhead : %13llu", myt.ticks.overhead); + + ok(1, "my_timer_init() did not crash"); +} + +void test_cycle() +{ + ulonglong t1= my_timer_cycles(); + ulonglong t2; + int i; + int backward= 0; + int nonzero= 0; + + for (i=0 ; i < LOOP_COUNT ; i++) + { + t2= my_timer_cycles(); + if (t1 >= t2) + backward++; + if (t2 != 0) + nonzero++; + t1= t2; + } + + /* Expect at most 1 backward, the cycle value can overflow */ + ok((backward <= 1), "The cycle timer is strictly increasing"); + + if (myt.cycles.routine != 0) + ok((nonzero != 0), "The cycle timer is implemented"); + else + ok((nonzero == 0), "The cycle timer is not implemented and returns 0"); +} + +void test_nanosecond() +{ + ulonglong t1= my_timer_nanoseconds(); + ulonglong t2; + int i; + int backward= 0; + int nonzero= 0; + + for (i=0 ; i < LOOP_COUNT ; i++) + { + t2= my_timer_nanoseconds(); + if (t1 > t2) + backward++; + if (t2 != 0) + nonzero++; + t1= t2; + } + + ok((backward == 0), "The nanosecond timer is increasing"); + + if (myt.nanoseconds.routine != 0) + ok((nonzero != 0), "The nanosecond timer is implemented"); + else + ok((nonzero == 0), "The nanosecond timer is not implemented and returns 0"); +} + +void test_microsecond() +{ + ulonglong t1= my_timer_microseconds(); + ulonglong t2; + int i; + int backward= 0; + int nonzero= 0; + + for (i=0 ; i < LOOP_COUNT ; i++) + { + t2= my_timer_microseconds(); + if (t1 > t2) + backward++; + if (t2 != 0) + nonzero++; + t1= t2; + } + + ok((backward == 0), "The microsecond timer is increasing"); + + if (myt.microseconds.routine != 0) + ok((nonzero != 0), "The microsecond timer is implemented"); + else + ok((nonzero == 0), "The microsecond timer is not implemented and returns 0"); +} + +void test_millisecond() +{ + ulonglong t1= my_timer_milliseconds(); + ulonglong t2; + int i; + int backward= 0; + int nonzero= 0; + + for (i=0 ; i < LOOP_COUNT ; i++) + { + t2= my_timer_milliseconds(); + if (t1 > t2) + backward++; + if (t2 != 0) + nonzero++; + t1= t2; + } + + ok((backward == 0), "The millisecond timer is increasing"); + + if (myt.milliseconds.routine != 0) + ok((nonzero != 0), "The millisecond timer is implemented"); + else + ok((nonzero == 0), "The millisecond timer is not implemented and returns 0"); +} + +void test_tick() +{ + ulonglong t1= my_timer_ticks(); + ulonglong t2; + int i; + int backward= 0; + int nonzero= 0; + + for (i=0 ; i < LOOP_COUNT ; i++) + { + t2= my_timer_ticks(); + if (t1 > t2) + backward++; + if (t2 != 0) + nonzero++; + t1= t2; + } + + ok((backward == 0), "The tick timer is increasing"); + + if (myt.ticks.routine != 0) + ok((nonzero != 0), "The tick timer is implemented"); + else + ok((nonzero == 0), "The tick timer is not implemented and returns 0"); +} + +int main(int argc __attribute__((unused)), + char ** argv __attribute__((unused))) +{ + plan(11); + + test_init(); + test_cycle(); + test_nanosecond(); + test_microsecond(); + test_millisecond(); + test_tick(); + + return 0; +} +