Changeset 686:f83d9878bf66 in freeDiameter for libfdcore/core.c
- Timestamp:
- Jan 19, 2011, 2:35:14 PM (13 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libfdcore/core.c
r662 r686 39 39 40 40 /* The static configuration structure */ 41 static struct fd_config conf;42 struct fd_config * fd_g_config = &conf;41 static struct fd_config g_conf; 42 struct fd_config * fd_g_config = NULL; 43 43 44 44 /* gcrypt functions to support posix threads */ … … 62 62 /* Thread that process incoming events on the main queue -- and terminates the framework when requested */ 63 63 static pthread_t core_runner = (pthread_t)NULL; 64 enum core_mode { 65 CORE_MODE_EVENTS, 66 CORE_MODE_IMMEDIATE 67 }; 64 68 65 69 static void * core_runner_thread(void * arg) 66 70 { 67 71 fd_log_threadname("Core Runner"); 72 73 if (arg && (*(int *)arg == CORE_MODE_IMMEDIATE)) 74 goto end; 68 75 69 76 /* Handle events incoming on the main event queue */ … … 161 168 int ret; 162 169 163 memset(fd_g_config, 0, sizeof(struct fd_config));164 165 170 /* Initialize the library -- must come first since it initializes the debug facility */ 166 171 ret = fd_libproto_init(); … … 187 192 188 193 /* Initialize the config with default values */ 194 memset(&g_conf, 0, sizeof(struct fd_config)); 195 fd_g_config = &g_conf; 189 196 CHECK_FCT( fd_conf_init() ); 190 197 … … 269 276 int fd_core_shutdown(void) 270 277 { 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 } 273 286 274 287 return 0; … … 282 295 void * th_ret = NULL; 283 296 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.