From: Monty Taylor Date: Thu, 3 Dec 2009 17:31:52 +0000 (-0800) Subject: Added atomic workaround header. X-Git-Tag: 0.37~81^2~3 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=88642cefb9f215ee7dd2be926af1e8fdbe64b963;p=awesomized%2Flibmemcached Added atomic workaround header. --- diff --git a/clients/ms_atomic.h b/clients/ms_atomic.h new file mode 100644 index 00000000..580afabf --- /dev/null +++ b/clients/ms_atomic.h @@ -0,0 +1,24 @@ +#ifndef CLIENTS_MS_ATOMIC_H +#define CLIENTS_MS_ATOMIC_H + +#if defined(__SUNC) + +#define _KERNEL +#include +#undef _KERNEL + +inline int32_t __sync_add_and_fetch(volatile int32_t* ptr, int32_t val) +{ + (val == 1) ? atomic_inc_32((volatile uint32_t*)ptr) : atomic_add_32((volatile uint32_t*)ptr, val); + return *ptr; +} + + +inline uint32_t __sync_sub_and_fetch(volatile uint32_t* ptr, uint32_t val) +{ + (val == 1) ? atomic_dec_32(ptr) : atomic_add_32(ptr, 0-(int32_t)val); + return *ptr; +} + +#endif /* defined(__SUNC) */ +#endif /* CLIENTS_MS_ATOMIC_H */ diff --git a/clients/ms_conn.c b/clients/ms_conn.c index ad12a113..feb6a476 100644 --- a/clients/ms_conn.c +++ b/clients/ms_conn.c @@ -20,6 +20,7 @@ #include #include "ms_setting.h" #include "ms_thread.h" +#include "ms_atomic.h" /* for network write */ #define TRANSMIT_COMPLETE 0 @@ -39,7 +40,7 @@ static uint64_t key_prefix_seq= KEY_PREFIX_BASE; /* global increasing counter, generating request id for UDP */ -static int udp_request_id= 0; +static int32_t udp_request_id= 0; extern __thread ms_thread_t ms_thread; diff --git a/clients/ms_setting.c b/clients/ms_setting.c index 51f89714..8e02bc46 100644 --- a/clients/ms_setting.c +++ b/clients/ms_setting.c @@ -12,6 +12,8 @@ #include "config.h" #include +#include + #include "ms_setting.h" #include "ms_conn.h" diff --git a/clients/ms_setting.h b/clients/ms_setting.h index 3cccc6ba..1f1f2347 100644 --- a/clients/ms_setting.h +++ b/clients/ms_setting.h @@ -53,8 +53,8 @@ typedef struct mcd_sever int srv_port; /* server port */ /* for calculating how long the server disconnects */ - int disconn_cnt; /* number of disconnections count */ - int reconn_cnt; /* number of reconnections count */ + int32_t disconn_cnt; /* number of disconnections count */ + int32_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; diff --git a/clients/ms_task.c b/clients/ms_task.c index aadc419e..85e85331 100644 --- a/clients/ms_task.c +++ b/clients/ms_task.c @@ -13,6 +13,7 @@ #include "ms_thread.h" #include "ms_setting.h" +#include "ms_atomic.h" /* command distribution adjustment cycle */ #define CMD_DISTR_ADJUST_CYCLE 1000 diff --git a/clients/ms_thread.c b/clients/ms_thread.c index 9af3a10b..e1c00e07 100644 --- a/clients/ms_thread.c +++ b/clients/ms_thread.c @@ -13,6 +13,7 @@ #include "ms_thread.h" #include "ms_setting.h" +#include "ms_atomic.h" /* global variable */ __thread ms_thread_t ms_thread; /* each thread with a private ms_thread structure */