summaryrefslogtreecommitdiff
path: root/cache.c
diff options
context:
space:
mode:
authordormando <dormando@rydia.net>2016-12-31 00:33:37 -0800
committerdormando <dormando@rydia.net>2017-01-07 18:22:56 -0800
commitf4c550f664553ef996d84c4b19f24449dc739c7b (patch)
treee6420a83c46fe498cc779c2f9d94310f3760dbc8 /cache.c
parentc2027ad42a727e26116e06592a3b4965731d30e7 (diff)
downloadmemcached-f4c550f664553ef996d84c4b19f24449dc739c7b.tar.gz
allow skipping thread-local cache locks
suffix cache was using a generic cache system, which uses a mutex lock. the pools are per-thread however.
Diffstat (limited to 'cache.c')
-rw-r--r--cache.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/cache.c b/cache.c
index 07a2ae0..0ccda9c 100644
--- a/cache.c
+++ b/cache.c
@@ -70,8 +70,15 @@ void cache_destroy(cache_t *cache) {
void* cache_alloc(cache_t *cache) {
void *ret;
- void *object;
pthread_mutex_lock(&cache->mutex);
+ ret = do_cache_alloc(cache);
+ pthread_mutex_unlock(&cache->mutex);
+ return ret;
+}
+
+void* do_cache_alloc(cache_t *cache) {
+ void *ret;
+ void *object;
if (cache->freecurr > 0) {
ret = cache->ptr[--cache->freecurr];
object = get_object(ret);
@@ -87,7 +94,6 @@ void* cache_alloc(cache_t *cache) {
}
}
}
- pthread_mutex_unlock(&cache->mutex);
#ifndef NDEBUG
if (object != NULL) {
@@ -105,14 +111,17 @@ void* cache_alloc(cache_t *cache) {
void cache_free(cache_t *cache, void *ptr) {
pthread_mutex_lock(&cache->mutex);
+ do_cache_free(cache, ptr);
+ pthread_mutex_unlock(&cache->mutex);
+}
+void do_cache_free(cache_t *cache, void *ptr) {
#ifndef NDEBUG
/* validate redzone... */
if (memcmp(((char*)ptr) + cache->bufsize - (2 * sizeof(redzone_pattern)),
&redzone_pattern, sizeof(redzone_pattern)) != 0) {
raise(SIGABRT);
cache_error = 1;
- pthread_mutex_unlock(&cache->mutex);
return;
}
uint64_t *pre = ptr;
@@ -120,7 +129,6 @@ void cache_free(cache_t *cache, void *ptr) {
if (*pre != redzone_pattern) {
raise(SIGABRT);
cache_error = -1;
- pthread_mutex_unlock(&cache->mutex);
return;
}
ptr = pre;
@@ -143,6 +151,5 @@ void cache_free(cache_t *cache, void *ptr) {
}
}
- pthread_mutex_unlock(&cache->mutex);
}