#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>
# 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; \
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; \
#include <math.h>
#include "ms_stats.h"
+#include "ms_atomic.h"
#ifdef __cplusplus
extern "C" {
/* 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 */
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;