コード例 #1
0
ファイル: mc_thread.c プロジェクト: shantanusharma/twemcache
/*
 * Setup a thread's stats-related fields.
 *
 * Return success status as a boolean.
 */
static rstatus_t
thread_setup_stats(struct thread_worker *t)
{
    err_t err;

    t->stats_mutex = mc_alloc(sizeof(*t->stats_mutex));
    if (t->stats_mutex == NULL) {
        return MC_ENOMEM;
    }

    err = pthread_mutex_init(t->stats_mutex, NULL);
    if (err != 0) {
        log_error("pthread mutex init failed: %s", strerror(err));
        return MC_ERROR;
    }

    t->stats_thread = stats_thread_init();
    if (t->stats_thread == NULL) {
        log_error("stats thread init failed: %s", strerror(errno));
        pthread_mutex_destroy(t->stats_mutex);
        return MC_ERROR;
    }

    t->stats_slabs = stats_slabs_init();
    if (t->stats_slabs == NULL) {
        log_error("stats slabs init failed: %s", strerror(errno));
        pthread_mutex_destroy(t->stats_mutex);
        stats_thread_deinit(t->stats_thread);
        return MC_ERROR;
    }

    return MC_OK;
}
コード例 #2
0
ファイル: mc_thread.c プロジェクト: shantanusharma/twemcache
/*
 * Setup aggregator thread
 */
static rstatus_t
thread_setup_aggregator(void)
{
    int status;

    aggregator.base = event_base_new();
    if (NULL == aggregator.base) {
        log_error("event init failed: %s", strerror(errno));
        return MC_ERROR;
    }

    /* +1 because we also aggregate from dispatcher */
    sem_init(&aggregator.stats_sem, 0, settings.num_workers + 1);

    aggregator.stats_thread = stats_thread_init();
    if (aggregator.stats_thread == NULL) {
        sem_destroy(&aggregator.stats_sem);
        return MC_ERROR;
    }

    aggregator.stats_slabs = stats_slabs_init();
    if (aggregator.stats_slabs == NULL) {
        sem_destroy(&aggregator.stats_sem);
        stats_thread_deinit(aggregator.stats_thread);
        return MC_ERROR;
    }

    evtimer_set(&aggregator.ev, thread_aggregate_stats, NULL);
    event_base_set(aggregator.base, &aggregator.ev);

    status = evtimer_add(&aggregator.ev, &settings.stats_agg_intvl);
    if (status < 0) {
        log_error("evtimer add failed: %s", strerror(errno));
        return status;
    }

    return MC_OK;
}
コード例 #3
0
static int jt_init()
{
	int err;
	char iface[MAX_IFACE_LEN];

	if (netem_init() < 0) {
		fprintf(stderr,
		        "Couldn't initialise netlink for netem module.\n");
		return -1;
	}

	err = jt_ws_mq_init();
	if (err) {
		return -1;
	}

	get_first_iface(iface);
	select_iface(&iface);

	stats_thread_init(stats_event_handler);

	g_jt_state = JT_STATE_RUNNING;
	return 0;
}