/**
 * create a global context
 */
chassis *chassis_new() {
	chassis *chas;

	if (0 != chassis_check_version(event_get_version(), _EVENT_VERSION)) {
		g_critical("%s: chassis is build against libevent %s, but now runs against %s",
				G_STRLOC, _EVENT_VERSION, event_get_version());
		return NULL;
	}

	chas = g_new0(chassis, 1);

	chas->modules     = g_ptr_array_new();
	
	chas->stats = chassis_stats_new();

	/* create a new global timer info */
	chassis_timestamps_global_init(NULL);

	chas->threads = chassis_event_threads_new();

	chas->event_hdr_version = g_strdup(_EVENT_VERSION);

	chas->shutdown_hooks = chassis_shutdown_hooks_new();

	return chas;
}
Esempio n. 2
0
/**
 * create a global context
 */
chassis *chassis_new() {
	chassis *chas;
  int i;
  GTimeVal	now;

	if (0 != chassis_check_version(event_get_version(), _EVENT_VERSION)) {
		g_critical("%s: chassis is build against libevent %s, but now runs against %s",
				G_STRLOC, _EVENT_VERSION, event_get_version());
		return NULL;
	}
	
	/* add by vinchen/CFR£¬init libevent to be thread_safe */
	if (0 != chassis_libevent_init()){
		g_critical("%s: chassis_libevent_init error, libevent version : %s",
				G_STRLOC, event_get_version());
		return NULL;
	}

	chas = g_new0(chassis, 1);

	chas->modules     = g_ptr_array_new();
	
	chas->stats = chassis_stats_new();

	/* create a new global timer info */
	chassis_timestamps_global_init(NULL);

	chas->threads = chassis_event_threads_new();

	chas->event_hdr_version = g_strdup(_EVENT_VERSION);

	chas->shutdown_hooks = chassis_shutdown_hooks_new();

  /*
   * Init for query_response_time
   */
  for (i = 0; i < OVERALL_POWER_COUNT; i++){
    chas->counter[i] = 0;
    chas->total[i] = 0;
  }
  for (i = 0; i < OVERALL_POWER_COUNT; i++){
    if (i < OVERALL_POWER_HALF)
      /* 2^(-15) ~ 2^(-1) */
      chas->time[i] = 1.00/(1 << (OVERALL_POWER_HALF - i)) * MILLION;
    else
      /* 2^0 ~ 2^15 */
      chas->time[i] = (guint64)(1 << (i - OVERALL_POWER_HALF)) * MILLION;
  }

  g_get_current_time(&now);
  chas->start_time = now;
  chas->query_mutex = g_mutex_new();

	return chas;
}
Esempio n. 3
0
/**
 * create a global context
 */
chassis *chassis_new() {
    chassis *chas;
    gint ret = 0;

    if (0 != chassis_check_version(event_get_version(), _EVENT_VERSION)) {
        g_critical("%s: chassis is build against libevent %s, but now runs against %s",
                G_STRLOC, _EVENT_VERSION, event_get_version());
        return NULL;
    }

    chas = g_new0(chassis, 1);

    chas->modules = g_ptr_array_new();
    
    chas->stats = chassis_stats_new();

    /* create a new global timer info */
    chassis_timestamps_global_init(NULL);

    chas->threads = g_ptr_array_new();

    chas->event_hdr_version = g_strdup(_EVENT_VERSION);

    chas->shutdown_hooks = chassis_shutdown_hooks_new();

    chas->proxy_filter = sql_filter_new(0);
    chas->proxy_reserved = sql_reserved_query_new();

    chas->daemon_mode = 0;
    chas->max_files_number = 0;
    chas->auto_restart = 0;

    chas->opts = NULL;//need to free

    if (0 != ret) {
        g_critical("create thread exit semphore failed. %s", G_STRLOC);
        return NULL;
    }

    return chas;
}
Esempio n. 4
0
/**
 * create a global context
 */
chassis *chassis_new() {
    chassis *chas;

    if (0 != chassis_check_version(event_get_version(), _EVENT_VERSION)) {
        g_log_dbproxy(g_critical, "chassis is build against libevent %s, but now runs against %s", _EVENT_VERSION, event_get_version());
        return NULL;
    }

    chas = g_new0(chassis, 1);

    chas->modules = g_ptr_array_new();
    
    chas->stats = chassis_stats_new();

    /* create a new global timer info */
    chassis_timestamps_global_init(NULL);

    chas->threads = g_ptr_array_new();

    chas->event_hdr_version = g_strdup(_EVENT_VERSION);

    chas->shutdown_hooks = chassis_shutdown_hooks_new();

    chas->proxy_filter = sql_filter_new(0);
    chas->proxy_reserved = sql_reserved_query_new();

    chas->daemon_mode = 0;
    chas->max_files_number = 0;
    chas->auto_restart = 0;

    chas->opts = NULL;//need to free

    chas->db_connect_timeout = 3.0;//default timeout 3.0s

    return chas;
}