Commit 913f8903 authored by Satya B's avatar Satya B

Applying InnoDB Plugin 1.0.5 snapshot , part 8

Note : r5865 is skipped
       r5869 plug.in related changes are aslo skipped

Detailed revision comments:

r5865 | vasil | 2009-09-12 02:26:03 -0500 (Sat, 12 Sep 2009) | 10 lines
branches/zip:

Simplify the compile time checks by splittig them into 5 independent checks:

* Whether GCC atomics are available
* Whether pthread_t can be used by GCC atomics
* Whether Solaris libc atomics are available
* Whether pthread_t can be used by Solaris libs atomics
* Checking the size of pthread_t

r5866 | vasil | 2009-09-12 02:30:08 -0500 (Sat, 12 Sep 2009) | 5 lines
branches/zip:

Add the check for GCC atomics to ut0auxconf* (copied from plug.in) because
we no longer rely on MySQL's HAVE_GCC_ATOMIC_BUILTINS.

r5867 | vasil | 2009-09-12 02:43:45 -0500 (Sat, 12 Sep 2009) | 4 lines
branches/zip:

Update comment to reflect reality.

r5868 | vasil | 2009-09-12 03:01:17 -0500 (Sat, 12 Sep 2009) | 6 lines
branches/zip:

Move the check whether to include ut0auxconf.h before everything because
we are now even checking for GCC atomics, we relied on MySQL to define
this macro before.

r5869 | vasil | 2009-09-12 03:33:11 -0500 (Sat, 12 Sep 2009) | 15 lines
branches/zip:

Include ut0auxconf.h only if none of the macros it would define is defined.
The check when to include this header was outdated from the time when there
was only one macro involved.

Move the atomics checks that are in univ.i outside of
#if windows ... #else ... #endif
This simplifies the code and removes some duplicates like defining
HAVE_ATOMIC_BUILTINS if HAVE_WINDOWS_ATOMICS is defined in both branches.

Do not define the same macro HAVE_ATOMIC_PTHREAD_T for different events.
Instead define HAVE_IB_ATOMIC_PTHREAD_T_GCC and
HAVE_IB_ATOMIC_PTHREAD_T_SOLARIS.

r5870 | vasil | 2009-09-12 04:13:44 -0500 (Sat, 12 Sep 2009) | 7 lines
branches/zip:

Define HAVE_ATOMIC_BUILTINS and INNODB_RW_LOCKS_USE_ATOMICS in os0sync.h
instead of in univ.i. The code expects os_*() macros to be present if
HAVE_ATOMIC_BUILTINS and INNODB_RW_LOCKS_USE_ATOMICS are defined. So define
them next to defining the os_*() macros.

r5871 | vasil | 2009-09-12 04:25:44 -0500 (Sat, 12 Sep 2009) | 6 lines
branches/zip:

Rename HAVE_SOLARIS_ATOMICS to HAVE_IB_SOLARIS_ATOMICS and 
IB_HAVE_PAUSE_INSTRUCTION to HAVE_IB_PAUSE_INSTRUCTION so they
all follow the same HAVE_IB_* convention.

r5872 | vasil | 2009-09-12 04:35:17 -0500 (Sat, 12 Sep 2009) | 5 lines
branches/zip:

