mirror of
https://github.com/asterisk/asterisk.git
synced 2025-11-19 00:00:09 +00:00
store the list of 'atexit' functions using linked list macros (issue #6329)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@8572 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
40
asterisk.c
40
asterisk.c
@@ -167,12 +167,12 @@ struct console {
|
|||||||
pthread_t t; /*!< Thread of handler */
|
pthread_t t; /*!< Thread of handler */
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct ast_atexit {
|
struct ast_atexit {
|
||||||
void (*func)(void);
|
void (*func)(void);
|
||||||
struct ast_atexit *next;
|
AST_LIST_ENTRY(ast_atexit) list;
|
||||||
} *atexits = NULL;
|
};
|
||||||
|
|
||||||
AST_MUTEX_DEFINE_STATIC(atexitslock);
|
static AST_LIST_HEAD_STATIC(atexits, ast_atexit);
|
||||||
|
|
||||||
time_t ast_startuptime;
|
time_t ast_startuptime;
|
||||||
time_t ast_lastreloadtime;
|
time_t ast_lastreloadtime;
|
||||||
@@ -355,35 +355,29 @@ int ast_register_atexit(void (*func)(void))
|
|||||||
struct ast_atexit *ae;
|
struct ast_atexit *ae;
|
||||||
ast_unregister_atexit(func);
|
ast_unregister_atexit(func);
|
||||||
ae = malloc(sizeof(struct ast_atexit));
|
ae = malloc(sizeof(struct ast_atexit));
|
||||||
ast_mutex_lock(&atexitslock);
|
AST_LIST_LOCK(&atexits);
|
||||||
if (ae) {
|
if (ae) {
|
||||||
memset(ae, 0, sizeof(struct ast_atexit));
|
memset(ae, 0, sizeof(struct ast_atexit));
|
||||||
ae->next = atexits;
|
AST_LIST_INSERT_HEAD(&atexits, ae, list);
|
||||||
ae->func = func;
|
ae->func = func;
|
||||||
atexits = ae;
|
|
||||||
res = 0;
|
res = 0;
|
||||||
}
|
}
|
||||||
ast_mutex_unlock(&atexitslock);
|
AST_LIST_UNLOCK(&atexits);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ast_unregister_atexit(void (*func)(void))
|
void ast_unregister_atexit(void (*func)(void))
|
||||||
{
|
{
|
||||||
struct ast_atexit *ae, *prev = NULL;
|
struct ast_atexit *ae;
|
||||||
ast_mutex_lock(&atexitslock);
|
AST_LIST_LOCK(&atexits);
|
||||||
ae = atexits;
|
AST_LIST_TRAVERSE_SAFE_BEGIN(&atexits, ae, list) {
|
||||||
while(ae) {
|
|
||||||
if (ae->func == func) {
|
if (ae->func == func) {
|
||||||
if (prev)
|
AST_LIST_REMOVE_CURRENT(&atexits, list);
|
||||||
prev->next = ae->next;
|
|
||||||
else
|
|
||||||
atexits = ae->next;
|
|
||||||
break;
|
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)
|
static int fdprint(int fd, const char *s)
|
||||||
@@ -806,14 +800,12 @@ int ast_set_priority(int pri)
|
|||||||
static void ast_run_atexits(void)
|
static void ast_run_atexits(void)
|
||||||
{
|
{
|
||||||
struct ast_atexit *ae;
|
struct ast_atexit *ae;
|
||||||
ast_mutex_lock(&atexitslock);
|
AST_LIST_LOCK(&atexits);
|
||||||
ae = atexits;
|
AST_LIST_TRAVERSE(&atexits, ae, list) {
|
||||||
while(ae) {
|
|
||||||
if (ae->func)
|
if (ae->func)
|
||||||
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)
|
static void quit_handler(int num, int nice, int safeshutdown, int restart)
|
||||||
|
|||||||
Reference in New Issue
Block a user