mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-06 12:36:58 +00:00
Don't hold modlock while doing reload
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@4276 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
15
loader.c
15
loader.c
@@ -103,6 +103,7 @@ AST_MUTEX_DEFINE_STATIC(modlock);
|
|||||||
AST_MUTEX_DEFINE_STATIC(reloadlock);
|
AST_MUTEX_DEFINE_STATIC(reloadlock);
|
||||||
|
|
||||||
static struct module *module_list=NULL;
|
static struct module *module_list=NULL;
|
||||||
|
static int modlistver = 0;
|
||||||
|
|
||||||
int ast_unload_resource(char *resource_name, int force)
|
int ast_unload_resource(char *resource_name, int force)
|
||||||
{
|
{
|
||||||
@@ -142,6 +143,7 @@ int ast_unload_resource(char *resource_name, int force)
|
|||||||
ml = m;
|
ml = m;
|
||||||
m = m->next;
|
m = m->next;
|
||||||
}
|
}
|
||||||
|
modlistver = rand();
|
||||||
ast_mutex_unlock(&modlock);
|
ast_mutex_unlock(&modlock);
|
||||||
ast_update_use_count();
|
ast_update_use_count();
|
||||||
return res;
|
return res;
|
||||||
@@ -190,6 +192,8 @@ int ast_module_reload(const char *name)
|
|||||||
{
|
{
|
||||||
struct module *m;
|
struct module *m;
|
||||||
int reloaded = 0;
|
int reloaded = 0;
|
||||||
|
int oldversion;
|
||||||
|
int (*reload)(void);
|
||||||
/* We'll do the logger and manager the favor of calling its reload here first */
|
/* We'll do the logger and manager the favor of calling its reload here first */
|
||||||
|
|
||||||
if (ast_mutex_trylock(&reloadlock)) {
|
if (ast_mutex_trylock(&reloadlock)) {
|
||||||
@@ -215,17 +219,23 @@ int ast_module_reload(const char *name)
|
|||||||
time(&ast_lastreloadtime);
|
time(&ast_lastreloadtime);
|
||||||
|
|
||||||
ast_mutex_lock(&modlock);
|
ast_mutex_lock(&modlock);
|
||||||
|
oldversion = modlistver;
|
||||||
m = module_list;
|
m = module_list;
|
||||||
while(m) {
|
while(m) {
|
||||||
if (!name || !strcasecmp(name, m->resource)) {
|
if (!name || !strcasecmp(name, m->resource)) {
|
||||||
if (reloaded < 1)
|
if (reloaded < 1)
|
||||||
reloaded = 1;
|
reloaded = 1;
|
||||||
if (m->reload) {
|
reload = m->reload;
|
||||||
|
ast_mutex_unlock(&modlock);
|
||||||
|
if (reload) {
|
||||||
reloaded = 2;
|
reloaded = 2;
|
||||||
if (option_verbose > 2)
|
if (option_verbose > 2)
|
||||||
ast_verbose(VERBOSE_PREFIX_3 "Reloading module '%s' (%s)\n", m->resource, m->description());
|
ast_verbose(VERBOSE_PREFIX_3 "Reloading module '%s' (%s)\n", m->resource, m->description());
|
||||||
m->reload();
|
reload();
|
||||||
}
|
}
|
||||||
|
ast_mutex_lock(&modlock);
|
||||||
|
if (oldversion != modlistver)
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
m = m->next;
|
m = m->next;
|
||||||
}
|
}
|
||||||
@@ -380,6 +390,7 @@ int ast_load_resource(char *resource_name)
|
|||||||
i->next = m;
|
i->next = m;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
modlistver = rand();
|
||||||
ast_mutex_unlock(&modlock);
|
ast_mutex_unlock(&modlock);
|
||||||
if ((res = m->load_module())) {
|
if ((res = m->load_module())) {
|
||||||
ast_log(LOG_WARNING, "%s: load_module failed, returning %d\n", m->resource, res);
|
ast_log(LOG_WARNING, "%s: load_module failed, returning %d\n", m->resource, res);
|
||||||
|
Reference in New Issue
Block a user