summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2017-05-10 09:33:49 +0200
committerantirez <antirez@gmail.com>2017-05-10 09:33:49 +0200
commitde786186a5a0cd15aa86a2127647fb9c758bc405 (patch)
tree6b64f7fe124665b2b0f4379d0a06e87f5259abde
parent6eb51bf1ecd114f97a0666d4027b600e5124f42c (diff)
downloadredis-de786186a5a0cd15aa86a2127647fb9c758bc405.tar.gz
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.
-rw-r--r--src/atomicvar.h17
-rw-r--r--src/server.c2
2 files changed, 13 insertions, 6 deletions
diff --git a/src/atomicvar.h b/src/atomicvar.h
index 9b5628ad6..84a5bbc5c 100644
--- a/src/atomicvar.h
+++ b/src/atomicvar.h
@@ -62,7 +62,13 @@
#ifndef __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. */
#define atomicIncr(var,count) __atomic_add_fetch(&var,(count),__ATOMIC_RELAXED)
@@ -74,6 +80,7 @@
dstvar = __atomic_load_n(&var,__ATOMIC_RELAXED); \
} while(0)
#define atomicSet(var,value) __atomic_store_n(&var,value,__ATOMIC_RELAXED)
+#define REDIS_ATOMIC_API "atomic-builtin"
#elif defined(HAVE_ATOMIC)
/* Implementation using __sync macros. */
@@ -89,6 +96,7 @@
#define atomicSet(var,value) do { \
while(!__sync_bool_compare_and_swap(&var,var,value)); \
} while(0)
+#define REDIS_ATOMIC_API "sync-builtin"
#else
/* Implementation using pthread mutex. */
@@ -98,31 +106,28 @@
var += (count); \
pthread_mutex_unlock(&var ## _mutex); \
} while(0)
-
#define atomicGetIncr(var,oldvalue_var,count) do { \
pthread_mutex_lock(&var ## _mutex); \
oldvalue_var = var; \
var += (count); \
pthread_mutex_unlock(&var ## _mutex); \
} while(0)
-
#define atomicDecr(var,count) do { \
pthread_mutex_lock(&var ## _mutex); \
var -= (count); \
pthread_mutex_unlock(&var ## _mutex); \
} while(0)
-
#define atomicGet(var,dstvar) do { \
pthread_mutex_lock(&var ## _mutex); \
dstvar = var; \
pthread_mutex_unlock(&var ## _mutex); \
} while(0)
-
#define atomicSet(var,value) do { \
pthread_mutex_lock(&var ## _mutex); \
var = value; \
pthread_mutex_unlock(&var ## _mutex); \
} while(0)
-#endif
+#define REDIS_ATOMIC_API "pthread-mutex"
+#endif
#endif /* __ATOMIC_VAR_H */
diff --git a/src/server.c b/src/server.c
index 0ef3168fe..75268b8a4 100644
--- a/src/server.c
+++ b/src/server.c
@@ -2827,6 +2827,7 @@ sds genRedisInfoString(char *section) {
"os:%s %s %s\r\n"
"arch_bits:%d\r\n"
"multiplexing_api:%s\r\n"
+ "atomicvar_api:%s\r\n"
"gcc_version:%d.%d.%d\r\n"
"process_id:%ld\r\n"
"run_id:%s\r\n"
@@ -2845,6 +2846,7 @@ sds genRedisInfoString(char *section) {
name.sysname, name.release, name.machine,
server.arch_bits,
aeGetApiName(),
+ REDIS_ATOMIC_API,
#ifdef __GNUC__
__GNUC__,__GNUC_MINOR__,__GNUC_PATCHLEVEL__,
#else