mirror of
https://github.com/MariaDB/server.git
synced 2025-01-22 06:44:16 +01:00
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.
This commit is contained in:
parent
ff368dec8a
commit
7bb8d19ceb
2 changed files with 54 additions and 33 deletions
|
@ -286,43 +286,68 @@ 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)
|
||||
# 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)
|
||||
# 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_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
|
||||
# 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) \
|
||||
((pthread_t)atomic_cas_32(ptr, old_val, new_val) == old_val)
|
||||
# elif SIZEOF_PTHREAD_T == 8
|
||||
|
@ -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) \
|
||||
|
||||
# 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"
|
||||
|
|
|
@ -91,29 +91,6 @@ or will be empty */
|
|||
# include "ut0auxconf.h"
|
||||
#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__)
|
||||
# undef __WIN__
|
||||
# define __WIN__
|
||||
|
|
Loading…
Add table
Reference in a new issue