Navigation


Changeset 686:f83d9878bf66 in freeDiameter for libfdcore/routing_dispatch.c


Ignore:
Timestamp:
Jan 19, 2011, 2:35:14 PM (13 years ago)
Author:
Sebastien Decugis <sdecugis@nict.go.jp>
Branch:
default
Phase:
public
Message:

Fixed in case of termination of several modules (before initialization completed)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libfdcore/routing_dispatch.c

    r662 r686  
    973973
    974974/* Threads report their status */
    975 enum thread_state { INITIAL = 0, RUNNING = 1, TERMINATED = 2 };
     975enum thread_state { NOTRUNNING = 0, RUNNING = 1 };
    976976static void cleanup_state(void * state_loc)
    977977{
    978978        if (state_loc)
    979                 *(enum thread_state *)state_loc = TERMINATED;
     979                *(enum thread_state *)state_loc = NOTRUNNING;
    980980}
    981981
     
    10801080/* Later: make this more dynamic */
    10811081static pthread_t rt_out = (pthread_t)NULL;
    1082 static enum thread_state out_state = INITIAL;
     1082static enum thread_state out_state = NOTRUNNING;
    10831083
    10841084static pthread_t rt_in  = (pthread_t)NULL;
    1085 static enum thread_state in_state = INITIAL;
     1085static enum thread_state in_state = NOTRUNNING;
    10861086
    10871087/* Initialize the routing and dispatch threads */
     
    10911091       
    10921092        /* Prepare the array for dispatch */
     1093        CHECK_MALLOC( disp_state = calloc(fd_g_config->cnf_dispthr, sizeof(enum thread_state)) );
    10931094        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)) );
    10951095       
    10961096        /* Create the threads */
     
    11261126        /* Wait for a second for the thread to complete, by monitoring my_state */
    11271127        fd_cpu_flush_cache();
    1128         if (*st != TERMINATED) {
     1128        if (*st != NOTRUNNING) {
    11291129                TRACE_DEBUG(INFO, "Waiting for the %s thread to have a chance to terminate", th_name);
    11301130                do {
     
    11371137                       
    11381138                        while (TS_IS_INFERIOR( &ts, &ts_final )) {
    1139                                 if (*st == TERMINATED)
     1139                                fd_cpu_flush_cache();
     1140                                if (*st == NOTRUNNING)
    11401141                                        break;
    11411142                               
     
    11711172        CHECK_FCT_DO( fd_queues_fini(&fd_g_local), /* ignore */);
    11721173       
    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;
    11761185        }
    11771186       
Note: See TracChangeset for help on using the changeset viewer.