Navigation


Changeset 1182:cc96a4dfb3d1 in freeDiameter for libfdcore


Ignore:
Timestamp:
Jun 6, 2013, 12:25:23 PM (11 years ago)
Author:
Sebastien Decugis <sdecugis@freediameter.net>
Branch:
default
Phase:
public
Message:

Early shutdown situation: detect the race condition and delay the shutdown in freeDiameterd. Alternative would be to initialize in a separate thread that we can cancel before calling shutdown.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libfdcore/core.c

    r1167 r1182  
    228228}
    229229
     230static pthread_mutex_t core_lock = PTHREAD_MUTEX_INITIALIZER;
     231
    230232/* Parse the freeDiameter.conf configuration file, load the extensions */
    231 int fd_core_parseconf(const char * conffile)
     233static int fd_core_parseconf_int(const char * conffile)
    232234{
    233235        char * buf = NULL, *b;
     
    274276}
    275277
     278int fd_core_parseconf(const char * conffile)
     279{
     280        int ret;
     281        CHECK_POSIX( pthread_mutex_lock(&core_lock) );
     282        ret = fd_core_parseconf_int(conffile);
     283        CHECK_POSIX( pthread_mutex_unlock(&core_lock) );
     284        return ret;
     285}
     286
     287
    276288/* For threads that would need to wait complete start of the framework (ex: in extensions) */
    277289int fd_core_waitstartcomplete(void)
     
    283295
    284296/* Start the server & client threads */
    285 int fd_core_start(void)
     297static int fd_core_start_int(void)
    286298{
    287299        /* Start server threads */
     
    301313}
    302314
     315int fd_core_start(void)
     316{
     317        int ret;
     318        CHECK_POSIX( pthread_mutex_lock(&core_lock) );
     319        ret = fd_core_start_int();
     320        CHECK_POSIX( pthread_mutex_unlock(&core_lock) );
     321        return ret;
     322}
    303323
    304324/* Initialize shutdown of the framework. This is not blocking. */
     
    308328       
    309329        if (cur_state < CORE_RUNNING) {
     330                /* Calling application must make sure the initialization is not ongoing in a separate thread... */
     331                if (pthread_mutex_lock(&core_lock) != 0) {
     332                        /* This function must not be called asynchronously from fd_core_parseconf / fd_core_start ! Please review your main app design */
     333                        ASSERT(0);
     334                        return EINVAL;
     335                }
    310336                core_shutdown();
    311337                core_state_set(CORE_TERM);
     338                pthread_mutex_unlock(&core_lock);
    312339        } else if (cur_state == CORE_RUNNING) {
    313340                core_state_set(CORE_SHUTDOWN);
Note: See TracChangeset for help on using the changeset viewer.