diff options
author | russell <russell@f38db490-d61c-443f-a65b-d21fe96a405b> | 2006-01-24 20:27:09 +0000 |
---|---|---|
committer | russell <russell@f38db490-d61c-443f-a65b-d21fe96a405b> | 2006-01-24 20:27:09 +0000 |
commit | 486665c8c0f110bf4c0809098bd4e00cebff3102 (patch) | |
tree | b8fec28622939c5c8fa24054bb45173b274335ac /asterisk.c | |
parent | 90b3bcb192b77040a36d015d99bba9bb62d456b5 (diff) |
store the list of 'atexit' functions using linked list macros (issue #6329)
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@8572 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'asterisk.c')
-rw-r--r-- | asterisk.c | 40 |
1 files changed, 16 insertions, 24 deletions
diff --git a/asterisk.c b/asterisk.c index 16903da3e..acdaca634 100644 --- a/asterisk.c +++ b/asterisk.c @@ -167,12 +167,12 @@ struct console { pthread_t t; /*!< Thread of handler */ }; -static struct ast_atexit { +struct ast_atexit { void (*func)(void); - struct ast_atexit *next; -} *atexits = NULL; + AST_LIST_ENTRY(ast_atexit) list; +}; -AST_MUTEX_DEFINE_STATIC(atexitslock); +static AST_LIST_HEAD_STATIC(atexits, ast_atexit); time_t ast_startuptime; time_t ast_lastreloadtime; @@ -355,35 +355,29 @@ int ast_register_atexit(void (*func)(void)) struct ast_atexit *ae; ast_unregister_atexit(func); ae = malloc(sizeof(struct ast_atexit)); - ast_mutex_lock(&atexitslock); + AST_LIST_LOCK(&atexits); if (ae) { memset(ae, 0, sizeof(struct ast_atexit)); - ae->next = atexits; + AST_LIST_INSERT_HEAD(&atexits, ae, list); ae->func = func; - atexits = ae; res = 0; } - ast_mutex_unlock(&atexitslock); + AST_LIST_UNLOCK(&atexits); return res; } void ast_unregister_atexit(void (*func)(void)) { - struct ast_atexit *ae, *prev = NULL; - ast_mutex_lock(&atexitslock); - ae = atexits; - while(ae) { + struct ast_atexit *ae; + AST_LIST_LOCK(&atexits); + AST_LIST_TRAVERSE_SAFE_BEGIN(&atexits, ae, list) { if (ae->func == func) { - if (prev) - prev->next = ae->next; - else - atexits = ae->next; + AST_LIST_REMOVE_CURRENT(&atexits, list); break; } - prev = ae; - ae = ae->next; } - ast_mutex_unlock(&atexitslock); + AST_LIST_TRAVERSE_SAFE_END + AST_LIST_UNLOCK(&atexits); } static int fdprint(int fd, const char *s) @@ -806,14 +800,12 @@ int ast_set_priority(int pri) static void ast_run_atexits(void) { struct ast_atexit *ae; - ast_mutex_lock(&atexitslock); - ae = atexits; - while(ae) { + AST_LIST_LOCK(&atexits); + AST_LIST_TRAVERSE(&atexits, ae, list) { if (ae->func) ae->func(); - ae = ae->next; } - ast_mutex_unlock(&atexitslock); + AST_LIST_UNLOCK(&atexits); } static void quit_handler(int num, int nice, int safeshutdown, int restart) |