memaslap: fix atomics
authorMichael Wallner <mike@php.net>
Thu, 6 Feb 2020 13:22:13 +0000 (14:22 +0100)
committerMichael Wallner <mike@php.net>
Thu, 6 Feb 2020 13:22:13 +0000 (14:22 +0100)
.gitignore
clients/ms_atomic.h
clients/ms_conn.c
clients/ms_memslap.h
clients/ms_setting.h
clients/ms_thread.c

index 7b63c298a4015aa3f6ae036192a9a26639253774..6febe3844aed8e41210746bbb9acccc1b3418546 100644 (file)
@@ -168,3 +168,4 @@ tests/var/
 tmp_chroot
 unittests/unittests
 venv/
+/infer-out/
index 045f0a6146c07e0ea68915b1972fd3f6aabe36ef..6ec990c0551930c8e03e6e7f8cbe454fc9da9080 100644 (file)
 #ifndef CLIENTS_MS_ATOMIC_H
 #define CLIENTS_MS_ATOMIC_H
 
+#if HAVE_C_STDATOMIC
+# define ATOMIC _Atomic
+#else
+# define ATOMIC volatile
+#endif
+
 #if defined(__SUNPRO_C)
 # define _KERNEL
 # include <atomic.h>
@@ -57,7 +63,7 @@
 # define atomic_dec_size(X) atomic_fetch_sub(X, 1)
 /* The same as above, but these return the new value instead of void */
 # define ATOMIC_ADD_FETCH_DECL(T) \
-static inline T atomic_add_fetch_##T(volatile T *ptr, T add) { \
+static inline T atomic_add_fetch_##T(ATOMIC T *ptr, T add) { \
        T des, cur = atomic_load(ptr); \
        do { \
                des = cur + add; \
@@ -65,7 +71,7 @@ static inline T atomic_add_fetch_##T(volatile T *ptr, T add) { \
        return des; \
 }
 # define ATOMIC_SUB_FETCH_DECL(T) \
-T atomic_sub_fetch_##T(volatile T *ptr) { \
+T atomic_sub_fetch_##T(ATOMIC T *ptr) { \
        T des, cur = atomic_load(ptr); \
        do { \
                des = cur - 1; \
index 9c4b7f534af6cc28934708d5f7e06e1aa63b51f2..71353d5b4806defd0b7f93bc6f611fbd775f130a 100644 (file)
@@ -66,7 +66,7 @@
 static uint64_t key_prefix_seq= KEY_PREFIX_BASE;
 
 /* global increasing counter, generating request id for UDP */
-static volatile uint32_t udp_request_id= 0;
+static ATOMIC uint32_t udp_request_id= 0;
 
 extern pthread_key_t ms_thread_key;
 
index 1c1b29ebe7f38163ab84f745aad80710bdb6bc35..9575a8107f952f6315bdca4121982919d8edeb28 100644 (file)
@@ -25,6 +25,7 @@
 #include <math.h>
 
 #include "ms_stats.h"
+#include "ms_atomic.h"
 
 #ifdef __cplusplus
 extern "C" {
@@ -71,22 +72,22 @@ typedef struct statistic
 /* global status statistic structure */
 typedef struct stats
 {
-  volatile uint32_t active_conns;   /* active connections */
-  size_t bytes_read;              /* read bytes */
-  size_t bytes_written;           /* written bytes */
-  size_t obj_bytes;               /* object bytes */
-  size_t pre_cmd_get;             /* previous total get command count */
-  size_t pre_cmd_set;             /* previous total set command count */
-  size_t cmd_get;                 /* current total get command count */
-  size_t cmd_set;                 /* current total set command count */
-  size_t get_misses;              /* total objects of get miss */
-  size_t vef_miss;                /* total objects of verification miss  */
-  size_t vef_failed;              /* total objects of verification failed  */
-  size_t unexp_unget;             /* total objects which is unexpired but not get */
-  size_t exp_get;                 /* total objects which is expired but get  */
-  volatile size_t pkt_disorder;            /* disorder packages of UDP */
-  size_t pkt_drop;                /* packages dropped of UDP */
-  size_t udp_timeout;             /* how many times timeout of UDP happens */
+  ATOMIC uint32_t active_conns;   /* active connections */
+  ATOMIC size_t bytes_read;       /* read bytes */
+  ATOMIC size_t bytes_written;    /* written bytes */
+  ATOMIC size_t obj_bytes;        /* object bytes */
+  ATOMIC size_t pre_cmd_get;      /* previous total get command count */
+  ATOMIC size_t pre_cmd_set;      /* previous total set command count */
+  ATOMIC size_t cmd_get;          /* current total get command count */
+  ATOMIC size_t cmd_set;          /* current total set command count */
+  ATOMIC size_t get_misses;       /* total objects of get miss */
+  ATOMIC size_t vef_miss;         /* total objects of verification miss  */
+  ATOMIC size_t vef_failed;       /* total objects of verification failed  */
+  ATOMIC size_t unexp_unget;      /* total objects which is unexpired but not get */
+  ATOMIC size_t exp_get;          /* total objects which is expired but get  */
+  ATOMIC size_t pkt_disorder;     /* disorder packages of UDP */
+  ATOMIC size_t pkt_drop;         /* packages dropped of UDP */
+  ATOMIC size_t udp_timeout;      /* how many times timeout of UDP happens */
 } ms_stats_t;
 
 /* lock adapter */
index 4bab2b99d259e3b1b15fb4431778a7ea4000a83a..9db956c962c895b7701a6cd825de0102105aa71b 100644 (file)
@@ -53,8 +53,8 @@ typedef struct mcd_server
   int srv_port;                                     /* server port */
 
   /* for calculating how long the server disconnects */
-  volatile uint32_t disconn_cnt;                    /* number of disconnections count */
-  volatile uint32_t reconn_cnt;                     /* number of reconnections count */
+  ATOMIC uint32_t disconn_cnt;                    /* number of disconnections count */
+  ATOMIC uint32_t reconn_cnt;                     /* number of reconnections count */
   struct timeval disconn_time;                      /* start time of disconnection */
   struct timeval reconn_time;                       /* end time of reconnection */
 } ms_mcd_server_t;
index 264cca7c3a0e162b2d6a1083ca9dc77c33915fff..f9f52bfbe7c2eb5dd0b9bfb5019d084d78a73127 100644 (file)
@@ -184,7 +184,7 @@ static int ms_setup_thread(ms_thread_ctx_t *thread_ctx)
   ms_thread->thread_ctx= thread_ctx;
   ms_thread->nactive_conn= thread_ctx->nconns;
   ms_thread->initialized= false;
-  static volatile uint32_t cnt= 0;
+  static ATOMIC uint32_t cnt= 0;
 
   gettimeofday(&ms_thread->startup_time, NULL);