Add atomic_add for 64-bit integers.
Now only GCC intrinsics are used.
This commit is contained in:
@ -21,11 +21,7 @@
|
|||||||
MXS_BEGIN_DECLS
|
MXS_BEGIN_DECLS
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implementation of an atomic add operation for the GCC environment, or the
|
* Implementation of an atomic add operations for the GCC environment.
|
||||||
* X86 processor. If we are working within GNU C then we can use the GCC
|
|
||||||
* atomic add built in function, which is portable across platforms that
|
|
||||||
* implement GCC. Otherwise, this function currently supports only X86
|
|
||||||
* architecture (without further development).
|
|
||||||
*
|
*
|
||||||
* Adds a value to the contents of a location pointed to by the first parameter.
|
* Adds a value to the contents of a location pointed to by the first parameter.
|
||||||
* The add operation is atomic and the return value is the value stored in the
|
* The add operation is atomic and the return value is the value stored in the
|
||||||
@ -36,7 +32,9 @@ MXS_BEGIN_DECLS
|
|||||||
* @param value Value to be added
|
* @param value Value to be added
|
||||||
* @return The value of variable before the add occurred
|
* @return The value of variable before the add occurred
|
||||||
*/
|
*/
|
||||||
int atomic_add(int *variable, int value);
|
int atomic_add(int *variable, int value);
|
||||||
|
int64_t atomic_add_int64(int64_t *variable, int64_t value);
|
||||||
|
uint64_t atomic_add_uint64(uint64_t *variable, int64_t value);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Impose a full memory barrier
|
* @brief Impose a full memory barrier
|
||||||
|
@ -11,29 +11,23 @@
|
|||||||
* Public License.
|
* Public License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <maxscale/atomic.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @file atomic.c - Implementation of atomic operations for MaxScale
|
* @file atomic.c - Implementation of atomic operations for MaxScale
|
||||||
*
|
|
||||||
* @verbatim
|
|
||||||
* Revision History
|
|
||||||
*
|
|
||||||
* Date Who Description
|
|
||||||
* 10/06/13 Mark Riddoch Initial implementation
|
|
||||||
*
|
|
||||||
* @endverbatim
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int
|
int atomic_add(int *variable, int value)
|
||||||
atomic_add(int *variable, int value)
|
|
||||||
{
|
{
|
||||||
#ifdef __GNUC__
|
return __sync_fetch_and_add(variable, value);
|
||||||
return (int) __sync_fetch_and_add (variable, value);
|
}
|
||||||
#else
|
|
||||||
asm volatile(
|
int64_t atomic_add_int64(int64_t *variable, int64_t value)
|
||||||
"lock; xaddl %%eax, %2;"
|
{
|
||||||
:"=a" (value)
|
return __sync_fetch_and_add(variable, value);
|
||||||
: "a" (value), "m" (*variable)
|
}
|
||||||
: "memory" );
|
|
||||||
return value;
|
uint64_t atomic_add_uint64(uint64_t *variable, int64_t value)
|
||||||
#endif
|
{
|
||||||
|
return __sync_fetch_and_add(variable, value);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user