本文整理汇总了C++中STATS_LOCK函数的典型用法代码示例。如果您正苦于以下问题:C++ STATS_LOCK函数的具体用法?C++ STATS_LOCK怎么用?C++ STATS_LOCK使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了STATS_LOCK函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: do_item_unlink_nolock
/* FIXME: Is it necessary to keep this copy/pasted code? */
void do_item_unlink_nolock(item *it, const uint32_t hv) {
MEMCACHED_ITEM_UNLINK(ITEM_key(it), it->nkey, it->nbytes);
if ((it->it_flags & ITEM_LINKED) != 0) {
it->it_flags &= ~ITEM_LINKED;
STATS_LOCK();
stats.curr_bytes -= ITEM_ntotal(it);
stats.curr_items -= 1;
STATS_UNLOCK();
assoc_delete(ITEM_key(it), it->nkey, hv);
item_unlink_q(it);
do_item_remove(it);
}
}
示例2: do_item_unlink
void do_item_unlink(item *it) {
MEMCACHED_ITEM_UNLINK(ITEM_key(it), it->nbytes);
if ((it->it_flags & ITEM_LINKED) != 0) {
it->it_flags &= ~ITEM_LINKED;
STATS_LOCK();
stats.curr_bytes -= ITEM_ntotal(it);
stats.curr_items -= 1;
STATS_UNLOCK();
assoc_delete(ITEM_key(it), it->nkey);
item_unlink_q(it);
if (it->refcount == 0) item_free(it);
}
}
示例3: stats_prefix_record_get
void stats_prefix_record_get(const char *key, const size_t nkey, const bool is_hit) {
PREFIX_STATS *pfs;
STATS_LOCK();
pfs = stats_prefix_find(key, nkey);
if (NULL != pfs) {
pfs->num_gets++;
if (is_hit) {
pfs->num_hits++;
}
}
STATS_UNLOCK();
}
示例4: slab_rebalance_finish
static void slab_rebalance_finish(void) {
slabclass_t *s_cls;
slabclass_t *d_cls;
pthread_mutex_lock(&cache_lock);
pthread_mutex_lock(&slabs_lock);
s_cls = &slabclass[slab_rebal.s_clsid];
d_cls = &slabclass[slab_rebal.d_clsid];
/* At this point the stolen slab is completely clear */
//相当于把指针赋NULL值
s_cls->slab_list[s_cls->killing - 1] =
s_cls->slab_list[s_cls->slabs - 1];
s_cls->slabs--;//源slab class的内存页数减一
s_cls->killing = 0;
//内存页所有字节清零,这个也很重要的
memset(slab_rebal.slab_start, 0, (size_t)settings.item_size_max);
//将slab_rebal.slab_start指向的一个页内存馈赠给目标slab class
//slab_rebal.slab_start指向的页是从源slab class中得到的。
d_cls->slab_list[d_cls->slabs++] = slab_rebal.slab_start;
//按照目标slab class的item尺寸进行划分这个页,并且将这个页的
//内存并入到目标slab class的空闲item队列中
split_slab_page_into_freelist(slab_rebal.slab_start,
slab_rebal.d_clsid);
//清零
slab_rebal.done = 0;
slab_rebal.s_clsid = 0;
slab_rebal.d_clsid = 0;
slab_rebal.slab_start = NULL;
slab_rebal.slab_end = NULL;
slab_rebal.slab_pos = NULL;
slab_rebalance_signal = 0;//rebalance线程完成工作后,再次进入休眠状态
pthread_mutex_unlock(&slabs_lock);
pthread_mutex_unlock(&cache_lock);
STATS_LOCK();
stats.slab_reassign_running = false;
stats.slabs_moved++;
STATS_UNLOCK();
if (settings.verbose > 1) {
fprintf(stderr, "finished a slab move\n");
}
}
示例5: slab_rebalance_start
static int slab_rebalance_start(void) {
slabclass_t *s_cls;
int no_go = 0;
pthread_mutex_lock(&slabs_lock);
if (slab_rebal.s_clsid < POWER_SMALLEST ||
slab_rebal.s_clsid > power_largest ||
slab_rebal.d_clsid < SLAB_GLOBAL_PAGE_POOL ||
slab_rebal.d_clsid > power_largest ||
slab_rebal.s_clsid == slab_rebal.d_clsid)
no_go = -2;
s_cls = &slabclass[slab_rebal.s_clsid];
if (!grow_slab_list(slab_rebal.d_clsid)) {
no_go = -1;
}
if (s_cls->slabs < 2)
no_go = -3;
if (no_go != 0) {
pthread_mutex_unlock(&slabs_lock);
return no_go; /* Should use a wrapper function... */
}
/* Always kill the first available slab page as it is most likely to
* contain the oldest items
*/
slab_rebal.slab_start = s_cls->slab_list[0];
slab_rebal.slab_end = (char *)slab_rebal.slab_start +
(s_cls->size * s_cls->perslab);
slab_rebal.slab_pos = slab_rebal.slab_start;
slab_rebal.done = 0;
/* Also tells do_item_get to search for items in this slab */
slab_rebalance_signal = 2;
if (settings.verbose > 1) {
fprintf(stderr, "Started a slab rebalance\n");
}
pthread_mutex_unlock(&slabs_lock);
STATS_LOCK();
stats_state.slab_reassign_running = true;
STATS_UNLOCK();
return 0;
}
示例6: memset
static void *lru_maintainer_thread(void *arg) {
int i;
useconds_t to_sleep = MIN_LRU_MAINTAINER_SLEEP;
rel_time_t last_crawler_check = 0;
struct crawler_expired_data cdata;
memset(&cdata, 0, sizeof(struct crawler_expired_data));
pthread_mutex_init(&cdata.lock, NULL);
cdata.crawl_complete = true; // kick off the crawler.
pthread_mutex_lock(&lru_maintainer_lock);
if (settings.verbose > 2)
fprintf(stderr, "Starting LRU maintainer background thread\n");
while (do_run_lru_maintainer_thread) {
int did_moves = 0;
pthread_mutex_unlock(&lru_maintainer_lock);
usleep(to_sleep);
pthread_mutex_lock(&lru_maintainer_lock);
STATS_LOCK();
stats.lru_maintainer_juggles++;
STATS_UNLOCK();
/* We were asked to immediately wake up and poke a particular slab
* class due to a low watermark being hit */
if (lru_maintainer_check_clsid != 0) {
did_moves = lru_maintainer_juggle(lru_maintainer_check_clsid);
lru_maintainer_check_clsid = 0;
} else {
for (i = POWER_SMALLEST; i < MAX_NUMBER_OF_SLAB_CLASSES; i++) {
did_moves += lru_maintainer_juggle(i);
}
}
if (did_moves == 0) {
if (to_sleep < MAX_LRU_MAINTAINER_SLEEP)
to_sleep += 1000;
} else {
to_sleep /= 2;
if (to_sleep < MIN_LRU_MAINTAINER_SLEEP)
to_sleep = MIN_LRU_MAINTAINER_SLEEP;
}
/* Once per second at most */
if (settings.lru_crawler && last_crawler_check != current_time) {
lru_maintainer_crawler_check(&cdata);
last_crawler_check = current_time;
}
}
pthread_mutex_unlock(&lru_maintainer_lock);
if (settings.verbose > 2)
fprintf(stderr, "LRU maintainer thread stopping\n");
return NULL;
}
示例7: while
static void *assoc_maintenance_thread(void *arg) {
while (do_run_maintenance_thread) {
int ii = 0;
/* Lock the cache, and bulk move multiple buckets to the new
* hash table. */
mutex_lock(&cache_lock);
for (ii = 0; ii < hash_bulk_move && expanding; ++ii) {
item *it, *next;
int bucket;
for (it = old_hashtable[expand_bucket]; NULL != it; it = next) {
next = it->h_next;
bucket = hash(ITEM_key(it), it->nkey, 0) & hashmask(hashpower);
it->h_next = primary_hashtable[bucket];
primary_hashtable[bucket] = it;
}
old_hashtable[expand_bucket] = NULL;
expand_bucket++;
if (expand_bucket == hashsize(hashpower - 1)) {
expanding = false;
free(old_hashtable);
STATS_LOCK();
stats.hash_bytes -= hashsize(hashpower - 1) * sizeof(void *);
stats.hash_is_expanding = 0;
STATS_UNLOCK();
if (settings.verbose > 1)
fprintf(stderr, "Hash table expansion done\n");
}
}
if (!expanding) {
// added by Bin:
fprintf(stderr, "\nHash table expansion done\n");
//assoc_pre_bench();
//assoc_post_bench();
/* We are done expanding.. just wait for next invocation */
pthread_cond_wait(&maintenance_cond, &cache_lock);
}
pthread_mutex_unlock(&cache_lock);
}
return NULL;
}
示例8: slab_rebalance_start
static int slab_rebalance_start(void) {
slabclass_t *s_cls;
int no_go = 0;
pthread_mutex_lock(&slabs_lock);
if (slab_rebal.s_clsid < POWER_SMALLEST ||
slab_rebal.s_clsid > power_largest ||
slab_rebal.d_clsid < POWER_SMALLEST ||
slab_rebal.d_clsid > power_largest ||
slab_rebal.s_clsid == slab_rebal.d_clsid)
no_go = -2;
s_cls = &slabclass[slab_rebal.s_clsid];
if (!grow_slab_list(slab_rebal.d_clsid)) {
no_go = -1;
}
if (s_cls->slabs < 2)
no_go = -3;
if (no_go != 0) {
pthread_mutex_unlock(&slabs_lock);
return no_go; /* Should use a wrapper function... */
}
s_cls->killing = 1;
slab_rebal.slab_start = s_cls->slab_list[s_cls->killing - 1];
slab_rebal.slab_end = (char *)slab_rebal.slab_start +
(s_cls->size * s_cls->perslab);
slab_rebal.slab_pos = slab_rebal.slab_start;
slab_rebal.done = 0;
/* Also tells do_item_get to search for items in this slab */
slab_rebalance_signal = 2;
if (settings.verbose > 1) {
fprintf(stderr, "Started a slab rebalance\n");
}
pthread_mutex_unlock(&slabs_lock);
STATS_LOCK();
stats.slab_reassign_running = true;
STATS_UNLOCK();
return 0;
}
示例9: assoc_init
void assoc_init(const int hashtable_init) {
if (hashtable_init) {
hashpower = hashtable_init;
}
primary_hashtable = calloc(hashsize(hashpower), sizeof(void *));
if (! primary_hashtable) {
fprintf(stderr, "Failed to init hashtable.\n");
exit(EXIT_FAILURE);
}
STATS_LOCK();
stats.hash_power_level = hashpower;
stats.hash_bytes = hashsize(hashpower) * sizeof(void *);
STATS_UNLOCK();
}
示例10: do_item_unlink_nolock
/* FIXME: Is it necessary to keep this copy/pasted code? */
void do_item_unlink_nolock(item *it, const uint32_t hv) {
syslog(LOG_INFO, "[%s:%s:%d]", __FILE__, __func__, __LINE__);
MEMCACHED_ITEM_UNLINK(ITEM_key(it), it->nkey, it->nbytes);
if ((it->it_flags & ITEM_LINKED) != 0) {
it->it_flags &= ~ITEM_LINKED;
STATS_LOCK();
stats.curr_bytes -= ITEM_ntotal(it);
stats.curr_items -= 1;
STATS_UNLOCK();
assoc_delete(ITEM_key(it), it->nkey, hv);
item_unlink_q(it);
do_item_remove(it);
}
}
示例11: do_item_unlink
//将item从hashtable和LRU链中移除,而且还释放掉 item 所占的内存 (其实只是把 item 放到空闲链表中),是do_item_link的逆操作
void do_item_unlink(item *it, const uint32_t hv)
{
MEMCACHED_ITEM_UNLINK(ITEM_key(it), it->nkey, it->nbytes);
mutex_lock(&cache_lock);//执行同步
if ((it->it_flags & ITEM_LINKED) != 0) {//判断状态值,保证item还在LRU队列中
it->it_flags &= ~ITEM_LINKED;//修改状态值
STATS_LOCK();//更新统计信息
stats.curr_bytes -= ITEM_ntotal(it);
stats.curr_items -= 1;
STATS_UNLOCK();
assoc_delete(ITEM_key(it), it->nkey, hv);//从Hash表中删除
item_unlink_q(it);//将item从slabclass对应的LRU队列摘除
do_item_remove(it);//释放 item 所占的内存
}
mutex_unlock(&cache_lock);
}
示例12: do_item_unlink
void do_item_unlink(item *it, const uint32_t hv) {
syslog(LOG_INFO, "[%s:%s:%d]", __FILE__, __func__, __LINE__);
MEMCACHED_ITEM_UNLINK(ITEM_key(it), it->nkey, it->nbytes);
mutex_lock(&cache_lock);
if ((it->it_flags & ITEM_LINKED) != 0) {
it->it_flags &= ~ITEM_LINKED;//设置为非linked
STATS_LOCK();
stats.curr_bytes -= ITEM_ntotal(it);
stats.curr_items -= 1;
STATS_UNLOCK();
assoc_delete(ITEM_key(it), it->nkey, hv); //从hash表中删除
item_unlink_q(it); //从LRU链中删除
do_item_remove(it);
}
mutex_unlock(&cache_lock);
}
示例13: stats_prefix_delete
int stats_prefix_delete(const char *prefix, const size_t nprefix) {
PREFIX_STATS *curr, *next, *prev;
int hidx;
int ret = -1;
STATS_LOCK();
if (nprefix == 0) {
hidx = mc_hash(prefix, nprefix, 0) % PREFIX_HASH_SIZE;
prev = NULL;
for (curr = prefix_stats[hidx]; curr != NULL; prev = curr, curr = curr->next) {
if (curr->prefix_len == 0) break;
}
if (curr != NULL) { /* found */
if (prev == NULL) prefix_stats[hidx] = curr->next;
else prev->next = curr->next;
num_prefixes--;
total_prefix_size -= strlen(null_prefix_str);
free(curr->prefix);
free(curr);
ret = 0;
}
} else { /* nprefix > 0 */
// Full scan for sub-prefixies (we would fix it in future)
for (hidx = 0; hidx < PREFIX_HASH_SIZE; hidx++) {
prev = NULL;
for (curr = prefix_stats[hidx]; curr != NULL; curr = next) {
next = curr->next;
if ((curr->prefix_len >= nprefix && strncmp(curr->prefix, prefix, nprefix) == 0) &&
(curr->prefix_len == nprefix || *(curr->prefix+nprefix)==settings.prefix_delimiter)) {
if (prev == NULL) prefix_stats[hidx] = curr->next;
else prev->next = curr->next;
num_prefixes--;
total_prefix_size -= curr->prefix_len;
free(curr->prefix);
free(curr);
ret = 0;
} else {
prev = curr;
}
}
}
}
STATS_UNLOCK();
return ret;
}
示例14: STATS_LOCK
//输出所有信息
char *stats_prefix_dump(int *length) {
const char *format = "PREFIX %s get %llu hit %llu set %llu del %llu\r\n";
PREFIX_STATS *pfs;
char *buf;
int i, pos;
size_t size = 0, written = 0, total_written = 0;
/*
* Figure out how big the buffer needs to be. This is the sum of the
* lengths of the prefixes themselves, plus the size of one copy of
* the per-prefix output with 20-digit values for all the counts,
* plus space for the "END" at the end.
*/
STATS_LOCK();
//计算需要全部内存空间大小
size = strlen(format) + total_prefix_size +
num_prefixes * (strlen(format) - 2 /* %s */
+ 4 * (20 - 4)) /* %llu replaced by 20-digit num */
+ sizeof("END\r\n");
buf = malloc(size);
if (NULL == buf) {
perror("Can't allocate stats response: malloc");
STATS_UNLOCK();
return NULL;
}
pos = 0;
for (i = 0; i < PREFIX_HASH_SIZE; i++) {
for (pfs = prefix_stats[i]; NULL != pfs; pfs = pfs->next) {
//格式化后拷贝到指定指针处
written = snprintf(buf + pos, size-pos, format,
pfs->prefix, pfs->num_gets, pfs->num_hits,
pfs->num_sets, pfs->num_deletes);
pos += written;
total_written += written;
//判断是否拷贝正确
assert(total_written < size);
}
}
STATS_UNLOCK();
memcpy(buf + pos, "END\r\n", 6);
*length = pos + 5;
return buf;
}
示例15: assoc_init
//初始化哈希表
void assoc_init(const int hashtable_init) {
//如何设置了哈希表大小,用设置大小,否则使用默认参数。
if (hashtable_init) {
hashpower = hashtable_init;
}
//申请哈希表空间
primary_hashtable = calloc(hashsize(hashpower), sizeof(void *));
if (! primary_hashtable) {
fprintf(stderr, "Failed to init hashtable.\n");
exit(EXIT_FAILURE);
}
//记录哈希表大小和占用字节
STATS_LOCK();
stats.hash_power_level = hashpower;
stats.hash_bytes = hashsize(hashpower) * sizeof(void *);
STATS_UNLOCK();
}