// 销毁网络通信层 void iolayer_destroy( iolayer_t self ) { uint8_t i = 0; struct iolayer * layer = (struct iolayer *)self; // 设置停止状态 layer->status = eLayerStatus_Stopped; // 停止网络线程组 if ( layer->group ) { iothreads_stop( layer->group ); layer->group = NULL; } // 销毁管理器 if ( layer->managers ) { for ( i = 0; i < layer->nthreads; ++i ) { struct session_manager * manager = layer->managers[i<<3]; if ( manager ) { session_manager_destroy( manager ); } } free( layer->managers ); layer->managers = NULL; } free( layer ); }
int32_t main() { uint64_t index = 0; uint8_t i = 0; uint8_t nthreads = 4; iothreads_t threadgroup; uint64_t start_time = 0, end_time = 0; struct iothread_args * args = NULL; srand( (int32_t)time(NULL) ); signal( SIGINT, signal_handler ); // threadgroup = iothreads_start( nthreads, 0, task_method, NULL ); if ( threadgroup == NULL ) { printf("iothreads_start() failed \n"); return -1; } args = (struct iothread_args *)calloc( nthreads, sizeof(struct iothread_args) ); if ( args == NULL ) { printf("calloc for 'iothread_args' failed \n"); return -2; } // runflags = 1; // start_time = milliseconds(); while ( runflags ) { uint8_t _index = index&(nthreads-1); struct iothread_args * _args = args + _index; iothreads_post( threadgroup, _index, 0, _args, 0 ); ++index; } end_time = milliseconds(); // iothreads_stop( threadgroup ); // for ( i = 0; i < nthreads; ++i ) { struct iothread_args * _args = args + i; float rate = (float)(_args->taskcount)*1000.0f/(float)(end_time-start_time); printf("iothread[%d] process tasks: %ld, rate: %6.3f\n", i, _args->taskcount, rate ); } printf("dispatch tasks: %ld, rate: %6.3f\n", index, (float)(index)*1000.0f/(float)(end_time-start_time) ); return 0; }