本文整理汇总了C++中STATS_UNLOCK函数的典型用法代码示例。如果您正苦于以下问题:C++ STATS_UNLOCK函数的具体用法?C++ STATS_UNLOCK怎么用?C++ STATS_UNLOCK使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了STATS_UNLOCK函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: conn_put
void
conn_put(struct conn *conn)
{
struct conn_base *cb = conn->cb;
ASSERT(conn->sd < 0);
ASSERT(conn->owner == NULL);
log_debug(LOG_VVERB, "put conn %p", conn);
if (cb == NULL) {
conn_free(conn);
return;
}
cb->nfree_connq++;
TAILQ_INSERT_HEAD(&cb->free_connq, conn, conn_tqe);
if (conn->client) {
cb->ncurr_cconn--;
STATS_LOCK();
ncurr_cconn --;
STATS_UNLOCK();
}
cb->ncurr_conn--;
STATS_LOCK();
ncurr_conn --;
STATS_UNLOCK();
}
示例2: do_accept_new_conns
void do_accept_new_conns(const bool do_accept) {
conn *next;
//update_event 表示将监听事件更改,0表示不监听?应该是吧。H
for (next = listen_conn; next; next = next->next) {
if (do_accept) {
update_event(next, EV_READ | EV_PERSIST);
if (listen(next->sfd, 32) != 0) {
perror("listen");
}
}
else {
update_event(next, 0);
if (listen(next->sfd, 0) != 0) {
perror("listen");
}
}
}
if (do_accept) {
STATS_LOCK();
stats.accepting_conns = true;
STATS_UNLOCK();
} else {
STATS_LOCK();
stats.accepting_conns = false;
stats.listen_disabled_num++;
STATS_UNLOCK();
allow_new_conns = false;
//倒计时,重新调用accept_new_conns来将conns重新注册监听事件
maxconns_handler(-42, 0, 0);
}
}
示例3: do_item_link
int do_item_link(item *it) {
MEMCACHED_ITEM_LINK(ITEM_key(it), it->nkey, it->nbytes);
assert((it->it_flags & (ITEM_LINKED|ITEM_SLABBED)) == 0);
assert(it->nbytes < (1024 * 1024)); /* 1MB max size */
it->it_flags |= ITEM_LINKED;
it->time = current_time;
assoc_insert(it);
#ifdef MOXI_ITEM_MALLOC
it->refcount++;
#endif
STATS_LOCK();
stats.curr_bytes += ITEM_ntotal(it);
stats.curr_items += 1;
stats.total_items += 1;
STATS_UNLOCK();
/* Allocate a new CAS ID on link. */
ITEM_set_cas(it, (settings.use_cas) ? get_cas_id() : 0);
item_link_q(it);
return 1;
}
示例4: assoc_init
void assoc_init(const int hashtable_init) {
hashpower = HASHPOWER_DEFAULT;
if (hashtable_init) {
hashpower = hashtable_init;
}
// added by Bin: comment original calloc, use our impl in bench_util
//primary_hashtable = calloc(hashsize(hashpower), sizeof(void *));
primary_hashtable = alloc(hashsize(hashpower) * sizeof(void *));
if (! primary_hashtable) {
fprintf(stderr, "Failed to init hashtable.\n");
exit(EXIT_FAILURE);
}
#ifdef COUNT_LARGEST_BUCKET
bucket_size = calloc(hashsize(hashpower), sizeof(int));
if (! bucket_size) {
fprintf(stderr, "Failed to init bucket_size.\n");
exit(EXIT_FAILURE);
}
memset(bucket_size, 0, hashsize(hashpower));
#endif
STATS_LOCK();
stats.hash_power_level = hashpower;
stats.hash_bytes = hashsize(hashpower) * sizeof(void *);
STATS_UNLOCK();
}
示例5: do_item_link
//将item插入到哈希表和LRU队列中,hv为哈希值
int do_item_link(item *it, const uint32_t hv) {
MEMCACHED_ITEM_LINK(ITEM_key(it), it->nkey, it->nbytes);
//确保这个item已经从slab分配出去并且还没插入到LRU队列中
assert((it->it_flags & (ITEM_LINKED|ITEM_SLABBED)) == 0);
mutex_lock(&cache_lock);
//加入link标记
it->it_flags |= ITEM_LINKED;
it->time = current_time;
STATS_LOCK();
stats.curr_bytes += ITEM_ntotal(it);
stats.curr_items += 1;
stats.total_items += 1;
STATS_UNLOCK();
/* Allocate a new CAS ID on link. */
ITEM_set_cas(it, (settings.use_cas) ? get_cas_id() : 0);
//插入到hash表中
assoc_insert(it, hv);
//item插入到链表中
item_link_q(it);
//引用计数加1
refcount_incr(&it->refcount);
mutex_unlock(&cache_lock);
return 1;
}
示例6: logger_init
/* Global logger thread start/init */
void logger_init(void) {
/* TODO: auto destructor when threads exit */
/* TODO: error handling */
/* init stack for iterating loggers */
logger_stack_head = 0;
logger_stack_tail = 0;
pthread_key_create(&logger_key, NULL);
if (start_logger_thread() != 0) {
abort();
}
/* This can be removed once the global stats initializer is improved */
STATS_LOCK();
stats.log_worker_dropped = 0;
stats.log_worker_written = 0;
stats.log_watcher_skipped = 0;
stats.log_watcher_sent = 0;
STATS_UNLOCK();
/* This is what adding a STDERR watcher looks like. should replace old
* "verbose" settings. */
//logger_add_watcher(NULL, 0);
return;
}
示例7: get_stats
bool get_stats(const char *stat_type, int nkey, ADD_STAT add_stats, void *c) {
bool ret = true;
if (add_stats != NULL) {
if (!stat_type) {
/* prepare general statistics for the engine */
STATS_LOCK();
APPEND_STAT("bytes", "%llu", (unsigned long long)stats.curr_bytes);
APPEND_STAT("curr_items", "%u", stats.curr_items);
APPEND_STAT("total_items", "%u", stats.total_items);
APPEND_STAT("evictions", "%llu",
(unsigned long long)stats.evictions);
APPEND_STAT("reclaimed", "%llu",
(unsigned long long)stats.reclaimed);
STATS_UNLOCK();
} else if (nz_strcmp(nkey, stat_type, "items") == 0) {
item_stats(add_stats, c);
} else if (nz_strcmp(nkey, stat_type, "slabs") == 0) {
slabs_stats(add_stats, c);
} else if (nz_strcmp(nkey, stat_type, "sizes") == 0) {
item_stats_sizes(add_stats, c);
} else {
ret = false;
}
} else {
ret = false;
}
return ret;
}
示例8: do_item_link
/* 形成了一个完成的 item 后, 就要把它放入两个数据结构中, 一是 memcached 的哈希表,
memcached 运行过程中只有一个哈希表, 二是 item 所在的 slabclass 的 LRU 队列. */
int do_item_link(item *it, const uint32_t hv) {
MEMCACHED_ITEM_LINK(ITEM_key(it), it->nkey, it->nbytes);
assert((it->it_flags & (ITEM_LINKED|ITEM_SLABBED)) == 0);
mutex_lock(&cache_lock);
it->it_flags |= ITEM_LINKED;
it->time = current_time;
STATS_LOCK();
stats.curr_bytes += ITEM_ntotal(it);
stats.curr_items += 1;
stats.total_items += 1;
STATS_UNLOCK();
/* Allocate a new CAS ID on link. */
ITEM_set_cas(it, (settings.use_cas) ? get_cas_id() : 0);
/* 把 item 放入哈希表 */
assoc_insert(it, hv);
/* 把 item 放入 LRU 队列*/
item_link_q(it);
refcount_incr(&it->refcount);
mutex_unlock(&cache_lock);
return 1;
}
示例9: do_item_link
int do_item_link(item *it) {
MEMCACHED_ITEM_LINK(ITEM_key(it), it->nbytes);
assert((it->it_flags & (ITEM_LINKED|ITEM_SLABBED)) == 0);
assert(it->nbytes < (1024 * 1024)); /* 1MB max size */
it->it_flags |= ITEM_LINKED;
it->time = current_time;
assoc_insert(it);
STATS_LOCK();
stats.curr_bytes += ITEM_ntotal(it);
stats.curr_items += 1;
stats.total_items += 1;
STATS_UNLOCK();
#ifdef USE_REPLICATION
/* Allocate a new CAS ID on link. */
if(!(it->it_flags & ITEM_REPDATA))
it->cas_id = get_cas_id();
#else
/* Allocate a new CAS ID on link. */
it->cas_id = get_cas_id();
#endif /* USE_REPLICATION */
item_link_q(it);
return 1;
}
示例10: slab_rebalance_start
static int slab_rebalance_start(void) {
slabclass_t *s_cls;
int no_go = 0;
pthread_mutex_lock(&cache_lock);
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];
//为这个目标slab class增加一个页表项都失败,那么就
//根本无法为之增加一个页了
if (!grow_slab_list(slab_rebal.d_clsid)) {
no_go = -1;
}
if (s_cls->slabs < 2)//目标slab class页数太少了,无法分一个页给别人
no_go = -3;
if (no_go != 0) {
pthread_mutex_unlock(&slabs_lock);
pthread_mutex_unlock(&cache_lock);
return no_go; /* Should use a wrapper function... */
}
//标志将源slab class的第几个内存页分给目标slab class
//这里是默认是将第一个内存页分给目标slab class
s_cls->killing = 1;
//记录要移动的页的信息。slab_start指向页的开始位置。slab_end指向页
//的结束位置。slab_pos则记录当前处理的位置(item)
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;//要rebalance线程接下来进行内存页移动
if (settings.verbose > 1) {
fprintf(stderr, "Started a slab rebalance\n");
}
pthread_mutex_unlock(&slabs_lock);
pthread_mutex_unlock(&cache_lock);
STATS_LOCK();
stats.slab_reassign_running = true;
STATS_UNLOCK();
return 0;
}
示例11: 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. */
item_lock_global();
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");
}
}
mutex_unlock(&cache_lock);
item_unlock_global();
if (!expanding) {
/* finished expanding. tell all threads to use fine-grained locks */
switch_item_lock_type(ITEM_LOCK_GRANULAR);
slabs_rebalancer_resume();
/* We are done expanding.. just wait for next invocation */
mutex_lock(&cache_lock);
started_expanding = false;
pthread_cond_wait(&maintenance_cond, &cache_lock);
/* Before doing anything, tell threads to use a global lock */
mutex_unlock(&cache_lock);
slabs_rebalancer_pause();
switch_item_lock_type(ITEM_LOCK_GLOBAL);
mutex_lock(&cache_lock);
assoc_expand();
mutex_unlock(&cache_lock);
}
}
return NULL;
}
示例12: logger_thread_sum_stats
static void logger_thread_sum_stats(struct logger_stats *ls) {
STATS_LOCK();
stats.log_worker_dropped += ls->worker_dropped;
stats.log_worker_written += ls->worker_written;
stats.log_watcher_skipped += ls->watcher_skipped;
stats.log_watcher_sent += ls->watcher_sent;
STATS_UNLOCK();
}
示例13: 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;
}
示例14: slab_rebalance_start
static int slab_rebalance_start(void) {
slabclass_t *s_cls;
slabclass_t *d_cls;
int no_go = 0;
pthread_mutex_lock(&cache_lock);
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];
d_cls = &slabclass[slab_rebal.d_clsid];
if (d_cls->end_page_ptr || s_cls->end_page_ptr ||
!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);
pthread_mutex_unlock(&cache_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);
pthread_mutex_unlock(&cache_lock);
STATS_LOCK();
stats.slab_reassign_running = true;
STATS_UNLOCK();
return 0;
}
示例15: stats_prefix_record_set
void stats_prefix_record_set(const char *key, const size_t nkey) {//记录某key被设置的次数
PREFIX_STATS *pfs;
STATS_LOCK();
pfs = stats_prefix_find(key, nkey);
if (NULL != pfs) {
pfs->num_sets++; //写操作增加一次
}
STATS_UNLOCK();
}