Explicitly include os0sync.h to the places where HAVE_ATOMIC_BUILTINS and
INNODB_RW_LOCKS_USE_ATOMICS are used to avoid potential problems.
parent bf3b0747
......@@ -286,42 +286,67 @@ os_fast_mutex_free(
Atomic compare-and-swap and increment for InnoDB. */
#ifdef HAVE_IB_GCC_ATOMIC_BUILTINS
#define HAVE_ATOMIC_BUILTINS
/**********************************************************//**
Returns true if swapped, ptr is pointer to target, old_val is value to
compare to, new_val is the value to swap in. */
# define os_compare_and_swap(ptr, old_val, new_val) \
__sync_bool_compare_and_swap(ptr, old_val, new_val)
# define os_compare_and_swap_ulint(ptr, old_val, new_val) \
os_compare_and_swap(ptr, old_val, new_val)
# define os_compare_and_swap_lint(ptr, old_val, new_val) \
os_compare_and_swap(ptr, old_val, new_val)
# ifdef HAVE_IB_ATOMIC_PTHREAD_T_GCC
# define os_compare_and_swap_thread_id(ptr, old_val, new_val) \
os_compare_and_swap(ptr, old_val, new_val)
# define INNODB_RW_LOCKS_USE_ATOMICS
# endif /* HAVE_IB_ATOMIC_PTHREAD_T_GCC */
/**********************************************************//**
Returns the resulting value, ptr is pointer to target, amount is the
amount of increment. */
# define os_atomic_increment(ptr, amount) \
__sync_add_and_fetch(ptr, amount)
# define os_atomic_increment_lint(ptr, amount) \
os_atomic_increment(ptr, amount)
# define os_atomic_increment_ulint(ptr, amount) \
os_atomic_increment(ptr, amount)
/**********************************************************//**
Returns the old value of *ptr, atomically sets *ptr to new_val */
# define os_atomic_test_and_set_byte(ptr, new_val) \
__sync_lock_test_and_set(ptr, new_val)
#elif defined(HAVE_IB_SOLARIS_ATOMICS)
#define HAVE_ATOMIC_BUILTINS
/* If not compiling with GCC or GCC doesn't support the atomic
intrinsics and running on Solaris >= 10 use Solaris atomics */
#elif defined(HAVE_SOLARIS_ATOMICS)
#include <atomic.h>
/**********************************************************//**
Returns true if swapped, ptr is pointer to target, old_val is value to
compare to, new_val is the value to swap in. */
# define os_compare_and_swap_ulint(ptr, old_val, new_val) \
(atomic_cas_ulong(ptr, old_val, new_val) == old_val)
# define os_compare_and_swap_lint(ptr, old_val, new_val) \
((lint)atomic_cas_ulong((ulong_t*) ptr, old_val, new_val) == old_val)
# ifdef INNODB_RW_LOCKS_USE_ATOMICS
# ifdef HAVE_IB_ATOMIC_PTHREAD_T_SOLARIS
# if SIZEOF_PTHREAD_T == 4
# define os_compare_and_swap_thread_id(ptr, old_val, new_val) \
((pthread_t)atomic_cas_32(ptr, old_val, new_val) == old_val)
......@@ -331,21 +356,30 @@ compare to, new_val is the value to swap in. */
# else
# error "SIZEOF_PTHREAD_T != 4 or 8"
# endif /* SIZEOF_PTHREAD_T CHECK */
# endif /* INNODB_RW_LOCKS_USE_ATOMICS */
# define INNODB_RW_LOCKS_USE_ATOMICS
# endif /* HAVE_IB_ATOMIC_PTHREAD_T_SOLARIS */
/**********************************************************//**
Returns the resulting value, ptr is pointer to target, amount is the
amount of increment. */
# define os_atomic_increment_lint(ptr, amount) \
atomic_add_long_nv((ulong_t*) ptr, amount)
# define os_atomic_increment_ulint(ptr, amount) \
atomic_add_long_nv(ptr, amount)
/**********************************************************//**
Returns the old value of *ptr, atomically sets *ptr to new_val */
# define os_atomic_test_and_set_byte(ptr, new_val) \
atomic_swap_uchar(ptr, new_val)
/* On Windows, use Windows atomics / interlocked */
#elif defined(HAVE_WINDOWS_ATOMICS)
#define HAVE_ATOMIC_BUILTINS
/* On Windows, use Windows atomics / interlocked */
# ifdef _WIN64
# define win_cmp_and_xchg InterlockedCompareExchange64
# define win_xchg_and_add InterlockedExchangeAdd64
......@@ -353,31 +387,41 @@ Returns the old value of *ptr, atomically sets *ptr to new_val */
# define win_cmp_and_xchg InterlockedCompareExchange
# define win_xchg_and_add InterlockedExchangeAdd
# endif
/**********************************************************//**
Returns true if swapped, ptr is pointer to target, old_val is value to
compare to, new_val is the value to swap in. */
# define os_compare_and_swap_ulint(ptr, old_val, new_val) \
(win_cmp_and_xchg(ptr, new_val, old_val) == old_val)
# define os_compare_and_swap_lint(ptr, old_val, new_val) \
(win_cmp_and_xchg(ptr, new_val, old_val) == old_val)
# ifdef INNODB_RW_LOCKS_USE_ATOMICS
# define os_compare_and_swap_thread_id(ptr, old_val, new_val) \
(InterlockedCompareExchange(ptr, new_val, old_val) == old_val)
# endif /* INNODB_RW_LOCKS_USE_ATOMICS */
/* windows thread objects can always be passed to windows atomic functions */
# define HAVE_IB_ATOMIC_PTHREAD_T_WINDOWS
/**********************************************************//**
Returns the resulting value, ptr is pointer to target, amount is the
amount of increment. */
# define os_atomic_increment_lint(ptr, amount) \
(win_xchg_and_add(ptr, amount) + amount)
# define os_atomic_increment_ulint(ptr, amount) \
((ulint) (win_xchg_and_add(ptr, amount) + amount))
/**********************************************************//**
Returns the old value of *ptr, atomically sets *ptr to new_val.
InterlockedExchange() operates on LONG, and the LONG will be
clobbered */
# define os_atomic_test_and_set_byte(ptr, new_val) \
((byte) InterlockedExchange(ptr, new_val))
#endif /* HAVE_IB_GCC_ATOMIC_BUILTINS */
#endif
#ifndef UNIV_NONINL
#include "os0sync.ic"
......
......@@ -78,17 +78,25 @@ the virtual method table (vtable) in GCC 3. */
# define ha_innobase ha_innodb
#endif /* MYSQL_DYNAMIC_PLUGIN */
/* if any of the following macros is defined at this point this means
that the code from the "right" plug.in was executed and we do not
need to include ut0auxconf.h which would either define the same macros
or will be empty */
#if !defined(HAVE_IB_GCC_ATOMIC_BUILTINS) \
&& !defined(HAVE_IB_ATOMIC_PTHREAD_T_GCC) \
&& !defined(HAVE_IB_SOLARIS_ATOMICS) \
&& !defined(HAVE_IB_ATOMIC_PTHREAD_T_SOLARIS) \
&& !defined(SIZEOF_PTHREAD_T) \
&& !defined(HAVE_IB_PAUSE_INSTRUCTION)
# include "ut0auxconf.h"
#endif
#if (defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)) && !defined(MYSQL_SERVER) && !defined(__WIN__)
# undef __WIN__
# define __WIN__
# include <windows.h>
# if defined(HAVE_WINDOWS_ATOMICS)
/* If atomics are defined we use them in InnoDB mutex implementation */
# define HAVE_ATOMIC_BUILTINS
# endif /* HAVE_WINDOWS_ATOMICS */
# ifdef _NT_
# define __NT__
# endif
......@@ -122,31 +130,6 @@ if we are compiling on Windows. */
# include <sched.h>
# endif
# if defined(HAVE_IB_GCC_ATOMIC_BUILTINS) || defined(HAVE_SOLARIS_ATOMICS) \
|| defined(HAVE_WINDOWS_ATOMICS)
/* If atomics are defined we use them in InnoDB mutex implementation */
# define HAVE_ATOMIC_BUILTINS
# endif /* (HAVE_IB_GCC_ATOMIC_BUILTINS) || (HAVE_SOLARIS_ATOMICS)
|| (HAVE_WINDOWS_ATOMICS) */
/* For InnoDB rw_locks to work with atomics we need the thread_id
to be no more than machine word wide. The following enables using
atomics for InnoDB rw_locks where these conditions are met. */
#ifdef HAVE_ATOMIC_BUILTINS
/* if HAVE_ATOMIC_PTHREAD_T is defined at this point that means that
the code from plug.in has defined it and we do not need to include
ut0auxconf.h which would either define HAVE_ATOMIC_PTHREAD_T or will
be empty */
# ifndef HAVE_ATOMIC_PTHREAD_T
# include "ut0auxconf.h"
# endif /* HAVE_ATOMIC_PTHREAD_T */
/* now HAVE_ATOMIC_PTHREAD_T is eventually defined either by plug.in or
from Makefile.in->ut0auxconf.h */
# ifdef HAVE_ATOMIC_PTHREAD_T
# define INNODB_RW_LOCKS_USE_ATOMICS
# endif /* HAVE_ATOMIC_PTHREAD_T */
#endif /* HAVE_ATOMIC_BUILTINS */
/* We only try to do explicit inlining of functions with gcc and
Sun Studio */
......
/* Do not remove this file even though it is empty.
This file is included in univ.i and will cause compilation failure
if not present.
A custom check has been added in the generated
A custom checks have been added in the generated
storage/innobase/Makefile.in that is shipped with the InnoDB Plugin
source archive. This check tries to compile a test program and if
successful then adds "#define HAVE_ATOMIC_PTHREAD_T" to this file.
This is a hack that has been developed in order to check for pthread_t
atomicity without the need to regenerate the ./configure script that is
source archive. These checks eventually define some macros and put
them in this file.
This is a hack that has been developed in order to deploy new compile
time checks without the need to regenerate the ./configure script that is
distributed in the MySQL 5.1 official source archives.
If by any chance Makefile.in and ./configure are regenerated and thus
the hack from Makefile.in wiped away then the "real" check from plug.in
the hack from Makefile.in wiped away then the "real" checks from plug.in
will take over.
*/
......@@ -34,6 +34,9 @@ Created 1/20/1994 Heikki Tuuri
#define ut0ut_h
#include "univ.i"
#include "os0sync.h" /* for HAVE_ATOMIC_BUILTINS */
#include <time.h>
#ifndef MYSQL_SERVER
#include <ctype.h>
......@@ -47,7 +50,7 @@ Created 1/20/1994 Heikki Tuuri
/** Time stamp */
typedef time_t ib_time_t;
#if defined(IB_HAVE_PAUSE_INSTRUCTION)
#if defined(HAVE_IB_PAUSE_INSTRUCTION)
# ifdef WIN32
/* In the Win32 API, the x86 PAUSE instruction is executed by calling
the YieldProcessor macro defined in WinNT.h. It is a CPU architecture-
......
......@@ -102,6 +102,7 @@ Created 10/8/1995 Heikki Tuuri
#include "row0mysql.h"
#include "ha_prototypes.h"
#include "trx0i_s.h"
#include "os0sync.h" /* for HAVE_ATOMIC_BUILTINS */
/* This is set to TRUE if the MySQL user has set it in MySQL; currently
affects only FOREIGN KEY definition parsing */
......
......@@ -103,6 +103,7 @@ Created 2/16/1996 Heikki Tuuri
# include "row0row.h"
# include "row0mysql.h"
# include "btr0pcur.h"
# include "os0sync.h" /* for INNODB_RW_LOCKS_USE_ATOMICS */
/** Log sequence number immediately after startup */
UNIV_INTERN ib_uint64_t srv_start_lsn;
......@@ -1114,7 +1115,7 @@ innobase_start_or_create_for_mysql(void)
fprintf(stderr,
"InnoDB: Mutexes use GCC atomic builtins, rw_locks do not.\n");
# endif /* INNODB_RW_LOCKS_USE_ATOMICS */
#elif defined(HAVE_SOLARIS_ATOMICS)
#elif defined(HAVE_IB_SOLARIS_ATOMICS)
# ifdef INNODB_RW_LOCKS_USE_ATOMICS
fprintf(stderr,
"InnoDB: Mutexes and rw_locks use Solaris atomic functions.\n");
......
......@@ -38,6 +38,7 @@ Created 9/11/1995 Heikki Tuuri
#include "os0thread.h"
#include "mem0mem.h"
#include "srv0srv.h"
#include "os0sync.h" /* for INNODB_RW_LOCKS_USE_ATOMICS */
/*
IMPLEMENTATION OF THE RW_LOCK
......
......@@ -39,6 +39,7 @@ Created 9/5/1995 Heikki Tuuri
#include "buf0buf.h"
#include "srv0srv.h"
#include "buf0types.h"
#include "os0sync.h" /* for HAVE_ATOMIC_BUILTINS */
/*
REASONS FOR IMPLEMENTING THE SPIN LOCK MUTEX
......
/*****************************************************************************
Copyright (c) 2009, Innobase Oy. All Rights Reserved.
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place, Suite 330, Boston, MA 02111-1307 USA
*****************************************************************************/
/*****************************************************************************
If this program compiles and returns 0, then GCC atomic funcions are available.
Created September 12, 2009 Vasil Dimov
*****************************************************************************/
int
main(int argc, char** argv)
{
long x;
long y;
long res;
char c;
x = 10;
y = 123;
res = __sync_bool_compare_and_swap(&x, x, y);
if (!res || x != y) {
return(1);
}
x = 10;
y = 123;
res = __sync_bool_compare_and_swap(&x, x + 1, y);
if (res || x != 10) {
return(1);
}
x = 10;
y = 123;
res = __sync_add_and_fetch(&x, y);
if (res != 123 + 10 || x != 123 + 10) {
return(1);
}
c = 10;
res = __sync_lock_test_and_set(&c, 123);
if (res != 10 || c != 123) {
return(1);
}
return(0);
}
/*****************************************************************************
Copyright (c) 2009, Innobase Oy. All Rights Reserved.
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place, Suite 330, Boston, MA 02111-1307 USA
*****************************************************************************/
/*****************************************************************************
If this program compiles and returns 0, then GCC atomic funcions are available.
Created September 12, 2009 Vasil Dimov
*****************************************************************************/
int
main(int argc, char** argv)
{
long x;
long y;
long res;
char c;
x = 10;
y = 123;
res = __sync_bool_compare_and_swap(&x, x, y);
if (!res || x != y) {
return(1);
}
x = 10;
y = 123;
res = __sync_bool_compare_and_swap(&x, x + 1, y);
if (res || x != 10) {
return(1);
}
x = 10;
y = 123;
res = __sync_add_and_fetch(&x, y);
if (res != 123 + 10 || x != 123 + 10) {
return(1);
}
c = 10;
res = __sync_lock_test_and_set(&c, 123);
if (res != 10 || c != 123) {
return(1);
}
return(0);
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment