Commit 48bbbf1f authored by vasil's avatar vasil

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.
parent c548ef1b
...@@ -286,43 +286,68 @@ os_fast_mutex_free( ...@@ -286,43 +286,68 @@ os_fast_mutex_free(
Atomic compare-and-swap and increment for InnoDB. */ Atomic compare-and-swap and increment for InnoDB. */
#ifdef HAVE_IB_GCC_ATOMIC_BUILTINS #ifdef HAVE_IB_GCC_ATOMIC_BUILTINS
#define HAVE_ATOMIC_BUILTINS
/**********************************************************//** /**********************************************************//**
Returns true if swapped, ptr is pointer to target, old_val is value to Returns true if swapped, ptr is pointer to target, old_val is value to
compare to, new_val is the value to swap in. */ compare to, new_val is the value to swap in. */
# define os_compare_and_swap(ptr, old_val, new_val) \ # define os_compare_and_swap(ptr, old_val, new_val) \
__sync_bool_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) \ # define os_compare_and_swap_ulint(ptr, old_val, new_val) \
os_compare_and_swap(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) \ # define os_compare_and_swap_lint(ptr, old_val, new_val) \
os_compare_and_swap(ptr, old_val, new_val) os_compare_and_swap(ptr, old_val, new_val)
# define os_compare_and_swap_thread_id(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) 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 Returns the resulting value, ptr is pointer to target, amount is the
amount of increment. */ amount of increment. */
# define os_atomic_increment(ptr, amount) \ # define os_atomic_increment(ptr, amount) \
__sync_add_and_fetch(ptr, amount) __sync_add_and_fetch(ptr, amount)
# define os_atomic_increment_lint(ptr, amount) \ # define os_atomic_increment_lint(ptr, amount) \
os_atomic_increment(ptr, amount) os_atomic_increment(ptr, amount)
# define os_atomic_increment_ulint(ptr, amount) \ # define os_atomic_increment_ulint(ptr, amount) \
os_atomic_increment(ptr, amount) os_atomic_increment(ptr, amount)
/**********************************************************//** /**********************************************************//**
Returns the old value of *ptr, atomically sets *ptr to new_val */ Returns the old value of *ptr, atomically sets *ptr to new_val */
# define os_atomic_test_and_set_byte(ptr, new_val) \ # define os_atomic_test_and_set_byte(ptr, new_val) \
__sync_lock_test_and_set(ptr, new_val) __sync_lock_test_and_set(ptr, new_val)
#elif defined(HAVE_SOLARIS_ATOMICS)
#define HAVE_ATOMIC_BUILTINS
/* If not compiling with GCC or GCC doesn't support the atomic /* If not compiling with GCC or GCC doesn't support the atomic
intrinsics and running on Solaris >= 10 use Solaris atomics */ intrinsics and running on Solaris >= 10 use Solaris atomics */
#elif defined(HAVE_SOLARIS_ATOMICS)
#include <atomic.h> #include <atomic.h>
/**********************************************************//** /**********************************************************//**
Returns true if swapped, ptr is pointer to target, old_val is value to Returns true if swapped, ptr is pointer to target, old_val is value to
compare to, new_val is the value to swap in. */ compare to, new_val is the value to swap in. */
# define os_compare_and_swap_ulint(ptr, old_val, new_val) \ # define os_compare_and_swap_ulint(ptr, old_val, new_val) \
(atomic_cas_ulong(ptr, old_val, new_val) == old_val) (atomic_cas_ulong(ptr, old_val, new_val) == old_val)
# define os_compare_and_swap_lint(ptr, old_val, new_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) ((lint)atomic_cas_ulong((ulong_t*) ptr, old_val, new_val) == old_val)
# ifdef INNODB_RW_LOCKS_USE_ATOMICS
# if SIZEOF_PTHREAD_T == 4 # ifdef HAVE_IB_ATOMIC_PTHREAD_T_SOLARIS
# if SIZEOF_PTHREAD_T == 4
# define os_compare_and_swap_thread_id(ptr, old_val, new_val) \ # define os_compare_and_swap_thread_id(ptr, old_val, new_val) \
((pthread_t)atomic_cas_32(ptr, old_val, new_val) == old_val) ((pthread_t)atomic_cas_32(ptr, old_val, new_val) == old_val)
# elif SIZEOF_PTHREAD_T == 8 # elif SIZEOF_PTHREAD_T == 8
...@@ -331,21 +356,30 @@ compare to, new_val is the value to swap in. */ ...@@ -331,21 +356,30 @@ compare to, new_val is the value to swap in. */
# else # else
# error "SIZEOF_PTHREAD_T != 4 or 8" # error "SIZEOF_PTHREAD_T != 4 or 8"
# endif /* SIZEOF_PTHREAD_T CHECK */ # 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 Returns the resulting value, ptr is pointer to target, amount is the
amount of increment. */ amount of increment. */
# define os_atomic_increment_lint(ptr, amount) \ # define os_atomic_increment_lint(ptr, amount) \
atomic_add_long_nv((ulong_t*) ptr, amount) atomic_add_long_nv((ulong_t*) ptr, amount)
# define os_atomic_increment_ulint(ptr, amount) \ # define os_atomic_increment_ulint(ptr, amount) \
atomic_add_long_nv(ptr, amount) atomic_add_long_nv(ptr, amount)
/**********************************************************//** /**********************************************************//**
Returns the old value of *ptr, atomically sets *ptr to new_val */ Returns the old value of *ptr, atomically sets *ptr to new_val */
# define os_atomic_test_and_set_byte(ptr, new_val) \ # define os_atomic_test_and_set_byte(ptr, new_val) \
atomic_swap_uchar(ptr, new_val) atomic_swap_uchar(ptr, new_val)
/* On Windows, use Windows atomics / interlocked */
#elif defined(HAVE_WINDOWS_ATOMICS) #elif defined(HAVE_WINDOWS_ATOMICS)
#define HAVE_ATOMIC_BUILTINS
/* On Windows, use Windows atomics / interlocked */
# ifdef _WIN64 # ifdef _WIN64
# define win_cmp_and_xchg InterlockedCompareExchange64 # define win_cmp_and_xchg InterlockedCompareExchange64
# define win_xchg_and_add InterlockedExchangeAdd64 # define win_xchg_and_add InterlockedExchangeAdd64
...@@ -353,31 +387,41 @@ Returns the old value of *ptr, atomically sets *ptr to new_val */ ...@@ -353,31 +387,41 @@ Returns the old value of *ptr, atomically sets *ptr to new_val */
# define win_cmp_and_xchg InterlockedCompareExchange # define win_cmp_and_xchg InterlockedCompareExchange
# define win_xchg_and_add InterlockedExchangeAdd # define win_xchg_and_add InterlockedExchangeAdd
# endif # endif
/**********************************************************//** /**********************************************************//**
Returns true if swapped, ptr is pointer to target, old_val is value to Returns true if swapped, ptr is pointer to target, old_val is value to
compare to, new_val is the value to swap in. */ compare to, new_val is the value to swap in. */
# define os_compare_and_swap_ulint(ptr, old_val, new_val) \ # define os_compare_and_swap_ulint(ptr, old_val, new_val) \
(win_cmp_and_xchg(ptr, new_val, old_val) == old_val) (win_cmp_and_xchg(ptr, new_val, old_val) == old_val)
# define os_compare_and_swap_lint(ptr, old_val, new_val) \ # define os_compare_and_swap_lint(ptr, old_val, new_val) \
(win_cmp_and_xchg(ptr, new_val, old_val) == old_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) \ # define os_compare_and_swap_thread_id(ptr, old_val, new_val) \
(InterlockedCompareExchange(ptr, new_val, old_val) == old_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 Returns the resulting value, ptr is pointer to target, amount is the
amount of increment. */ amount of increment. */
# define os_atomic_increment_lint(ptr, amount) \ # define os_atomic_increment_lint(ptr, amount) \
(win_xchg_and_add(ptr, amount) + amount) (win_xchg_and_add(ptr, amount) + amount)
# define os_atomic_increment_ulint(ptr, amount) \ # define os_atomic_increment_ulint(ptr, amount) \
((ulint) (win_xchg_and_add(ptr, amount) + amount)) ((ulint) (win_xchg_and_add(ptr, amount) + amount))
/**********************************************************//** /**********************************************************//**
Returns the old value of *ptr, atomically sets *ptr to new_val. Returns the old value of *ptr, atomically sets *ptr to new_val.
InterlockedExchange() operates on LONG, and the LONG will be InterlockedExchange() operates on LONG, and the LONG will be
clobbered */ clobbered */
# define os_atomic_test_and_set_byte(ptr, new_val) \ # define os_atomic_test_and_set_byte(ptr, new_val) \
((byte) InterlockedExchange(ptr, new_val)) ((byte) InterlockedExchange(ptr, new_val))
#endif /* HAVE_IB_GCC_ATOMIC_BUILTINS */
#endif
#ifndef UNIV_NONINL #ifndef UNIV_NONINL
#include "os0sync.ic" #include "os0sync.ic"
......
...@@ -91,29 +91,6 @@ or will be empty */ ...@@ -91,29 +91,6 @@ or will be empty */
# include "ut0auxconf.h" # include "ut0auxconf.h"
#endif #endif
#ifdef HAVE_WINDOWS_ATOMICS
/* windows thread objects can always be passed to windows atomic functions */
# define HAVE_IB_ATOMIC_PTHREAD_T_WINDOWS
#endif /* HAVE_WINDOWS_ATOMICS */
#if defined(HAVE_IB_GCC_ATOMIC_BUILTINS) \
|| defined(HAVE_SOLARIS_ATOMICS) \
|| defined(HAVE_WINDOWS_ATOMICS)
/* An auxiliary macro to know that some atomics are present and the
relevant os_*() macros will be defined and can be used */
# define HAVE_ATOMIC_BUILTINS
/* If pthread_t can be passed to any of the atomic functions then we know
that the appropriate macro os_compare_and_swap_thread_id() will be defined
and can be used */
# if defined(HAVE_IB_ATOMIC_PTHREAD_T_GCC) \
|| defined(HAVE_IB_ATOMIC_PTHREAD_T_SOLARIS) \
|| defined(HAVE_IB_ATOMIC_PTHREAD_T_WINDOWS)
# define INNODB_RW_LOCKS_USE_ATOMICS
# endif
#endif /* HAVE_IB_GCC_ATOMIC_BUILTINS
|| HAVE_SOLARIS_ATOMICS
|| HAVE_WINDOWS_ATOMICS */
#if (defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)) && !defined(MYSQL_SERVER) && !defined(__WIN__) #if (defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)) && !defined(MYSQL_SERVER) && !defined(__WIN__)
# undef __WIN__ # undef __WIN__
# define __WIN__ # define __WIN__
......
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