static void _item_replace(struct item *it, struct item *nit) { assert(it->magic == ITEM_MAGIC); assert(!item_is_slabbed(it)); assert(nit->magic == ITEM_MAGIC); assert(!item_is_slabbed(nit)); _item_unlink(it); _item_link(nit); }
void item_insert(struct item *it, const struct bstring *key) { ASSERT(it != NULL && key != NULL); item_delete(key); _item_link(it); log_verb("insert it %p of id %"PRIu8" for key %.*s", it, it->id, key->len, key->data); }
struct item *item_alloc(uint8_t id, char *key, uint16_t nkey, int exptime, char *value, uint32_t nbyte) { struct item *it, *oit; pthread_mutex_lock(&cache_lock); it = _item_alloc(id, key, nkey, exptime, value, nbyte); if (it == NULL) return NULL; oit = _item_get(key, nkey); if (oit != NULL) _item_replace(oit, it); else { _item_link(it); } if (oit != NULL) _item_remove(oit); pthread_mutex_unlock(&cache_lock); return it; }