Commit de786186 authored by antirez's avatar antirez
Browse files

atomicvar.h: show used API in INFO. Add macro to force __sync builtin.

The __sync builtin can be correctly detected by Helgrind so to force it
is useful for testing. The API in the INFO output can be useful for
debugging after problems are reported.
parent 6eb51bf1
...@@ -62,7 +62,13 @@ ...@@ -62,7 +62,13 @@
#ifndef __ATOMIC_VAR_H #ifndef __ATOMIC_VAR_H
#define __ATOMIC_VAR_H #define __ATOMIC_VAR_H
#if defined(__ATOMIC_RELAXED) && !defined(__sun) && (!defined(__clang__) || !defined(__APPLE__) || __apple_build_version__ > 4210057) /* To test Redis with Helgrind (a Valgrind tool) it is useful to define
* the following macro, so that __sync macros are used: those can be detected
* by Helgrind (even if they are less efficient) so that no false positive
* is reported. */
// #define __ATOMIC_VAR_FORCE_SYNC_MACROS
#if !defined(__ATOMIC_VAR_FORCE_SYNC_MACROS) && defined(__ATOMIC_RELAXED) && !defined(__sun) && (!defined(__clang__) || !defined(__APPLE__) || __apple_build_version__ > 4210057)
/* Implementation using __atomic macros. */ /* Implementation using __atomic macros. */
#define atomicIncr(var,count) __atomic_add_fetch(&var,(count),__ATOMIC_RELAXED) #define atomicIncr(var,count) __atomic_add_fetch(&var,(count),__ATOMIC_RELAXED)
...@@ -74,6 +80,7 @@ ...@@ -74,6 +80,7 @@
dstvar = __atomic_load_n(&var,__ATOMIC_RELAXED); \ dstvar = __atomic_load_n(&var,__ATOMIC_RELAXED); \
} while(0) } while(0)
#define atomicSet(var,value) __atomic_store_n(&var,value,__ATOMIC_RELAXED) #define atomicSet(var,value) __atomic_store_n(&var,value,__ATOMIC_RELAXED)
#define REDIS_ATOMIC_API "atomic-builtin"
#elif defined(HAVE_ATOMIC) #elif defined(HAVE_ATOMIC)
/* Implementation using __sync macros. */ /* Implementation using __sync macros. */
...@@ -89,6 +96,7 @@ ...@@ -89,6 +96,7 @@
#define atomicSet(var,value) do { \ #define atomicSet(var,value) do { \
while(!__sync_bool_compare_and_swap(&var,var,value)); \ while(!__sync_bool_compare_and_swap(&var,var,value)); \
} while(0) } while(0)
#define REDIS_ATOMIC_API "sync-builtin"
#else #else
/* Implementation using pthread mutex. */ /* Implementation using pthread mutex. */
...@@ -98,31 +106,28 @@ ...@@ -98,31 +106,28 @@
var += (count); \ var += (count); \
pthread_mutex_unlock(&var ## _mutex); \ pthread_mutex_unlock(&var ## _mutex); \
} while(0) } while(0)
#define atomicGetIncr(var,oldvalue_var,count) do { \ #define atomicGetIncr(var,oldvalue_var,count) do { \
pthread_mutex_lock(&var ## _mutex); \ pthread_mutex_lock(&var ## _mutex); \
oldvalue_var = var; \ oldvalue_var = var; \
var += (count); \ var += (count); \
pthread_mutex_unlock(&var ## _mutex); \ pthread_mutex_unlock(&var ## _mutex); \
} while(0) } while(0)
#define atomicDecr(var,count) do { \ #define atomicDecr(var,count) do { \
pthread_mutex_lock(&var ## _mutex); \ pthread_mutex_lock(&var ## _mutex); \
var -= (count); \ var -= (count); \
pthread_mutex_unlock(&var ## _mutex); \ pthread_mutex_unlock(&var ## _mutex); \
} while(0) } while(0)
#define atomicGet(var,dstvar) do { \ #define atomicGet(var,dstvar) do { \
pthread_mutex_lock(&var ## _mutex); \ pthread_mutex_lock(&var ## _mutex); \
dstvar = var; \ dstvar = var; \
pthread_mutex_unlock(&var ## _mutex); \ pthread_mutex_unlock(&var ## _mutex); \
} while(0) } while(0)
#define atomicSet(var,value) do { \ #define atomicSet(var,value) do { \
pthread_mutex_lock(&var ## _mutex); \ pthread_mutex_lock(&var ## _mutex); \
var = value; \ var = value; \
pthread_mutex_unlock(&var ## _mutex); \ pthread_mutex_unlock(&var ## _mutex); \
} while(0) } while(0)
#endif #define REDIS_ATOMIC_API "pthread-mutex"
#endif
#endif /* __ATOMIC_VAR_H */ #endif /* __ATOMIC_VAR_H */
...@@ -2827,6 +2827,7 @@ sds genRedisInfoString(char *section) { ...@@ -2827,6 +2827,7 @@ sds genRedisInfoString(char *section) {
"os:%s %s %s\r\n" "os:%s %s %s\r\n"
"arch_bits:%d\r\n" "arch_bits:%d\r\n"
"multiplexing_api:%s\r\n" "multiplexing_api:%s\r\n"
"atomicvar_api:%s\r\n"
"gcc_version:%d.%d.%d\r\n" "gcc_version:%d.%d.%d\r\n"
"process_id:%ld\r\n" "process_id:%ld\r\n"
"run_id:%s\r\n" "run_id:%s\r\n"
...@@ -2845,6 +2846,7 @@ sds genRedisInfoString(char *section) { ...@@ -2845,6 +2846,7 @@ sds genRedisInfoString(char *section) {
name.sysname, name.release, name.machine, name.sysname, name.release, name.machine,
server.arch_bits, server.arch_bits,
aeGetApiName(), aeGetApiName(),
REDIS_ATOMIC_API,
#ifdef __GNUC__ #ifdef __GNUC__
__GNUC__,__GNUC_MINOR__,__GNUC_PATCHLEVEL__, __GNUC__,__GNUC_MINOR__,__GNUC_PATCHLEVEL__,
#else #else
......
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