Dep/MySQL: Updated MySQL sources to version 5.5.9 (current GA)
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
#ifndef ATOMIC_GCC_BUILTINS_INCLUDED
|
||||
#define ATOMIC_GCC_BUILTINS_INCLUDED
|
||||
|
||||
/* Copyright (C) 2008 MySQL AB
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; version 2 of the License.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
||||
|
||||
#define make_atomic_add_body(S) \
|
||||
v= __sync_fetch_and_add(a, v);
|
||||
#define make_atomic_fas_body(S) \
|
||||
v= __sync_lock_test_and_set(a, v);
|
||||
#define make_atomic_cas_body(S) \
|
||||
int ## S sav; \
|
||||
int ## S cmp_val= *cmp; \
|
||||
sav= __sync_val_compare_and_swap(a, cmp_val, set);\
|
||||
if (!(ret= (sav == cmp_val))) *cmp= sav
|
||||
|
||||
#ifdef MY_ATOMIC_MODE_DUMMY
|
||||
#define make_atomic_load_body(S) ret= *a
|
||||
#define make_atomic_store_body(S) *a= v
|
||||
#define MY_ATOMIC_MODE "gcc-builtins-up"
|
||||
|
||||
#else
|
||||
#define MY_ATOMIC_MODE "gcc-builtins-smp"
|
||||
#define make_atomic_load_body(S) \
|
||||
ret= __sync_fetch_and_or(a, 0);
|
||||
#define make_atomic_store_body(S) \
|
||||
(void) __sync_lock_test_and_set(a, v);
|
||||
#endif
|
||||
|
||||
#endif /* ATOMIC_GCC_BUILTINS_INCLUDED */
|
||||
@@ -0,0 +1,134 @@
|
||||
/* Copyright (C) 2006-2008 MySQL AB, 2008-2009 Sun Microsystems, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; version 2 of the License.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
||||
|
||||
#ifndef _atomic_h_cleanup_
|
||||
#define _atomic_h_cleanup_ "atomic/generic-msvc.h"
|
||||
|
||||
/*
|
||||
We don't implement anything specific for MY_ATOMIC_MODE_DUMMY, always use
|
||||
intrinsics.
|
||||
8 and 16-bit atomics are not implemented, but it can be done if necessary.
|
||||
*/
|
||||
#undef MY_ATOMIC_HAS_8_16
|
||||
|
||||
#include <windows.h>
|
||||
/*
|
||||
x86 compilers (both VS2003 or VS2005) never use instrinsics, but generate
|
||||
function calls to kernel32 instead, even in the optimized build.
|
||||
We force intrinsics as described in MSDN documentation for
|
||||
_InterlockedCompareExchange.
|
||||
*/
|
||||
#ifdef _M_IX86
|
||||
|
||||
#if (_MSC_VER >= 1500)
|
||||
#include <intrin.h>
|
||||
#else
|
||||
C_MODE_START
|
||||
/*Visual Studio 2003 and earlier do not have prototypes for atomic intrinsics*/
|
||||
LONG _InterlockedCompareExchange (LONG volatile *Target, LONG Value, LONG Comp);
|
||||
LONGLONG _InterlockedCompareExchange64 (LONGLONG volatile *Target,
|
||||
LONGLONG Value, LONGLONG Comp);
|
||||
C_MODE_END
|
||||
|
||||
#pragma intrinsic(_InterlockedCompareExchange)
|
||||
#pragma intrinsic(_InterlockedCompareExchange64)
|
||||
#endif
|
||||
|
||||
#define InterlockedCompareExchange _InterlockedCompareExchange
|
||||
#define InterlockedCompareExchange64 _InterlockedCompareExchange64
|
||||
/*
|
||||
No need to do something special for InterlockedCompareExchangePointer
|
||||
as it is a #define to InterlockedCompareExchange. The same applies to
|
||||
InterlockedExchangePointer.
|
||||
*/
|
||||
#endif /*_M_IX86*/
|
||||
|
||||
#define MY_ATOMIC_MODE "msvc-intrinsics"
|
||||
/* Implement using CAS on WIN32 */
|
||||
#define IL_COMP_EXCHG32(X,Y,Z) \
|
||||
InterlockedCompareExchange((volatile LONG *)(X),(Y),(Z))
|
||||
#define IL_COMP_EXCHG64(X,Y,Z) \
|
||||
InterlockedCompareExchange64((volatile LONGLONG *)(X), \
|
||||
(LONGLONG)(Y),(LONGLONG)(Z))
|
||||
#define IL_COMP_EXCHGptr InterlockedCompareExchangePointer
|
||||
|
||||
#define make_atomic_cas_body(S) \
|
||||
int ## S initial_cmp= *cmp; \
|
||||
int ## S initial_a= IL_COMP_EXCHG ## S (a, set, initial_cmp); \
|
||||
if (!(ret= (initial_a == initial_cmp))) *cmp= initial_a;
|
||||
|
||||
#ifndef _M_IX86
|
||||
/* Use full set of optimised functions on WIN64 */
|
||||
#define IL_EXCHG_ADD32(X,Y) \
|
||||
InterlockedExchangeAdd((volatile LONG *)(X),(Y))
|
||||
#define IL_EXCHG_ADD64(X,Y) \
|
||||
InterlockedExchangeAdd64((volatile LONGLONG *)(X),(LONGLONG)(Y))
|
||||
#define IL_EXCHG32(X,Y) \
|
||||
InterlockedExchange((volatile LONG *)(X),(Y))
|
||||
#define IL_EXCHG64(X,Y) \
|
||||
InterlockedExchange64((volatile LONGLONG *)(X),(LONGLONG)(Y))
|
||||
#define IL_EXCHGptr InterlockedExchangePointer
|
||||
|
||||
#define make_atomic_add_body(S) \
|
||||
v= IL_EXCHG_ADD ## S (a, v)
|
||||
#define make_atomic_swap_body(S) \
|
||||
v= IL_EXCHG ## S (a, v)
|
||||
#define make_atomic_load_body(S) \
|
||||
ret= 0; /* avoid compiler warning */ \
|
||||
ret= IL_COMP_EXCHG ## S (a, ret, ret);
|
||||
#endif
|
||||
/*
|
||||
my_yield_processor (equivalent of x86 PAUSE instruction) should be used
|
||||
to improve performance on hyperthreaded CPUs. Intel recommends to use it in
|
||||
spin loops also on non-HT machines to reduce power consumption (see e.g
|
||||
http://softwarecommunity.intel.com/articles/eng/2004.htm)
|
||||
|
||||
Running benchmarks for spinlocks implemented with InterlockedCompareExchange
|
||||
and YieldProcessor shows that much better performance is achieved by calling
|
||||
YieldProcessor in a loop - that is, yielding longer. On Intel boxes setting
|
||||
loop count in the range 200-300 brought best results.
|
||||
*/
|
||||
#ifndef YIELD_LOOPS
|
||||
#define YIELD_LOOPS 200
|
||||
#endif
|
||||
|
||||
static __inline int my_yield_processor()
|
||||
{
|
||||
int i;
|
||||
for(i=0; i<YIELD_LOOPS; i++)
|
||||
{
|
||||
#if (_MSC_VER <= 1310)
|
||||
/* On older compilers YieldProcessor is not available, use inline assembly*/
|
||||
__asm { rep nop }
|
||||
#else
|
||||
YieldProcessor();
|
||||
#endif
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
#define LF_BACKOFF my_yield_processor()
|
||||
#else /* cleanup */
|
||||
|
||||
#undef IL_EXCHG_ADD32
|
||||
#undef IL_EXCHG_ADD64
|
||||
#undef IL_COMP_EXCHG32
|
||||
#undef IL_COMP_EXCHG64
|
||||
#undef IL_COMP_EXCHGptr
|
||||
#undef IL_EXCHG32
|
||||
#undef IL_EXCHG64
|
||||
#undef IL_EXCHGptr
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,69 @@
|
||||
#ifndef ATOMIC_NOLOCK_INCLUDED
|
||||
#define ATOMIC_NOLOCK_INCLUDED
|
||||
|
||||
/* Copyright (C) 2006 MySQL AB
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; version 2 of the License.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
||||
|
||||
#if defined(__i386__) || defined(_MSC_VER) || defined(__x86_64__) \
|
||||
|| defined(HAVE_GCC_ATOMIC_BUILTINS) \
|
||||
|| defined(HAVE_SOLARIS_ATOMIC)
|
||||
|
||||
# ifdef MY_ATOMIC_MODE_DUMMY
|
||||
# define LOCK_prefix ""
|
||||
# else
|
||||
# define LOCK_prefix "lock"
|
||||
# endif
|
||||
/*
|
||||
We choose implementation as follows:
|
||||
------------------------------------
|
||||
On Windows using Visual C++ the native implementation should be
|
||||
preferrable. When using gcc we prefer the Solaris implementation
|
||||
before the gcc because of stability preference, we choose gcc
|
||||
builtins if available, otherwise we choose the somewhat broken
|
||||
native x86 implementation. If neither Visual C++ or gcc we still
|
||||
choose the Solaris implementation on Solaris (mainly for SunStudio
|
||||
compilers).
|
||||
*/
|
||||
# if defined(_MSV_VER)
|
||||
# include "generic-msvc.h"
|
||||
# elif __GNUC__
|
||||
# if defined(HAVE_SOLARIS_ATOMIC)
|
||||
# include "solaris.h"
|
||||
# elif defined(HAVE_GCC_ATOMIC_BUILTINS)
|
||||
# include "gcc_builtins.h"
|
||||
# elif defined(__i386__) || defined(__x86_64__)
|
||||
# include "x86-gcc.h"
|
||||
# endif
|
||||
# elif defined(HAVE_SOLARIS_ATOMIC)
|
||||
# include "solaris.h"
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if defined(make_atomic_cas_body)
|
||||
/*
|
||||
Type not used so minimal size (emptry struct has different size between C
|
||||
and C++, zero-length array is gcc-specific).
|
||||
*/
|
||||
typedef char my_atomic_rwlock_t __attribute__ ((unused));
|
||||
#define my_atomic_rwlock_destroy(name)
|
||||
#define my_atomic_rwlock_init(name)
|
||||
#define my_atomic_rwlock_rdlock(name)
|
||||
#define my_atomic_rwlock_wrlock(name)
|
||||
#define my_atomic_rwlock_rdunlock(name)
|
||||
#define my_atomic_rwlock_wrunlock(name)
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* ATOMIC_NOLOCK_INCLUDED */
|
||||
@@ -0,0 +1,100 @@
|
||||
#ifndef ATOMIC_RWLOCK_INCLUDED
|
||||
#define ATOMIC_RWLOCK_INCLUDED
|
||||
|
||||
/* Copyright (C) 2006 MySQL AB, 2009 Sun Microsystems, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; version 2 of the License.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
||||
|
||||
#define MY_ATOMIC_MODE_RWLOCKS 1
|
||||
|
||||
#ifdef MY_ATOMIC_MODE_DUMMY
|
||||
/*
|
||||
the following can never be enabled by ./configure, one need to put #define in
|
||||
a source to trigger the following warning. The resulting code will be broken,
|
||||
it only makes sense to do it to see now test_atomic detects broken
|
||||
implementations (another way is to run a UP build on an SMP box).
|
||||
*/
|
||||
#warning MY_ATOMIC_MODE_DUMMY and MY_ATOMIC_MODE_RWLOCKS are incompatible
|
||||
|
||||
typedef char my_atomic_rwlock_t;
|
||||
|
||||
#define my_atomic_rwlock_destroy(name)
|
||||
#define my_atomic_rwlock_init(name)
|
||||
#define my_atomic_rwlock_rdlock(name)
|
||||
#define my_atomic_rwlock_wrlock(name)
|
||||
#define my_atomic_rwlock_rdunlock(name)
|
||||
#define my_atomic_rwlock_wrunlock(name)
|
||||
#define MY_ATOMIC_MODE "dummy (non-atomic)"
|
||||
#else /* not MY_ATOMIC_MODE_DUMMY */
|
||||
|
||||
typedef struct {pthread_mutex_t rw;} my_atomic_rwlock_t;
|
||||
|
||||
#ifndef SAFE_MUTEX
|
||||
|
||||
/*
|
||||
we're using read-write lock macros but map them to mutex locks, and they're
|
||||
faster. Still, having semantically rich API we can change the
|
||||
underlying implementation, if necessary.
|
||||
*/
|
||||
#define my_atomic_rwlock_destroy(name) pthread_mutex_destroy(& (name)->rw)
|
||||
#define my_atomic_rwlock_init(name) pthread_mutex_init(& (name)->rw, 0)
|
||||
#define my_atomic_rwlock_rdlock(name) pthread_mutex_lock(& (name)->rw)
|
||||
#define my_atomic_rwlock_wrlock(name) pthread_mutex_lock(& (name)->rw)
|
||||
#define my_atomic_rwlock_rdunlock(name) pthread_mutex_unlock(& (name)->rw)
|
||||
#define my_atomic_rwlock_wrunlock(name) pthread_mutex_unlock(& (name)->rw)
|
||||
|
||||
#else /* SAFE_MUTEX */
|
||||
|
||||
/*
|
||||
SAFE_MUTEX pollutes the compiling name space with macros
|
||||
that alter pthread_mutex_t, pthread_mutex_init, etc.
|
||||
Atomic operations should never use the safe mutex wrappers.
|
||||
Unfortunately, there is no way to have both:
|
||||
- safe mutex macros expanding pthread_mutex_lock to safe_mutex_lock
|
||||
- my_atomic macros expanding to unmodified pthread_mutex_lock
|
||||
inlined in the same compilation unit.
|
||||
So, in case of SAFE_MUTEX, a function call is required.
|
||||
Given that SAFE_MUTEX is a debugging facility,
|
||||
this extra function call is not a performance concern for
|
||||
production builds.
|
||||
*/
|
||||
C_MODE_START
|
||||
extern void plain_pthread_mutex_init(safe_mutex_t *);
|
||||
extern void plain_pthread_mutex_destroy(safe_mutex_t *);
|
||||
extern void plain_pthread_mutex_lock(safe_mutex_t *);
|
||||
extern void plain_pthread_mutex_unlock(safe_mutex_t *);
|
||||
C_MODE_END
|
||||
|
||||
#define my_atomic_rwlock_destroy(name) plain_pthread_mutex_destroy(&(name)->rw)
|
||||
#define my_atomic_rwlock_init(name) plain_pthread_mutex_init(&(name)->rw)
|
||||
#define my_atomic_rwlock_rdlock(name) plain_pthread_mutex_lock(&(name)->rw)
|
||||
#define my_atomic_rwlock_wrlock(name) plain_pthread_mutex_lock(&(name)->rw)
|
||||
#define my_atomic_rwlock_rdunlock(name) plain_pthread_mutex_unlock(&(name)->rw)
|
||||
#define my_atomic_rwlock_wrunlock(name) plain_pthread_mutex_unlock(&(name)->rw)
|
||||
|
||||
#endif /* SAFE_MUTEX */
|
||||
|
||||
#define MY_ATOMIC_MODE "mutex"
|
||||
#ifndef MY_ATOMIC_MODE_RWLOCKS
|
||||
#define MY_ATOMIC_MODE_RWLOCKS 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define make_atomic_add_body(S) int ## S sav; sav= *a; *a+= v; v=sav;
|
||||
#define make_atomic_fas_body(S) int ## S sav; sav= *a; *a= v; v=sav;
|
||||
#define make_atomic_cas_body(S) if ((ret= (*a == *cmp))) *a= set; else *cmp=*a;
|
||||
#define make_atomic_load_body(S) ret= *a;
|
||||
#define make_atomic_store_body(S) *a= v;
|
||||
|
||||
#endif /* ATOMIC_RWLOCK_INCLUDED */
|
||||
@@ -0,0 +1,72 @@
|
||||
/* Copyright (C) 2008 MySQL AB, 2009 Sun Microsystems, Inc
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; version 2 of the License.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
||||
|
||||
#ifndef _atomic_h_cleanup_
|
||||
#define _atomic_h_cleanup_ "atomic/solaris.h"
|
||||
|
||||
#include <atomic.h>
|
||||
|
||||
#define MY_ATOMIC_MODE "solaris-atomic"
|
||||
|
||||
#if defined(__GNUC__)
|
||||
#define atomic_typeof(T,V) __typeof__(V)
|
||||
#else
|
||||
#define atomic_typeof(T,V) T
|
||||
#endif
|
||||
|
||||
#define uintptr_t void *
|
||||
#define atomic_or_ptr_nv(X,Y) (void *)atomic_or_ulong_nv((volatile ulong_t *)X, Y)
|
||||
|
||||
#define make_atomic_cas_body(S) \
|
||||
atomic_typeof(uint ## S ## _t, *cmp) sav; \
|
||||
sav = atomic_cas_ ## S( \
|
||||
(volatile uint ## S ## _t *)a, \
|
||||
(uint ## S ## _t)*cmp, \
|
||||
(uint ## S ## _t)set); \
|
||||
if (! (ret= (sav == *cmp))) \
|
||||
*cmp= sav;
|
||||
|
||||
#define make_atomic_add_body(S) \
|
||||
int ## S nv; /* new value */ \
|
||||
nv= atomic_add_ ## S ## _nv((volatile uint ## S ## _t *)a, v); \
|
||||
v= nv - v
|
||||
|
||||
/* ------------------------------------------------------------------------ */
|
||||
|
||||
#ifdef MY_ATOMIC_MODE_DUMMY
|
||||
|
||||
#define make_atomic_load_body(S) ret= *a
|
||||
#define make_atomic_store_body(S) *a= v
|
||||
|
||||
#else /* MY_ATOMIC_MODE_DUMMY */
|
||||
|
||||
#define make_atomic_load_body(S) \
|
||||
ret= atomic_or_ ## S ## _nv((volatile uint ## S ## _t *)a, 0)
|
||||
|
||||
#define make_atomic_store_body(S) \
|
||||
(void) atomic_swap_ ## S((volatile uint ## S ## _t *)a, (uint ## S ## _t)v)
|
||||
|
||||
#endif
|
||||
|
||||
#define make_atomic_fas_body(S) \
|
||||
v= atomic_swap_ ## S((volatile uint ## S ## _t *)a, (uint ## S ## _t)v)
|
||||
|
||||
#else /* cleanup */
|
||||
|
||||
#undef uintptr_t
|
||||
#undef atomic_or_ptr_nv
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,145 @@
|
||||
#ifndef ATOMIC_X86_GCC_INCLUDED
|
||||
#define ATOMIC_X86_GCC_INCLUDED
|
||||
|
||||
/* Copyright (C) 2006 MySQL AB
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; version 2 of the License.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
||||
|
||||
/*
|
||||
XXX 64-bit atomic operations can be implemented using
|
||||
cmpxchg8b, if necessary. Though I've heard that not all 64-bit
|
||||
architectures support double-word (128-bit) cas.
|
||||
*/
|
||||
|
||||
/*
|
||||
No special support of 8 and 16 bit operations are implemented here
|
||||
currently.
|
||||
*/
|
||||
#undef MY_ATOMIC_HAS_8_AND_16
|
||||
|
||||
#ifdef __x86_64__
|
||||
# ifdef MY_ATOMIC_NO_XADD
|
||||
# define MY_ATOMIC_MODE "gcc-amd64" LOCK_prefix "-no-xadd"
|
||||
# else
|
||||
# define MY_ATOMIC_MODE "gcc-amd64" LOCK_prefix
|
||||
# endif
|
||||
#else
|
||||
# ifdef MY_ATOMIC_NO_XADD
|
||||
# define MY_ATOMIC_MODE "gcc-x86" LOCK_prefix "-no-xadd"
|
||||
# else
|
||||
# define MY_ATOMIC_MODE "gcc-x86" LOCK_prefix
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* fix -ansi errors while maintaining readability */
|
||||
#ifndef asm
|
||||
#define asm __asm__
|
||||
#endif
|
||||
|
||||
#ifndef MY_ATOMIC_NO_XADD
|
||||
#define make_atomic_add_body(S) make_atomic_add_body ## S
|
||||
#define make_atomic_cas_body(S) make_atomic_cas_body ## S
|
||||
#endif
|
||||
|
||||
#define make_atomic_add_body32 \
|
||||
asm volatile (LOCK_prefix "; xadd %0, %1;" \
|
||||
: "+r" (v), "=m" (*a) \
|
||||
: "m" (*a) \
|
||||
: "memory")
|
||||
|
||||
#define make_atomic_cas_body32 \
|
||||
__typeof__(*cmp) sav; \
|
||||
asm volatile (LOCK_prefix "; cmpxchg %3, %0; setz %2;" \
|
||||
: "=m" (*a), "=a" (sav), "=q" (ret) \
|
||||
: "r" (set), "m" (*a), "a" (*cmp) \
|
||||
: "memory"); \
|
||||
if (!ret) \
|
||||
*cmp= sav
|
||||
|
||||
#ifdef __x86_64__
|
||||
#define make_atomic_add_body64 make_atomic_add_body32
|
||||
#define make_atomic_cas_body64 make_atomic_cas_body32
|
||||
|
||||
#define make_atomic_fas_body(S) \
|
||||
asm volatile ("xchg %0, %1;" \
|
||||
: "+r" (v), "=m" (*a) \
|
||||
: "m" (*a) \
|
||||
: "memory")
|
||||
|
||||
/*
|
||||
Actually 32/64-bit reads/writes are always atomic on x86_64,
|
||||
nonetheless issue memory barriers as appropriate.
|
||||
*/
|
||||
#define make_atomic_load_body(S) \
|
||||
/* Serialize prior load and store operations. */ \
|
||||
asm volatile ("mfence" ::: "memory"); \
|
||||
ret= *a; \
|
||||
/* Prevent compiler from reordering instructions. */ \
|
||||
asm volatile ("" ::: "memory")
|
||||
#define make_atomic_store_body(S) \
|
||||
asm volatile ("; xchg %0, %1;" \
|
||||
: "=m" (*a), "+r" (v) \
|
||||
: "m" (*a) \
|
||||
: "memory")
|
||||
|
||||
#else
|
||||
/*
|
||||
Use default implementations of 64-bit operations since we solved
|
||||
the 64-bit problem on 32-bit platforms for CAS, no need to solve it
|
||||
once more for ADD, LOAD, STORE and FAS as well.
|
||||
Since we already added add32 support, we need to define add64
|
||||
here, but we haven't defined fas, load and store at all, so
|
||||
we can fallback on default implementations.
|
||||
*/
|
||||
#define make_atomic_add_body64 \
|
||||
int64 tmp=*a; \
|
||||
while (!my_atomic_cas64(a, &tmp, tmp+v)) ; \
|
||||
v=tmp;
|
||||
|
||||
/*
|
||||
On some platforms (e.g. Mac OS X and Solaris) the ebx register
|
||||
is held as a pointer to the global offset table. Thus we're not
|
||||
allowed to use the b-register on those platforms when compiling
|
||||
PIC code, to avoid this we push ebx and pop ebx. The new value
|
||||
is copied directly from memory to avoid problems with a implicit
|
||||
manipulation of the stack pointer by the push.
|
||||
|
||||
cmpxchg8b works on both 32-bit platforms and 64-bit platforms but
|
||||
the code here is only used on 32-bit platforms, on 64-bit
|
||||
platforms the much simpler make_atomic_cas_body32 will work
|
||||
fine.
|
||||
*/
|
||||
#define make_atomic_cas_body64 \
|
||||
asm volatile ("push %%ebx;" \
|
||||
"movl (%%ecx), %%ebx;" \
|
||||
"movl 4(%%ecx), %%ecx;" \
|
||||
LOCK_prefix "; cmpxchg8b %0;" \
|
||||
"setz %2; pop %%ebx" \
|
||||
: "=m" (*a), "+A" (*cmp), "=c" (ret) \
|
||||
: "c" (&set), "m" (*a) \
|
||||
: "memory", "esp")
|
||||
#endif
|
||||
|
||||
/*
|
||||
The implementation of make_atomic_cas_body32 is adaptable to
|
||||
the OS word size, so on 64-bit platforms it will automatically
|
||||
adapt to 64-bits and so it will work also on 64-bit platforms
|
||||
*/
|
||||
#define make_atomic_cas_bodyptr make_atomic_cas_body32
|
||||
|
||||
#ifdef MY_ATOMIC_MODE_DUMMY
|
||||
#define make_atomic_load_body(S) ret=*a
|
||||
#define make_atomic_store_body(S) *a=v
|
||||
#endif
|
||||
#endif /* ATOMIC_X86_GCC_INCLUDED */
|
||||
Reference in New Issue
Block a user