Navigation


Changeset 686:f83d9878bf66 in freeDiameter for libfdcore/core.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/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
Note: See TracChangeset for help on using the changeset viewer.