diff options
author | markster <markster@f38db490-d61c-443f-a65b-d21fe96a405b> | 2003-12-09 23:55:17 +0000 |
---|---|---|
committer | markster <markster@f38db490-d61c-443f-a65b-d21fe96a405b> | 2003-12-09 23:55:17 +0000 |
commit | dcfebf7bf6b94894f65fd5c6241cd639bdaaf110 (patch) | |
tree | e5e5eb37bd50d00a0215049ce584d248a60da5df /channels/chan_modem.c | |
parent | 5d20155225cb149d6326defea641e47809d67fe6 (diff) |
Cleanup unload calls
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@1850 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'channels/chan_modem.c')
-rwxr-xr-x | channels/chan_modem.c | 117 |
1 files changed, 61 insertions, 56 deletions
diff --git a/channels/chan_modem.c b/channels/chan_modem.c index 1da77d321..48571af3e 100755 --- a/channels/chan_modem.c +++ b/channels/chan_modem.c @@ -840,6 +840,64 @@ static unsigned int get_group(char *s) return group; } +static int __unload_module(void) +{ + struct ast_modem_pvt *p, *pl; + /* First, take us out of the channel loop */ + ast_channel_unregister(type); + if (!ast_mutex_lock(&iflock)) { + /* Hangup all interfaces if they have an owner */ + p = iflist; + while(p) { + if (p->owner) + ast_softhangup(p->owner, AST_SOFTHANGUP_APPUNLOAD); + p = p->next; + } + iflist = NULL; + ast_mutex_unlock(&iflock); + } else { + ast_log(LOG_WARNING, "Unable to lock the monitor\n"); + return -1; + } + if (!ast_mutex_lock(&monlock)) { + if (monitor_thread != (pthread_t) -1 && monitor_thread != (pthread_t) -2) { + pthread_cancel(monitor_thread); + pthread_join(monitor_thread, NULL); + } + monitor_thread = (pthread_t) -2; + ast_mutex_unlock(&monlock); + } else { + ast_log(LOG_WARNING, "Unable to lock the monitor\n"); + return -1; + } + + if (!ast_mutex_lock(&iflock)) { + /* Destroy all the interfaces and free their memory */ + p = iflist; + while(p) { + /* Close the socket, assuming it's real */ + if (p->fd > -1) + close(p->fd); + pl = p; + p = p->next; + /* Free associated memory */ + free(pl); + } + iflist = NULL; + ast_mutex_unlock(&iflock); + } else { + ast_log(LOG_WARNING, "Unable to lock the monitor\n"); + return -1; + } + + return 0; +} + +int unload_module() +{ + return __unload_module(); +} + int load_module() { struct ast_config *cfg; @@ -871,7 +929,7 @@ int load_module() ast_log(LOG_ERROR, "Unable to register channel '%s'\n", v->value); ast_destroy(cfg); ast_mutex_unlock(&iflock); - unload_module(); + __unload_module(); return -1; } } else if (!strcasecmp(v->name, "driver")) { @@ -883,7 +941,7 @@ int load_module() ast_log(LOG_ERROR, "Failed to load driver %s\n", driver); ast_destroy(cfg); ast_mutex_unlock(&iflock); - unload_module(); + __unload_module(); return -1; } } else if (!strcasecmp(v->name, "mode")) { @@ -921,7 +979,7 @@ int load_module() AST_FORMAT_SLINEAR, modem_request)) { ast_log(LOG_ERROR, "Unable to register channel class %s\n", type); ast_destroy(cfg); - unload_module(); + __unload_module(); return -1; } ast_destroy(cfg); @@ -930,59 +988,6 @@ int load_module() return 0; } -int unload_module() -{ - struct ast_modem_pvt *p, *pl; - /* First, take us out of the channel loop */ - ast_channel_unregister(type); - if (!ast_mutex_lock(&iflock)) { - /* Hangup all interfaces if they have an owner */ - p = iflist; - while(p) { - if (p->owner) - ast_softhangup(p->owner, AST_SOFTHANGUP_APPUNLOAD); - p = p->next; - } - iflist = NULL; - ast_mutex_unlock(&iflock); - } else { - ast_log(LOG_WARNING, "Unable to lock the monitor\n"); - return -1; - } - if (!ast_mutex_lock(&monlock)) { - if (monitor_thread != (pthread_t) -1 && monitor_thread != (pthread_t) -2) { - pthread_cancel(monitor_thread); - pthread_join(monitor_thread, NULL); - } - monitor_thread = (pthread_t) -2; - ast_mutex_unlock(&monlock); - } else { - ast_log(LOG_WARNING, "Unable to lock the monitor\n"); - return -1; - } - - if (!ast_mutex_lock(&iflock)) { - /* Destroy all the interfaces and free their memory */ - p = iflist; - while(p) { - /* Close the socket, assuming it's real */ - if (p->fd > -1) - close(p->fd); - pl = p; - p = p->next; - /* Free associated memory */ - free(pl); - } - iflist = NULL; - ast_mutex_unlock(&iflock); - } else { - ast_log(LOG_WARNING, "Unable to lock the monitor\n"); - return -1; - } - - return 0; -} - int usecount(void) { int res; |