void togo_init(int argc, char *argv[]) { //togo_test(); togo_pool_init(); togo_argv_init(argc, argv); togo_c_init(); togo_daemon_init(); togo_hashtable_init(togo_pool); togo_module_init(); togo_server_init(); }
void togo_m_queue_init(void) { togo_m_queue_pool = togo_pool_create(TOGO_M_QUEUE_POOL_SIZE); if (togo_m_queue_pool == NULL) { togo_log(ERROR, "Initialize modules_queue's pool fail."); togo_exit(); } togo_m_queue_hashtable = togo_hashtable_init(togo_m_queue_pool); if (togo_m_queue_hashtable == NULL) { togo_log(ERROR, "Initialize modules_queue's hashtable fail."); togo_exit(); } togo_m_queue_fblock = (TOGO_M_QUEUE_FBLOCK *) togo_pool_calloc( togo_m_queue_pool, sizeof(TOGO_M_QUEUE_FBLOCK)); if (togo_m_queue_fblock == NULL) { togo_log(ERROR, "Initialize modules_queue's free block fail."); togo_exit(); } pthread_mutex_init(&togo_m_queue_fblock->flock, NULL); pthread_mutex_init(&togo_m_queue_glock, NULL); }
void togo_m_cache_init(void) { uint32_t total_area, curr, i; uint32_t * area_table; TOGO_M_CACHE_AREA * area; togo_m_cache_pool = togo_pool_create(TOGO_M_CACHE_POOL_SIZE); if (togo_m_cache_pool == NULL) { togo_log(ERROR, "Initialize modules_cache's POOL fail."); togo_exit(); } togo_m_cache_hashtable = togo_hashtable_init(togo_m_cache_pool); if (togo_m_cache_hashtable == NULL) { togo_log(ERROR, "Initialize modules_cache's HASHTABLE fail."); togo_exit(); } togo_m_cache = (TOGO_M_CACHE *) togo_pool_calloc(togo_m_cache_pool, sizeof(TOGO_M_CACHE)); if (togo_m_cache == NULL) { togo_log(ERROR, "Initialize modules_cache's TOGO_M_CACHE fail."); togo_exit(); } togo_m_cache->pool = togo_m_cache_pool; togo_m_cache->total_area = 0; togo_m_cache->total_hit = 0; togo_m_cache->total_read = 0; togo_m_cache->total_size = 0; togo_m_cache->total_write = 0; togo_m_cache->is_flush = FALSE; pthread_mutex_init(&togo_m_cache->glock, NULL); /* Initialize the area table!*/ area_table = (uint32_t *) togo_pool_alloc(togo_m_cache_pool, sizeof(uint32_t) * TOGO_M_CACHE_AREA_TABLE_DEFAULT_SIZE); if (area_table == NULL) { togo_log(ERROR, "Initialize modules_cache's area_table fail."); togo_exit(); } togo_m_cache->area_table = area_table; total_area = i = 1; curr = TOGO_M_CACHE_ITEM_START; *area_table = curr; while (curr != TOGO_M_CACHE_CHUNK_SIZE) { total_area++; curr = (uint32_t)(curr * TOGO_M_CACHE_ITEM_POWER); if (curr >= TOGO_M_CACHE_CHUNK_SIZE) { curr = TOGO_M_CACHE_CHUNK_SIZE; } *(area_table + i) = curr; i++; } togo_m_cache->total_area = total_area; /* Initialize the memory of area!*/ area = (TOGO_M_CACHE_AREA *) togo_pool_calloc(togo_m_cache_pool, sizeof(TOGO_M_CACHE_AREA) * total_area); if (area == NULL) { togo_log(ERROR, "Initialize modules_cache's TOGO_M_CACHE_AREA fail."); togo_exit(); } togo_m_cache->area = area; for (i = 0; i < total_area; i++) { curr = *(area_table + i); togo_m_cache_create_area(curr, i, area); } }