void assoc_delete(const char *key, const size_t nkey, const uint32_t hv) { //得到前驱结点的h_next成员地址 item **before = _hashitem_before(key, nkey, hv); if (*before) {//查找成功 item *nxt; hash_items--; /* The DTrace probe cannot be triggered as the last instruction * due to possible tail-optimization by the compiler */ MEMCACHED_ASSOC_DELETE(key, nkey, hash_items); //因为before是一个二级指针,其值为所查找item的前驱item的h_next成员地址 //所以*before指向的是所查找的item。因为before是一个二级指针,所以*before //作为左值时,可以给h_next成员变量赋值。所以下面三行代码是 //使得删除中间的item后,前后的item还能连接起来。 nxt = (*before)->h_next; (*before)->h_next = 0; /* probably pointless, but whatever. */ *before = nxt; return; } /* Note: we never actually get here. the callers don't delete things they can't find. */ assert(*before != 0); }
item *assoc_rcu_replace(const char *key, const size_t nkey, const uint32_t hv, item *it) { item **before = _hashitem_before(key, nkey, hv); if (*before) { item *nxt, *old; old = *before; nxt = (*before)->h_next; it->h_next = nxt; *before = it; return old; } return NULL; }
void assoc_delete(struct persistent_engine *engine, uint32_t hash, const char *key, const size_t nkey) { hash_item **before = _hashitem_before(engine, hash, key, nkey); if (*before) { hash_item *nxt; engine->assoc.hash_items--; /* The DTrace probe cannot be triggered as the last instruction * due to possible tail-optimization by the compiler */ nxt = (*before)->h_next; (*before)->h_next = 0; /* probably pointless, but whatever. */ *before = nxt; return; } /* Note: we never actually get here. the callers don't delete things they can't find. */ assert(*before != 0); }
void assoc_delete(const char *key, const size_t nkey, const uint32_t hv) { item **before = _hashitem_before(key, nkey, hv); if (*before) { item *nxt; // hash_items--; /* The DTrace probe cannot be triggered as the last instruction * due to possible tail-optimization by the compiler */ // MEMCACHED_ASSOC_DELETE(key, nkey, hash_items); nxt = (*before)->h_next; /* (*before)->h_next = 0; /\* probably pointless, but whatever. *\/ */ *before = nxt; return; } /* Note: we never actually get here. the callers don't delete things they can't find. */ assert(*before != 0); }