mirror of
https://codeberg.org/redict/redict.git
synced 2025-01-22 16:18:28 -05:00
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.
This commit is contained in:
parent
6eb51bf1ec
commit
de786186a5
@ -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 */
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user