void t_chassis_shutdown_hooks_new(void) { chassis_shutdown_hooks_t *hooks; hooks = chassis_shutdown_hooks_new(); chassis_shutdown_hooks_free(hooks); }
void t_chassis_shutdown_hooks_register(void) { chassis_shutdown_hooks_t *hooks; chassis_shutdown_hook_t *hook; int count = 0; hooks = chassis_shutdown_hooks_new(); hook = chassis_shutdown_hook_new(); hook->func = shutdown_func; hook->udata = &count; g_assert_cmpint(TRUE, ==, chassis_shutdown_hooks_register(hooks, C("foo"), hook)); /* check that _call() only execs the shutdown hook once */ g_assert_cmpint(hook->is_called, ==, FALSE); g_assert_cmpint(*(int *)hook->udata, ==, 0); chassis_shutdown_hooks_call(hooks); g_assert_cmpint(hook->is_called, ==, TRUE); g_assert_cmpint(*(int *)hook->udata, ==, 1); chassis_shutdown_hooks_call(hooks); g_assert_cmpint(hook->is_called, ==, TRUE); g_assert_cmpint(*(int *)hook->udata, ==, 1); /* register a hook with the same name */ hook = chassis_shutdown_hook_new(); g_assert_cmpint(FALSE, ==, chassis_shutdown_hooks_register(hooks, C("foo"), hook)); chassis_shutdown_hook_free(hook); /* as it failed, we have to free it */ chassis_shutdown_hooks_free(hooks); }
/** * 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; }
/** * 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; }
/** * 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; }
/** * 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; }