Changeset 686:f83d9878bf66 in freeDiameter
- Timestamp:
- Jan 19, 2011, 2:35:14 PM (12 years ago)
- Branch:
- default
- Phase:
- public
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
libfdcore/config.c
r662 r686 457 457 TRACE_ENTRY(); 458 458 459 if (!fd_g_config) 460 return 0; 461 459 462 /* Free the TLS parameters */ 460 463 gnutls_priority_deinit(fd_g_config->cnf_sec_data.prio_cache); -
libfdcore/core.c
r662 r686 39 39 40 40 /* The static configuration structure */ 41 static struct fd_config conf;42 struct fd_config * fd_g_config = &conf;41 static struct fd_config g_conf; 42 struct fd_config * fd_g_config = NULL; 43 43 44 44 /* gcrypt functions to support posix threads */ … … 62 62 /* Thread that process incoming events on the main queue -- and terminates the framework when requested */ 63 63 static pthread_t core_runner = (pthread_t)NULL; 64 enum core_mode { 65 CORE_MODE_EVENTS, 66 CORE_MODE_IMMEDIATE 67 }; 64 68 65 69 static void * core_runner_thread(void * arg) 66 70 { 67 71 fd_log_threadname("Core Runner"); 72 73 if (arg && (*(int *)arg == CORE_MODE_IMMEDIATE)) 74 goto end; 68 75 69 76 /* Handle events incoming on the main event queue */ … … 161 168 int ret; 162 169 163 memset(fd_g_config, 0, sizeof(struct fd_config));164 165 170 /* Initialize the library -- must come first since it initializes the debug facility */ 166 171 ret = fd_libproto_init(); … … 187 192 188 193 /* Initialize the config with default values */ 194 memset(&g_conf, 0, sizeof(struct fd_config)); 195 fd_g_config = &g_conf; 189 196 CHECK_FCT( fd_conf_init() ); 190 197 … … 269 276 int fd_core_shutdown(void) 270 277 { 271 /* Signal the framework to terminate */ 272 CHECK_FCT( fd_event_send(fd_g_config->cnf_main_ev, FDEV_TERMINATE, 0, NULL) ); 278 if (core_runner != (pthread_t)NULL) { 279 /* Signal the framework to terminate */ 280 CHECK_FCT( fd_event_send(fd_g_config->cnf_main_ev, FDEV_TERMINATE, 0, NULL) ); 281 } else { 282 /* The framework was maybe not fully initialized (ex: tests) */ 283 enum core_mode arg = CORE_MODE_IMMEDIATE; 284 (void) core_runner_thread(&arg); 285 } 273 286 274 287 return 0; … … 282 295 void * th_ret = NULL; 283 296 284 /* Just wait for core_runner_thread to complete and return gracefully */ 285 ret = pthread_join(core_runner, &th_ret); 286 if (ret != 0) { 287 fprintf(stderr, "Unable to wait for main framework thread termination: %s\n", strerror(ret)); 288 return ret; 289 } 290 291 return 0; 292 } 293 294 295 296 297 if (core_runner != (pthread_t)NULL) { 298 /* Just wait for core_runner_thread to complete and return gracefully */ 299 ret = pthread_join(core_runner, &th_ret); 300 if (ret != 0) { 301 fprintf(stderr, "Unable to wait for main framework thread termination: %s\n", strerror(ret)); 302 return ret; 303 } 304 } 305 306 return 0; 307 } 308 309 310 311 -
libfdcore/p_expiry.c
r662 r686 39 39 #define GC_TIME 120 40 40 41 static pthread_t exp_thr ;42 static pthread_t gc_thr ;41 static pthread_t exp_thr = (pthread_t)NULL; 42 static pthread_t gc_thr = (pthread_t)NULL; 43 43 static struct fd_list exp_list = FD_LIST_INITIALIZER( exp_list ); 44 44 static pthread_cond_t exp_cnd = PTHREAD_COND_INITIALIZER; -
libfdcore/queues.c
r662 r686 60 60 61 61 /* Note : the threads that post into this queue should already been stopped before this !!! */ 62 63 CHECK_PARAMS(queue); 64 if (*queue == NULL) 65 return 0; /* the queue was not already initialized */ 62 66 63 67 /* Empty all contents */ -
libfdcore/routing_dispatch.c
r662 r686 973 973 974 974 /* Threads report their status */ 975 enum thread_state { INITIAL = 0, RUNNING = 1, TERMINATED = 2};975 enum thread_state { NOTRUNNING = 0, RUNNING = 1 }; 976 976 static void cleanup_state(void * state_loc) 977 977 { 978 978 if (state_loc) 979 *(enum thread_state *)state_loc = TERMINATED;979 *(enum thread_state *)state_loc = NOTRUNNING; 980 980 } 981 981 … … 1080 1080 /* Later: make this more dynamic */ 1081 1081 static pthread_t rt_out = (pthread_t)NULL; 1082 static enum thread_state out_state = INITIAL;1082 static enum thread_state out_state = NOTRUNNING; 1083 1083 1084 1084 static pthread_t rt_in = (pthread_t)NULL; 1085 static enum thread_state in_state = INITIAL;1085 static enum thread_state in_state = NOTRUNNING; 1086 1086 1087 1087 /* Initialize the routing and dispatch threads */ … … 1091 1091 1092 1092 /* Prepare the array for dispatch */ 1093 CHECK_MALLOC( disp_state = calloc(fd_g_config->cnf_dispthr, sizeof(enum thread_state)) ); 1093 1094 CHECK_MALLOC( dispatch = calloc(fd_g_config->cnf_dispthr, sizeof(pthread_t)) ); 1094 CHECK_MALLOC( disp_state = calloc(fd_g_config->cnf_dispthr, sizeof(enum thread_state)) );1095 1095 1096 1096 /* Create the threads */ … … 1126 1126 /* Wait for a second for the thread to complete, by monitoring my_state */ 1127 1127 fd_cpu_flush_cache(); 1128 if (*st != TERMINATED) {1128 if (*st != NOTRUNNING) { 1129 1129 TRACE_DEBUG(INFO, "Waiting for the %s thread to have a chance to terminate", th_name); 1130 1130 do { … … 1137 1137 1138 1138 while (TS_IS_INFERIOR( &ts, &ts_final )) { 1139 if (*st == TERMINATED) 1139 fd_cpu_flush_cache(); 1140 if (*st == NOTRUNNING) 1140 1141 break; 1141 1142 … … 1171 1172 CHECK_FCT_DO( fd_queues_fini(&fd_g_local), /* ignore */); 1172 1173 1173 /* Stop the Dispatch thread */ 1174 for (i=0; i < fd_g_config->cnf_dispthr; i++) { 1175 stop_thread_delayed(&disp_state[i], &dispatch[i], "Dispatching"); 1174 /* Stop the Dispatch threads */ 1175 if (dispatch != NULL) { 1176 for (i=0; i < fd_g_config->cnf_dispthr; i++) { 1177 stop_thread_delayed(&disp_state[i], &dispatch[i], "Dispatching"); 1178 } 1179 free(dispatch); 1180 dispatch = NULL; 1181 } 1182 if (disp_state != NULL) { 1183 free(disp_state); 1184 disp_state = NULL; 1176 1185 } 1177 1186 -
libfdcore/server.c
r662 r686 36 36 #include "fdcore-internal.h" 37 37 38 /* Server (listening) part of the daemon*/39 40 st ruct fd_listFD_SERVERS = FD_LIST_INITIALIZER(FD_SERVERS); /* The list of all server objects */41 /* We don't need to protect this list, it is only accessed from the main daemonthread. */38 /* Server (listening) part of the framework */ 39 40 static struct fd_list FD_SERVERS = FD_LIST_INITIALIZER(FD_SERVERS); /* The list of all server objects */ 41 /* We don't need to protect this list, it is only accessed from the main framework thread. */ 42 42 43 43 /* Servers information */ … … 83 83 "Thread status unknown"))); 84 84 /* Dump the client list of this server */ 85 (void) pthread_mutex_lock(&s->clients_mtx);85 CHECK_POSIX_DO( pthread_mutex_lock(&s->clients_mtx), ); 86 86 for (cli = s->clients.next; cli != &s->clients; cli = cli->next) { 87 87 struct client * c = (struct client *)cli; … … 91 91 fd_log_time(&c->ts, bufts, sizeof(bufts))); 92 92 } 93 (void) pthread_mutex_unlock(&s->clients_mtx);93 CHECK_POSIX_DO( pthread_mutex_unlock(&s->clients_mtx), ); 94 94 } 95 95 } -
libfdproto/messages.c
r658 r686 1109 1109 1110 1110 /******************* End-to-end counter *********************/ 1111 uint32_t fd_eteid;1112 pthread_mutex_t fd_eteid_lck = PTHREAD_MUTEX_INITIALIZER;1111 static uint32_t fd_eteid; 1112 static pthread_mutex_t fd_eteid_lck = PTHREAD_MUTEX_INITIALIZER; 1113 1113 1114 1114 void fd_msg_eteid_init(void) -
libfdproto/sessions.c
r662 r686 122 122 static pthread_mutex_t exp_lock = PTHREAD_MUTEX_INITIALIZER; /* lock protecting the list. */ 123 123 static pthread_cond_t exp_cond = PTHREAD_COND_INITIALIZER; /* condvar used by the expiry mecahinsm. */ 124 static pthread_t exp_thr ; /* The expiry thread that handles cleanup of expired sessions */124 static pthread_t exp_thr = (pthread_t)NULL; /* The expiry thread that handles cleanup of expired sessions */ 125 125 126 126 /* Hierarchy of the locks, to avoid deadlocks:
Note: See TracChangeset
for help on using the changeset viewer.