/********************************* ITEM ACCESS *******************************/
/*
* Allocates a new item.
*/
item *item_alloc(char *key, size_t nkey, int flags, rel_time_t exptime, int nbytes) {
item *it;
pthread_mutex_lock(&cache_lock);
it = do_item_alloc(key, nkey, flags, exptime, nbytes);
pthread_mutex_unlock(&cache_lock);
return it;
}
/*
* Returns an item if it hasn't been marked as expired,
* lazy-expiring as needed.
*/
item *item_get(const char *key, const size_t nkey) {
item *it;
pthread_mutex_lock(&cache_lock);
it = do_item_get(key, nkey);
pthread_mutex_unlock(&cache_lock);
return it;
}
/*
* Links an item into the LRU and hashtable.
*/
int item_link(item *item) {
int ret;
pthread_mutex_lock(&cache_lock);
ret = do_item_link(item);
pthread_mutex_unlock(&cache_lock);
return ret;
}
/*
* Decrements the reference count on an item and adds it to the freelist if
* needed.
*/
void item_remove(item *item) {
pthread_mutex_lock(&cache_lock);
do_item_remove(item);
pthread_mutex_unlock(&cache_lock);
}
/*
* Replaces one item with another in the hashtable.
* Unprotected by a mutex lock since the core server does not require
* it to be thread-safe.
*/
int item_replace(item *old_it, item *new_it) {
return do_item_replace(old_it, new_it);
}
/*
* Unlinks an item from the LRU and hashtable.
*/
void item_unlink(item *item) {
pthread_mutex_lock(&cache_lock);
do_item_unlink(item);
pthread_mutex_unlock(&cache_lock);
}
/*
* Moves an item to the back of the LRU queue.
*/
void item_update(item *item) {
pthread_mutex_lock(&cache_lock);
do_item_update(item);
pthread_mutex_unlock(&cache_lock);
}
/*
* Does arithmetic on a numeric item value.
*/
enum delta_result_type add_delta(conn *c, item *item, int incr,
const int64_t delta, char *buf) {
enum delta_result_type ret;
pthread_mutex_lock(&cache_lock);
ret = do_add_delta(c, item, incr, delta, buf);
pthread_mutex_unlock(&cache_lock);
return ret;
}
/*
* Stores an item in the cache (high level, obeys set/add/replace semantics)
*/
enum store_item_type store_item(item *item, int comm, conn* c) {
enum store_item_type ret;
pthread_mutex_lock(&cache_lock);
ret = do_store_item(item, comm, c);
pthread_mutex_unlock(&cache_lock);
return ret;
}
/*
* Flushes expired items after a flush_all call
*/
void item_flush_expired() {
pthread_mutex_lock(&cache_lock);
do_item_flush_expired();
pthread_mutex_unlock(&cache_lock);
}
/*
* Dumps part of the cache
*/
char *item_cachedump(unsigned int slabs_clsid, unsigned int limit, unsigned int *bytes) {
char *ret;
pthread_mutex_lock(&cache_lock);
ret = do_item_cachedump(slabs_clsid, limit, bytes);
pthread_mutex_unlock(&cache_lock);
return ret;
}
|