# HG changeset patch # User Sebastien Decugis # Date 1368442226 -28800 # Node ID d87cee14b05134d09c60efaa42dadc4859050b73 # Parent 84162710428e662c74002ffc430712b9189c04a1 Fix core termination sequence diff -r 84162710428e -r d87cee14b051 libfdcore/core.c --- a/libfdcore/core.c Mon May 13 11:37:12 2013 +0800 +++ b/libfdcore/core.c Mon May 13 18:50:26 2013 +0800 @@ -83,12 +83,12 @@ static int core_state_wait(enum core_state waitstate) { - int ret; + int ret = 0; CHECK_POSIX( pthread_mutex_lock( &core_mtx )); pthread_cleanup_push( fd_cleanup_mutex, &core_mtx ); - do { + while (waitstate > core_state) { CHECK_POSIX_DO(ret = pthread_cond_wait(&core_cnd, &core_mtx), break); - } while (waitstate > core_state); + } pthread_cleanup_pop( 0 ); CHECK_POSIX( pthread_mutex_unlock( &core_mtx )); return ret; @@ -188,7 +188,7 @@ return ret; } - LOG_D("libfdproto initialized."); + LOG_N("libfdproto initialized."); /* Name this thread */ fd_log_threadname("Main"); @@ -304,6 +304,7 @@ if (cur_state < CORE_RUNNING) { core_shutdown(); + core_state_set(CORE_TERM); } else if (cur_state == CORE_RUNNING) { core_state_set(CORE_SHUTDOWN); CHECK_FCT( fd_event_send(fd_g_config->cnf_main_ev, FDEV_TERMINATE, 0, NULL) ); @@ -322,11 +323,11 @@ enum core_state cur_state = core_state_get(); void * th_ret = NULL; + CHECK_FCT(core_state_wait(CORE_SHUTDOWN)); + if (cur_state == CORE_TERM) return 0; - CHECK_FCT(core_state_wait(CORE_SHUTDOWN)); - /* Just wait for core_runner_thread to complete and return gracefully */ CHECK_POSIX(pthread_join(core_runner, &th_ret));