Commit 57b5e8b5 authored by Yoni Fogel's avatar Yoni Fogel

[t:2257] Modify atomic instructions

git-svn-id: file:///svn/toku/tokudb@16995 c7de825b-a66e-492c-adef-691d508d4ae1
parent fb351891
...@@ -3,33 +3,37 @@ ...@@ -3,33 +3,37 @@
#if TOKU_WINDOWS #if TOKU_WINDOWS
#define TOKU_WINDOWS_INTEL_COMPILER_HAS_ATOMIC64 0
#if TOKU_WINDOWS_INTEL_COMPILER_HAS_ATOMIC64
//Intel compiler version 11 has these functions:
#include <ia64intrin.h>
static inline int32_t static inline int32_t
toku_sync_fetch_and_add_int32(volatile int32_t *a, int32_t b) { toku_sync_fetch_and_add_int32(volatile int32_t *a, int32_t b) {
return _InterlockedExchangeAdd(a, b); return _InterlockedExchangeAdd((LONG*)a, b);
} }
static inline uint64_t static inline int32_t
toku_sync_fetch_and_add_uint64(volatile uint64_t *a, uint64_t b) { toku_sync_fetch_and_increment_int32(volatile int32_t *a) {
return _InterlockedExchangeAdd64((int64_t*)a, b); return _InterlockedIncrement((LONG*)a);
} }
#else
static inline int32_t static inline int32_t
toku_sync_fetch_and_add_int32(volatile int32_t *a, int32_t b) { toku_sync_fetch_and_decrement_int32(volatile int32_t *a) {
return _InterlockedExchangeAdd((LONG*)a, b); return _InterlockedDecrement((LONG*)a);
} }
#define TOKU_WINDOWS_MIN_SUPPORTED_IS_VISTA 0 #define TOKU_WINDOWS_MIN_SUPPORTED_IS_VISTA 0
//Vista has 64 bit atomic instruction functions.
//64 bit windows should also have it, but we're using neither right now.
#if TOKU_WINDOWS_MIN_SUPPORTED_IS_VISTA
#define TOKU_WINDOWS_HAS_FAST_ATOMIC_64 1
#else
#define TOKU_WINDOWS_HAS_FAST_ATOMIC_64 0
#endif
static inline uint64_t static inline uint64_t
toku_sync_fetch_and_add_uint64(volatile ULONGLONG *a, uint64_t b) { toku_sync_fetch_and_add_uint64(volatile uint64_t *a, uint64_t b) {
#if TOKU_WINDOWS_MIN_SUPPORTED_IS_VISTA #if TOKU_WINDOWS_MIN_SUPPORTED_IS_VISTA
//Need Vista or later for this function to exist. //Need Vista or later for this function to exist.
return _InterlockedExchangeAdd64((LONGLONG*)a, b); return _InterlockedExchangeAdd64((int64_t*)a, b);
#else #else
//Temporarily just use 32 bit atomic instructions (treat the values as 32 //Temporarily just use 32 bit atomic instructions (treat the values as 32
//bit only). For now this is ok, the values are only used in show engine //bit only). For now this is ok, the values are only used in show engine
...@@ -38,7 +42,18 @@ toku_sync_fetch_and_add_uint64(volatile ULONGLONG *a, uint64_t b) { ...@@ -38,7 +42,18 @@ toku_sync_fetch_and_add_uint64(volatile ULONGLONG *a, uint64_t b) {
#endif #endif
} }
static inline uint64_t
toku_sync_fetch_and_increment_uint64(volatile uint64_t *a) {
#if TOKU_WINDOWS_MIN_SUPPORTED_IS_VISTA
//Need Vista or later for this function to exist.
return _InterlockedIncrement64((int64_t*)a);
#else
//Temporarily just use 32 bit atomic instructions (treat the values as 32
//bit only). For now this is ok, the values are only used in show engine
//status.
return _InterlockedIncrement((LONG*)a);
#endif #endif
}
#else #else
...@@ -48,10 +63,18 @@ static inline int32_t toku_sync_fetch_and_add_int32(volatile int32_t *a, int32_t ...@@ -48,10 +63,18 @@ static inline int32_t toku_sync_fetch_and_add_int32(volatile int32_t *a, int32_t
return __sync_fetch_and_add(a, b); return __sync_fetch_and_add(a, b);
} }
static inline int32_t toku_sync_fetch_and_increment_int32(volatile int32_t *a) {
return toku_sync_fetch_and_add_int32(a, 1);
}
static inline int32_t toku_sync_fetch_and_decrement_int32(volatile int32_t *a) {
return toku_sync_fetch_and_add_int32(a, -1);
}
#if __GNUC__ && __i386__ #if __GNUC__ && __i386__
// workaround for a gcc 4.1.2 bug on 32 bit platforms. // workaround for a gcc 4.1.2 bug on 32 bit platforms.
uint64_t toku_sync_fetch_and_add_uint64(volatile uint64_t *a, uint64_t b) __attribute__((noinline)); static uint64_t toku_sync_fetch_and_add_uint64(volatile uint64_t *a, uint64_t b) __attribute__((noinline));
#else #else
...@@ -61,6 +84,10 @@ static inline uint64_t toku_sync_fetch_and_add_uint64(volatile uint64_t *a, uint ...@@ -61,6 +84,10 @@ static inline uint64_t toku_sync_fetch_and_add_uint64(volatile uint64_t *a, uint
#endif #endif
static inline uint64_t toku_sync_fetch_and_increment_uint64(volatile uint64_t *a) {
return toku_sync_fetch_and_add_uint64(a, 1);
}
#endif #endif
#endif #endif
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