Skip to content

Commit

Permalink
call mutex_unlock() when we use mutex_lock()
Browse files Browse the repository at this point in the history
use both #define's when using the spinlock version of our locks. not all locks
are designed to be that way, so this doesn't touch the whole thing.
  • Loading branch information
dormando committed Jul 30, 2012
1 parent 67c9060 commit 890dfb7
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 19 deletions.
4 changes: 2 additions & 2 deletions assoc.c
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ static void *assoc_maintenance_thread(void *arg) {
pthread_cond_wait(&maintenance_cond, &cache_lock);
}

pthread_mutex_unlock(&cache_lock);
mutex_unlock(&cache_lock);
}
return NULL;
}
Expand Down Expand Up @@ -263,7 +263,7 @@ void stop_assoc_maintenance_thread() {
mutex_lock(&cache_lock);
do_run_maintenance_thread = 0;
pthread_cond_signal(&maintenance_cond);
pthread_mutex_unlock(&cache_lock);
mutex_unlock(&cache_lock);

/* Wait for the maintenance thread to stop */
pthread_join(maintenance_tid, NULL);
Expand Down
18 changes: 9 additions & 9 deletions items.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ static unsigned int sizes[LARGEST_ID];
void item_stats_reset(void) {
mutex_lock(&cache_lock);
memset(itemstats, 0, sizeof(itemstats));
pthread_mutex_unlock(&cache_lock);
mutex_unlock(&cache_lock);
}


Expand Down Expand Up @@ -125,7 +125,7 @@ item *do_item_alloc(char *key, const size_t nkey, const int flags, const rel_tim
} else if ((it = slabs_alloc(ntotal, id)) == NULL) {
if (settings.evict_to_free == 0) {
itemstats[id].outofmemory++;
pthread_mutex_unlock(&cache_lock);
mutex_unlock(&cache_lock);
return NULL;
}
itemstats[id].evicted++;
Expand Down Expand Up @@ -181,7 +181,7 @@ item *do_item_alloc(char *key, const size_t nkey, const int flags, const rel_tim
search->refcount = 1;
do_item_unlink_nolock(search, hash(ITEM_key(search), search->nkey, 0));
}
pthread_mutex_unlock(&cache_lock);
mutex_unlock(&cache_lock);
return NULL;
}

Expand All @@ -192,7 +192,7 @@ item *do_item_alloc(char *key, const size_t nkey, const int flags, const rel_tim
* been removed from the slab LRU.
*/
it->refcount = 1; /* the caller will have a reference */
pthread_mutex_unlock(&cache_lock);
mutex_unlock(&cache_lock);
it->next = it->prev = it->h_next = 0;
it->slabs_clsid = id;

Expand Down Expand Up @@ -298,7 +298,7 @@ int do_item_link(item *it, const uint32_t hv) {
assoc_insert(it, hv);
item_link_q(it);
refcount_incr(&it->refcount);
pthread_mutex_unlock(&cache_lock);
mutex_unlock(&cache_lock);

return 1;
}
Expand All @@ -316,7 +316,7 @@ void do_item_unlink(item *it, const uint32_t hv) {
item_unlink_q(it);
do_item_remove(it);
}
pthread_mutex_unlock(&cache_lock);
mutex_unlock(&cache_lock);
}

/* FIXME: Is it necessary to keep this copy/pasted code? */
Expand Down Expand Up @@ -354,7 +354,7 @@ void do_item_update(item *it) {
it->time = current_time;
item_link_q(it);
}
pthread_mutex_unlock(&cache_lock);
mutex_unlock(&cache_lock);
}
}

Expand Down Expand Up @@ -413,7 +413,7 @@ void item_stats_evictions(uint64_t *evicted) {
for (i = 0; i < LARGEST_ID; i++) {
evicted[i] = itemstats[i].evicted;
}
pthread_mutex_unlock(&cache_lock);
mutex_unlock(&cache_lock);
}

void do_item_stats(ADD_STAT add_stats, void *c) {
Expand Down Expand Up @@ -505,7 +505,7 @@ item *do_item_get(const char *key, const size_t nkey, const uint32_t hv) {
it = NULL;
}
}
pthread_mutex_unlock(&cache_lock);
mutex_unlock(&cache_lock);
int was_found = 0;

if (settings.verbose > 2) {
Expand Down
2 changes: 1 addition & 1 deletion memcached.c
Original file line number Diff line number Diff line change
Expand Up @@ -3118,7 +3118,7 @@ enum delta_result_type do_add_delta(conn *c, const char *key, const size_t nkey,
need to update the CAS on the existing item. */
mutex_lock(&cache_lock); /* FIXME */
ITEM_set_cas(it, (settings.use_cas) ? get_cas_id() : 0);
pthread_mutex_unlock(&cache_lock);
mutex_unlock(&cache_lock);

memcpy(ITEM_data(it), buf, res);
memset(ITEM_data(it) + res, ' ', it->nbytes - res - 2);
Expand Down
14 changes: 7 additions & 7 deletions thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ unsigned short refcount_incr(unsigned short *refcount) {
mutex_lock(&atomics_mutex);
(*refcount)++;
res = *refcount;
pthread_mutex_unlock(&atomics_mutex);
mutex_unlock(&atomics_mutex);
return res;
#endif
}
Expand All @@ -103,7 +103,7 @@ unsigned short refcount_decr(unsigned short *refcount) {
mutex_lock(&atomics_mutex);
(*refcount)--;
res = *refcount;
pthread_mutex_unlock(&atomics_mutex);
mutex_unlock(&atomics_mutex);
return res;
#endif
}
Expand All @@ -113,7 +113,7 @@ void item_lock(uint32_t hv) {
}

void item_unlock(uint32_t hv) {
pthread_mutex_unlock(&item_locks[hv & item_lock_mask]);
mutex_unlock(&item_locks[hv & item_lock_mask]);
}

/*
Expand Down Expand Up @@ -505,7 +505,7 @@ enum store_item_type store_item(item *item, int comm, conn* c) {
void item_flush_expired() {
mutex_lock(&cache_lock);
do_item_flush_expired();
pthread_mutex_unlock(&cache_lock);
mutex_unlock(&cache_lock);
}

/*
Expand All @@ -516,7 +516,7 @@ char *item_cachedump(unsigned int slabs_clsid, unsigned int limit, unsigned int

mutex_lock(&cache_lock);
ret = do_item_cachedump(slabs_clsid, limit, bytes);
pthread_mutex_unlock(&cache_lock);
mutex_unlock(&cache_lock);
return ret;
}

Expand All @@ -526,7 +526,7 @@ char *item_cachedump(unsigned int slabs_clsid, unsigned int limit, unsigned int
void item_stats(ADD_STAT add_stats, void *c) {
mutex_lock(&cache_lock);
do_item_stats(add_stats, c);
pthread_mutex_unlock(&cache_lock);
mutex_unlock(&cache_lock);
}

/*
Expand All @@ -535,7 +535,7 @@ void item_stats(ADD_STAT add_stats, void *c) {
void item_stats_sizes(ADD_STAT add_stats, void *c) {
mutex_lock(&cache_lock);
do_item_stats_sizes(add_stats, c);
pthread_mutex_unlock(&cache_lock);
mutex_unlock(&cache_lock);
}

/******************************* GLOBAL STATS ******************************/
Expand Down

0 comments on commit 890dfb7

Please sign in to comment.