Added atomic workaround header.
authorMonty Taylor <mordred@inaugust.com>
Thu, 3 Dec 2009 17:31:52 +0000 (09:31 -0800)
committerMonty Taylor <mordred@inaugust.com>
Thu, 3 Dec 2009 17:31:52 +0000 (09:31 -0800)
clients/ms_atomic.h [new file with mode: 0644]
clients/ms_conn.c
clients/ms_setting.c
clients/ms_setting.h
clients/ms_task.c
clients/ms_thread.c

diff --git a/clients/ms_atomic.h b/clients/ms_atomic.h
new file mode 100644 (file)
index 0000000..580afab
--- /dev/null
@@ -0,0 +1,24 @@
+#ifndef CLIENTS_MS_ATOMIC_H
+#define CLIENTS_MS_ATOMIC_H
+
+#if defined(__SUNC)
+
+#define _KERNEL
+#include <atomic.h>
+#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 */
index ad12a113b11f5015c7097d0e4345e9ea7bdc7ca6..feb6a476bbf91e2b65372d53f15ac8e9b36c1f6a 100644 (file)
@@ -20,6 +20,7 @@
 #include <arpa/inet.h>
 #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;
 
index 51f89714ac7c407f1039698444c6e2bbf3d23e70..8e02bc466e74c6ac98d8a9bd25bccf81f07598b7 100644 (file)
@@ -12,6 +12,8 @@
 #include "config.h"
 
 #include <ctype.h>
+#include <strings.h>
+
 #include "ms_setting.h"
 #include "ms_conn.h"
 
index 3cccc6ba654ae90b031ed26eaf128744651edd05..1f1f23473a55f4209e54dea22f5e810884b9caaa 100644 (file)
@@ -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;
index aadc419ebc2eddf9b4ed5b8fd04f55be2f422880..85e85331890bbc8a0bb59fb4d3b0f7610faf37af 100644 (file)
@@ -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
index 9af3a10b24bf5897150e702aa102c843a37bdb99..e1c00e0759357258339733e37d3e52960fbc9fa1 100644 (file)
@@ -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 */