fix MinGW
[m6w6/libmemcached] / src / libmemcachedutil / pool.cc
index 448526519d3331f7d33406c89531d3a3df7770cf..759b9576c66fe345d1b8fda089092592e077ac9e 100644 (file)
@@ -17,6 +17,8 @@
 
 #include <cassert>
 #include <cerrno>
+#include <cstring>
+#include <ctime>
 #include <pthread.h>
 #include <memory>
 
@@ -44,7 +46,9 @@ struct memcached_pool_st {
     _timeout.tv_nsec = 0;
   }
 
-  const struct timespec &timeout() const { return _timeout; }
+  const struct timespec &timeout() const {
+    return _timeout;
+  }
 
   bool release(memcached_st *, memcached_return_t &rc);
 
@@ -60,12 +64,12 @@ struct memcached_pool_st {
     }
 
     int error;
-    if ((error = pthread_mutex_destroy(&mutex)) != 0) {
-      assert_vmsg(error != 0, "pthread_mutex_destroy() %s(%d)", strerror(error), error);
+    if ((error = pthread_mutex_destroy(&mutex))) {
+      assert_vmsg(error, "pthread_mutex_destroy() %s(%d)", strerror(error), error);
     }
 
-    if ((error = pthread_cond_destroy(&cond)) != 0) {
-      assert_vmsg(error != 0, "pthread_cond_destroy() %s", strerror(error));
+    if ((error = pthread_cond_destroy(&cond))) {
+      assert_vmsg(error, "pthread_cond_destroy() %s", strerror(error));
     }
 
     delete[] server_pool;
@@ -74,13 +78,17 @@ struct memcached_pool_st {
     }
   }
 
-  void increment_version() { ++master->configure.version; }
+  void increment_version() {
+    ++master->configure.version;
+  }
 
   bool compare_version(const memcached_st *arg) const {
     return (arg->configure.version == version());
   }
 
-  int32_t version() const { return master->configure.version; }
+  int32_t version() const {
+    return master->configure.version;
+  }
 };
 
 /**
@@ -194,7 +202,7 @@ memcached_st *memcached_pool_st::fetch(const struct timespec &relative_time,
   rc = MEMCACHED_SUCCESS;
 
   int error;
-  if ((error = pthread_mutex_lock(&mutex)) != 0) {
+  if ((error = pthread_mutex_lock(&mutex))) {
     rc = MEMCACHED_IN_PROGRESS;
     return NULL;
   }
@@ -216,10 +224,10 @@ memcached_st *memcached_pool_st::fetch(const struct timespec &relative_time,
       time_to_wait.tv_nsec = relative_time.tv_nsec;
 
       int thread_ret;
-      if ((thread_ret = pthread_cond_timedwait(&cond, &mutex, &time_to_wait)) != 0) {
+      if ((thread_ret = pthread_cond_timedwait(&cond, &mutex, &time_to_wait))) {
         int unlock_error;
-        if ((unlock_error = pthread_mutex_unlock(&mutex)) != 0) {
-          assert_vmsg(error != 0, "pthread_mutex_unlock() %s", strerror(error));
+        if ((unlock_error = pthread_mutex_unlock(&mutex))) {
+          assert_vmsg(error, "pthread_mutex_unlock() %s", strerror(error));
         }
 
         if (thread_ret == ETIMEDOUT) {
@@ -233,16 +241,16 @@ memcached_st *memcached_pool_st::fetch(const struct timespec &relative_time,
       }
     } else if (grow_pool(this) == false) {
       int unlock_error;
-      if ((unlock_error = pthread_mutex_unlock(&mutex)) != 0) {
-        assert_vmsg(error != 0, "pthread_mutex_unlock() %s", strerror(error));
+      if ((unlock_error = pthread_mutex_unlock(&mutex))) {
+        assert_vmsg(error, "pthread_mutex_unlock() %s", strerror(error));
       }
 
       return NULL;
     }
   } while (ret == NULL);
 
-  if ((error = pthread_mutex_unlock(&mutex)) != 0) {
-    assert_vmsg(error != 0, "pthread_mutex_unlock() %s", strerror(error));
+  if ((error = pthread_mutex_unlock(&mutex))) {
+    assert_vmsg(error, "pthread_mutex_unlock() %s", strerror(error));
   }
 
   return ret;
@@ -277,12 +285,12 @@ bool memcached_pool_st::release(memcached_st *released, memcached_return_t &rc)
 
   if (firstfree == 0 and current_size == size) {
     /* we might have people waiting for a connection.. wake them up :-) */
-    if ((error = pthread_cond_broadcast(&cond)) != 0) {
-      assert_vmsg(error != 0, "pthread_cond_broadcast() %s", strerror(error));
+    if ((error = pthread_cond_broadcast(&cond))) {
+      assert_vmsg(error, "pthread_cond_broadcast() %s", strerror(error));
     }
   }
 
-  if ((error = pthread_mutex_unlock(&mutex)) != 0) {
+  if ((error = pthread_mutex_unlock(&mutex))) {
   }
 
   return true;
@@ -356,8 +364,8 @@ memcached_return_t memcached_pool_behavior_set(memcached_pool_st *pool, memcache
   /* update the master */
   memcached_return_t rc = memcached_behavior_set(pool->master, flag, data);
   if (memcached_failed(rc)) {
-    if ((error = pthread_mutex_unlock(&pool->mutex)) != 0) {
-      assert_vmsg(error != 0, "pthread_mutex_unlock() %s", strerror(error));
+    if ((error = pthread_mutex_unlock(&pool->mutex))) {
+      assert_vmsg(error, "pthread_mutex_unlock() %s", strerror(error));
     }
     return rc;
   }
@@ -382,8 +390,8 @@ memcached_return_t memcached_pool_behavior_set(memcached_pool_st *pool, memcache
     }
   }
 
-  if ((error = pthread_mutex_unlock(&pool->mutex)) != 0) {
-    assert_vmsg(error != 0, "pthread_mutex_unlock() %s", strerror(error));
+  if ((error = pthread_mutex_unlock(&pool->mutex))) {
+    assert_vmsg(error, "pthread_mutex_unlock() %s", strerror(error));
   }
 
   return rc;
@@ -402,8 +410,8 @@ memcached_return_t memcached_pool_behavior_get(memcached_pool_st *pool, memcache
 
   *value = memcached_behavior_get(pool->master, flag);
 
-  if ((error = pthread_mutex_unlock(&pool->mutex)) != 0) {
-    assert_vmsg(error != 0, "pthread_mutex_unlock() %s", strerror(error));
+  if ((error = pthread_mutex_unlock(&pool->mutex))) {
+    assert_vmsg(error, "pthread_mutex_unlock() %s", strerror(error));
   }
 
   return MEMCACHED_SUCCESS;