Navigation


Changeset 686:f83d9878bf66 in freeDiameter


Ignore:
Timestamp:
Jan 19, 2011, 2:35:14 PM (11 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)

Files:
8 edited

Legend:

Unmodified
Added
Removed
  • libfdcore/config.c

    r662 r686  
    457457        TRACE_ENTRY();
    458458       
     459        if (!fd_g_config)
     460                return 0;
     461       
    459462        /* Free the TLS parameters */
    460463        gnutls_priority_deinit(fd_g_config->cnf_sec_data.prio_cache);
  • libfdcore/core.c

    r662 r686  
    3939
    4040/* The static configuration structure */
    41 static struct fd_config conf;
    42 struct fd_config * fd_g_config = &conf;
     41static struct fd_config g_conf;
     42struct fd_config * fd_g_config = NULL;
    4343
    4444/* gcrypt functions to support posix threads */
     
    6262/* Thread that process incoming events on the main queue -- and terminates the framework when requested */
    6363static pthread_t core_runner = (pthread_t)NULL;
     64enum core_mode {
     65        CORE_MODE_EVENTS,
     66        CORE_MODE_IMMEDIATE
     67};
    6468
    6569static void * core_runner_thread(void * arg)
    6670{
    6771        fd_log_threadname("Core Runner");
     72       
     73        if (arg && (*(int *)arg == CORE_MODE_IMMEDIATE))
     74                goto end;
    6875       
    6976        /* Handle events incoming on the main event queue */
     
    161168        int ret;
    162169       
    163         memset(fd_g_config, 0, sizeof(struct fd_config));
    164        
    165170        /* Initialize the library -- must come first since it initializes the debug facility */
    166171        ret = fd_libproto_init();
     
    187192       
    188193        /* Initialize the config with default values */
     194        memset(&g_conf, 0, sizeof(struct fd_config));
     195        fd_g_config = &g_conf;
    189196        CHECK_FCT( fd_conf_init() );
    190197
     
    269276int fd_core_shutdown(void)
    270277{
    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        }
    273286       
    274287        return 0;
     
    282295        void * th_ret = NULL;
    283296       
    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  
    3939#define GC_TIME         120
    4040
    41 static pthread_t       exp_thr;
    42 static pthread_t       gc_thr;
     41static pthread_t       exp_thr = (pthread_t)NULL;
     42static pthread_t       gc_thr  = (pthread_t)NULL;
    4343static struct fd_list  exp_list = FD_LIST_INITIALIZER( exp_list );
    4444static pthread_cond_t  exp_cnd  = PTHREAD_COND_INITIALIZER;
  • libfdcore/queues.c

    r662 r686  
    6060       
    6161        /* 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 */
    6266
    6367        /* Empty all contents */
  • 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       
  • libfdcore/server.c

    r662 r686  
    3636#include "fdcore-internal.h"
    3737
    38 /* Server (listening) part of the daemon */
    39 
    40 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 daemon thread. */
     38/* Server (listening) part of the framework */
     39
     40static 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. */
    4242
    4343/* Servers information */
     
    8383                                                          "Thread status unknown")));
    8484                /* 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), );
    8686                for (cli = s->clients.next; cli != &s->clients; cli = cli->next) {
    8787                        struct client * c = (struct client *)cli;
     
    9191                                        fd_log_time(&c->ts, bufts, sizeof(bufts)));
    9292                }
    93                 (void) pthread_mutex_unlock(&s->clients_mtx);
     93                CHECK_POSIX_DO( pthread_mutex_unlock(&s->clients_mtx), );
    9494        }
    9595}
  • libfdproto/messages.c

    r658 r686  
    11091109
    11101110/******************* End-to-end counter *********************/
    1111 uint32_t fd_eteid;
    1112 pthread_mutex_t fd_eteid_lck = PTHREAD_MUTEX_INITIALIZER;
     1111static uint32_t fd_eteid;
     1112static pthread_mutex_t fd_eteid_lck = PTHREAD_MUTEX_INITIALIZER;
    11131113
    11141114void fd_msg_eteid_init(void)
  • libfdproto/sessions.c

    r662 r686  
    122122static pthread_mutex_t  exp_lock = PTHREAD_MUTEX_INITIALIZER;   /* lock protecting the list. */
    123123static 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 */
     124static pthread_t        exp_thr = (pthread_t)NULL;      /* The expiry thread that handles cleanup of expired sessions */
    125125
    126126/* Hierarchy of the locks, to avoid deadlocks:
Note: See TracChangeset for help on using the changeset viewer.