X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=libmemcachedutil%2Fpool.cc;h=8d7602465da8b0de4fc635c6b1580ff164b6b70a;hb=17690735658d7b44f91579df91e31da9ae185158;hp=a0f30c5195ababb422562ffb0f0aa3cd84b4c693;hpb=c69776b7cf0d0c26b07abd83da8a797182ff6fae;p=awesomized%2Flibmemcached diff --git a/libmemcachedutil/pool.cc b/libmemcachedutil/pool.cc index a0f30c51..8d760246 100644 --- a/libmemcachedutil/pool.cc +++ b/libmemcachedutil/pool.cc @@ -59,7 +59,7 @@ struct memcached_pool_st master(master_arg), server_pool(NULL), firstfree(-1), - size(max_arg), + size(uint32_t(max_arg)), current_size(0), _owns_master(false) { @@ -86,11 +86,20 @@ struct memcached_pool_st for (int x= 0; x <= firstfree; ++x) { memcached_free(server_pool[x]); - server_pool[x] = NULL; + server_pool[x]= NULL; + } + + int error; + if ((error= pthread_mutex_destroy(&mutex)) != 0) + { + assert_vmsg(error != 0, "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)); } - pthread_mutex_destroy(&mutex); - pthread_cond_destroy(&cond); delete [] server_pool; if (_owns_master) { @@ -139,8 +148,10 @@ static bool grow_pool(memcached_pool_st* pool) bool memcached_pool_st::init(uint32_t initial) { server_pool= new (std::nothrow) memcached_st *[size]; - if (not server_pool) + if (server_pool == NULL) + { return false; + } /* Try to create the initial size of the pool. An allocation failure at @@ -241,7 +252,8 @@ memcached_st* memcached_pool_st::fetch(const struct timespec& relative_time, mem { rc= MEMCACHED_SUCCESS; - if (pthread_mutex_lock(&mutex)) + int error; + if ((error= pthread_mutex_lock(&mutex)) != 0) { rc= MEMCACHED_IN_PROGRESS; return NULL; @@ -258,7 +270,7 @@ memcached_st* memcached_pool_st::fetch(const struct timespec& relative_time, mem { if (relative_time.tv_sec == 0 and relative_time.tv_nsec == 0) { - pthread_mutex_unlock(&mutex); + error= pthread_mutex_unlock(&mutex); rc= MEMCACHED_NOTFOUND; return NULL; @@ -271,7 +283,11 @@ memcached_st* memcached_pool_st::fetch(const struct timespec& relative_time, mem int thread_ret; if ((thread_ret= pthread_cond_timedwait(&cond, &mutex, &time_to_wait)) != 0) { - pthread_mutex_unlock(&mutex); + int unlock_error; + if ((unlock_error= pthread_mutex_unlock(&mutex)) != 0) + { + assert_vmsg(error != 0, "pthread_mutex_unlock() %s", strerror(error)); + } if (thread_ret == ETIMEDOUT) { @@ -288,12 +304,20 @@ memcached_st* memcached_pool_st::fetch(const struct timespec& relative_time, mem } else if (grow_pool(this) == false) { - (void)pthread_mutex_unlock(&mutex); + int unlock_error; + if ((unlock_error= pthread_mutex_unlock(&mutex)) != 0) + { + assert_vmsg(error != 0, "pthread_mutex_unlock() %s", strerror(error)); + } + return NULL; } } while (ret == NULL); - pthread_mutex_unlock(&mutex); + if ((error= pthread_mutex_unlock(&mutex)) != 0) + { + assert_vmsg(error != 0, "pthread_mutex_unlock() %s", strerror(error)); + } return ret; } @@ -307,7 +331,8 @@ bool memcached_pool_st::release(memcached_st *released, memcached_return_t& rc) return false; } - if (pthread_mutex_lock(&mutex)) + int error; + if ((error= pthread_mutex_lock(&mutex))) { rc= MEMCACHED_IN_PROGRESS; return false; @@ -331,10 +356,15 @@ 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 :-) */ - pthread_cond_broadcast(&cond); + if ((error= pthread_cond_broadcast(&cond)) != 0) + { + assert_vmsg(error != 0, "pthread_cond_broadcast() %s", strerror(error)); + } } - (void)pthread_mutex_unlock(&mutex); + if ((error= pthread_mutex_unlock(&mutex)) != 0) + { + } return true; } @@ -417,7 +447,8 @@ memcached_return_t memcached_pool_behavior_set(memcached_pool_st *pool, return MEMCACHED_INVALID_ARGUMENTS; } - if (pthread_mutex_lock(&pool->mutex)) + int error; + if ((error= pthread_mutex_lock(&pool->mutex))) { return MEMCACHED_IN_PROGRESS; } @@ -426,7 +457,10 @@ memcached_return_t memcached_pool_behavior_set(memcached_pool_st *pool, memcached_return_t rc= memcached_behavior_set(pool->master, flag, data); if (memcached_failed(rc)) { - (void)pthread_mutex_unlock(&pool->mutex); + if ((error= pthread_mutex_unlock(&pool->mutex)) != 0) + { + assert_vmsg(error != 0, "pthread_mutex_unlock() %s", strerror(error)); + } return rc; } @@ -455,7 +489,10 @@ memcached_return_t memcached_pool_behavior_set(memcached_pool_st *pool, } } - (void)pthread_mutex_unlock(&pool->mutex); + if ((error= pthread_mutex_unlock(&pool->mutex)) != 0) + { + assert_vmsg(error != 0, "pthread_mutex_unlock() %s", strerror(error)); + } return rc; } @@ -469,14 +506,18 @@ memcached_return_t memcached_pool_behavior_get(memcached_pool_st *pool, return MEMCACHED_INVALID_ARGUMENTS; } - if (pthread_mutex_lock(&pool->mutex)) + int error; + if ((error= pthread_mutex_lock(&pool->mutex))) { return MEMCACHED_IN_PROGRESS; } *value= memcached_behavior_get(pool->master, flag); - (void)pthread_mutex_unlock(&pool->mutex); + if ((error= pthread_mutex_unlock(&pool->mutex)) != 0) + { + assert_vmsg(error != 0, "pthread_mutex_unlock() %s", strerror(error)); + } return MEMCACHED_SUCCESS; }