Skip to content

Commit

Permalink
shorten lock for item allocation more
Browse files Browse the repository at this point in the history
after pulling an item off of the LRU, there's no reason to hold the cache lock
while we initialize a few values and memcpy some junk.
  • Loading branch information
dormando committed Dec 13, 2011
1 parent ee486ab commit 7066273
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions items.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,14 @@ item *do_item_alloc(char *key, const size_t nkey, const int flags, const rel_tim
}

assert(it->slabs_clsid == 0);
assert(it != heads[id]);

/* Item initialization can happen outside of the lock; the item's already
* been removed from the slab LRU.
*/
pthread_mutex_unlock(&cache_lock);
it->slabs_clsid = id;

assert(it != heads[it->slabs_clsid]);

it->next = it->prev = it->h_next = 0;
it->refcount = 1; /* the caller will have a reference */
DEBUG_REFCNT(it, '*');
Expand All @@ -196,7 +199,6 @@ item *do_item_alloc(char *key, const size_t nkey, const int flags, const rel_tim
it->exptime = exptime;
memcpy(ITEM_suffix(it), suffix, (size_t)nsuffix);
it->nsuffix = nsuffix;
pthread_mutex_unlock(&cache_lock);
return it;
}

Expand Down

0 comments on commit 7066273

Please sign in to comment.