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_vpb.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_vpb.c')
-rwxr-xr-x | channels/chan_vpb.c | 110 |
1 files changed, 57 insertions, 53 deletions
diff --git a/channels/chan_vpb.c b/channels/chan_vpb.c index d4aee06f5..b2a54d37c 100755 --- a/channels/chan_vpb.c +++ b/channels/chan_vpb.c @@ -1112,6 +1112,62 @@ static float parse_gain_value(char *gain_type, char *value) return gain; } +static int __unload_module(void) +{ + struct vpb_pvt *p; + /* First, take us out of the channel loop */ + ast_channel_unregister(type); + + 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); + + ast_mutex_lock(&monlock); { + if (mthreadactive > -1) { + pthread_cancel(monitor_thread); + pthread_join(monitor_thread, NULL); + } + mthreadactive = -2; + } ast_mutex_unlock(&monlock); + + ast_mutex_lock(&iflock); { + /* Destroy all the interfaces and free their memory */ + + while(iflist) { + p = iflist; + ast_mutex_destroy(&p->lock); + pthread_cancel(p->readthread); + p->readthread = 0; + + iflist = iflist->next; + + free(p); + } + iflist = NULL; + } ast_mutex_unlock(&iflock); + + ast_mutex_lock(&bridge_lock); { + memset(bridges, 0, sizeof bridges); + } ast_mutex_unlock(&bridge_lock); + ast_mutex_destroy(&bridge_lock); + + tcounter = 0; + + return 0; +} + +int unload_module(void) +{ + return __unload_module(); +} + int load_module() { struct ast_config *cfg; @@ -1213,65 +1269,13 @@ int load_module() if (error) - unload_module(); + __unload_module(); else restart_monitor(); /* And start the monitor for the first time */ return error; } - -int unload_module() -{ - struct vpb_pvt *p; - /* First, take us out of the channel loop */ - ast_channel_unregister(type); - - 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); - - ast_mutex_lock(&monlock); { - if (mthreadactive > -1) { - pthread_cancel(monitor_thread); - pthread_join(monitor_thread, NULL); - } - mthreadactive = -2; - } ast_mutex_unlock(&monlock); - - ast_mutex_lock(&iflock); { - /* Destroy all the interfaces and free their memory */ - - while(iflist) { - p = iflist; - ast_mutex_destroy(&p->lock); - pthread_cancel(p->readthread); - p->readthread = 0; - - iflist = iflist->next; - - free(p); - } - iflist = NULL; - } ast_mutex_unlock(&iflock); - - ast_mutex_lock(&bridge_lock); { - memset(bridges, 0, sizeof bridges); - } ast_mutex_unlock(&bridge_lock); - ast_mutex_destroy(&bridge_lock); - - tcounter = 0; - - return 0; -} - int usecount() { int res; |