comparison freeDiameter/routing_dispatch.c @ 253:ad6c0118fb50

Configurable number of server threads
author Sebastien Decugis <sdecugis@nict.go.jp>
date Tue, 13 Apr 2010 14:50:54 +0900
parents 84460aa8d77b
children 5df55136361b
comparison
equal deleted inserted replaced
252:433ef00ac049 253:ad6c0118fb50
1067 1067
1068 /********************************************************************************/ 1068 /********************************************************************************/
1069 /* The functions for the other files */ 1069 /* The functions for the other files */
1070 /********************************************************************************/ 1070 /********************************************************************************/
1071 1071
1072 static pthread_t * dispatch = NULL;
1073 static enum thread_state * disp_state = NULL;
1074
1072 /* Later: make this more dynamic */ 1075 /* Later: make this more dynamic */
1073 static pthread_t dispatch = (pthread_t)NULL;
1074 static enum thread_state disp_state = INITIAL;
1075
1076 static pthread_t rt_out = (pthread_t)NULL; 1076 static pthread_t rt_out = (pthread_t)NULL;
1077 static enum thread_state out_state = INITIAL; 1077 static enum thread_state out_state = INITIAL;
1078 1078
1079 static pthread_t rt_in = (pthread_t)NULL; 1079 static pthread_t rt_in = (pthread_t)NULL;
1080 static enum thread_state in_state = INITIAL; 1080 static enum thread_state in_state = INITIAL;
1081 1081
1082 /* Initialize the routing and dispatch threads */ 1082 /* Initialize the routing and dispatch threads */
1083 int fd_rtdisp_init(void) 1083 int fd_rtdisp_init(void)
1084 { 1084 {
1085 CHECK_POSIX( pthread_create( &dispatch, NULL, dispatch_thr, &disp_state ) ); 1085 int i;
1086
1087 /* Prepare the array for dispatch */
1088 CHECK_MALLOC( dispatch = calloc(fd_g_config->cnf_dispthr, sizeof(pthread_t)) );
1089 CHECK_MALLOC( disp_state = calloc(fd_g_config->cnf_dispthr, sizeof(enum thread_state)) );
1090
1091 /* Create the threads */
1092 for (i=0; i < fd_g_config->cnf_dispthr; i++) {
1093 CHECK_POSIX( pthread_create( &dispatch[i], NULL, dispatch_thr, &disp_state[i] ) );
1094 }
1086 CHECK_POSIX( pthread_create( &rt_out, NULL, routing_out_thr, &out_state) ); 1095 CHECK_POSIX( pthread_create( &rt_out, NULL, routing_out_thr, &out_state) );
1087 CHECK_POSIX( pthread_create( &rt_in, NULL, routing_in_thr, &in_state) ); 1096 CHECK_POSIX( pthread_create( &rt_in, NULL, routing_in_thr, &in_state) );
1088 1097
1089 /* Later: TODO("Set the thresholds for the queues to create more threads as needed"); */ 1098 /* Later: TODO("Set the thresholds for the queues to create more threads as needed"); */
1090 1099
1136 } 1145 }
1137 1146
1138 /* Stop the thread after up to one second of wait */ 1147 /* Stop the thread after up to one second of wait */
1139 int fd_rtdisp_fini(void) 1148 int fd_rtdisp_fini(void)
1140 { 1149 {
1150 int i;
1151
1141 /* Destroy the incoming queue */ 1152 /* Destroy the incoming queue */
1142 CHECK_FCT_DO( fd_queues_fini(&fd_g_incoming), /* ignore */); 1153 CHECK_FCT_DO( fd_queues_fini(&fd_g_incoming), /* ignore */);
1143 1154
1144 /* Stop the routing IN thread */ 1155 /* Stop the routing IN thread */
1145 stop_thread_delayed(&in_state, &rt_in, "IN routing"); 1156 stop_thread_delayed(&in_state, &rt_in, "IN routing");
1152 1163
1153 /* Destroy the local queue */ 1164 /* Destroy the local queue */
1154 CHECK_FCT_DO( fd_queues_fini(&fd_g_local), /* ignore */); 1165 CHECK_FCT_DO( fd_queues_fini(&fd_g_local), /* ignore */);
1155 1166
1156 /* Stop the Dispatch thread */ 1167 /* Stop the Dispatch thread */
1157 stop_thread_delayed(&disp_state, &dispatch, "Dispatching"); 1168 for (i=0; i < fd_g_config->cnf_dispthr; i++) {
1169 stop_thread_delayed(&disp_state[i], &dispatch[i], "Dispatching");
1170 }
1158 1171
1159 return 0; 1172 return 0;
1160 } 1173 }
1161 1174
1162 /* Cleanup handlers */ 1175 /* Cleanup handlers */
"Welcome to our mercurial repository"