diff options
author | file <file@f38db490-d61c-443f-a65b-d21fe96a405b> | 2007-01-23 22:46:31 +0000 |
---|---|---|
committer | file <file@f38db490-d61c-443f-a65b-d21fe96a405b> | 2007-01-23 22:46:31 +0000 |
commit | c7776916251e958e39a2fefd6a28a92fda4db23a (patch) | |
tree | 13789be06a91f943c067cfb42b6a1219d6328d6f /channels/chan_phone.c | |
parent | 2fca1655a1f427219d3a65e2c403a76bde344352 (diff) |
Update channel drivers to use module referencing so that unloading them while in use will not result in crashes. (issue #8897 reported by junky)
git-svn-id: http://svn.digium.com/svn/asterisk/branches/1.4@51788 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'channels/chan_phone.c')
-rw-r--r-- | channels/chan_phone.c | 33 |
1 files changed, 6 insertions, 27 deletions
diff --git a/channels/chan_phone.c b/channels/chan_phone.c index 44d79c25a..09a50bafe 100644 --- a/channels/chan_phone.c +++ b/channels/chan_phone.c @@ -93,7 +93,6 @@ static char context[AST_MAX_EXTENSION] = "default"; /* Default language */ static char language[MAX_LANGUAGE] = ""; -static int usecnt =0; static int echocancel = AEC_OFF; @@ -101,8 +100,6 @@ static int silencesupression = 0; static int prefformat = AST_FORMAT_G723_1 | AST_FORMAT_SLINEAR | AST_FORMAT_ULAW; -AST_MUTEX_DEFINE_STATIC(usecnt_lock); - /* Protect the interface list (of phone_pvt's) */ AST_MUTEX_DEFINE_STATIC(iflock); @@ -385,12 +382,7 @@ static int phone_hangup(struct ast_channel *ast) p->dialtone = 0; memset(p->ext, 0, sizeof(p->ext)); ((struct phone_pvt *)(ast->tech_pvt))->owner = NULL; - ast_mutex_lock(&usecnt_lock); - usecnt--; - if (usecnt < 0) - ast_log(LOG_WARNING, "Usecnt < 0???\n"); - ast_mutex_unlock(&usecnt_lock); - ast_update_use_count(); + ast_module_unref(ast_module_info->self); if (option_verbose > 2) ast_verbose( VERBOSE_PREFIX_3 "Hungup '%s'\n", ast->name); ast->tech_pvt = NULL; @@ -877,10 +869,7 @@ static struct ast_channel *phone_new(struct phone_pvt *i, int state, char *conte tmp->cid.cid_name = ast_strdup(i->cid_name); i->owner = tmp; - ast_mutex_lock(&usecnt_lock); - usecnt++; - ast_mutex_unlock(&usecnt_lock); - ast_update_use_count(); + ast_module_ref(ast_module_info->self); if (state != AST_STATE_DOWN) { if (state == AST_STATE_RING) { ioctl(tmp->fds[0], PHONE_RINGBACK); @@ -960,10 +949,7 @@ static void phone_check_exception(struct phone_pvt *i) if (i->mode == MODE_IMMEDIATE) { phone_new(i, AST_STATE_RING, i->context); } else if (i->mode == MODE_DIALTONE) { - ast_mutex_lock(&usecnt_lock); - usecnt++; - ast_mutex_unlock(&usecnt_lock); - ast_update_use_count(); + ast_module_ref(ast_module_info->self); /* Reset the extension */ i->ext[0] = '\0'; /* Play the dialtone */ @@ -973,10 +959,7 @@ static void phone_check_exception(struct phone_pvt *i) ioctl(i->fd, PHONE_PLAY_START); i->lastformat = -1; } else if (i->mode == MODE_SIGMA) { - ast_mutex_lock(&usecnt_lock); - usecnt++; - ast_mutex_unlock(&usecnt_lock); - ast_update_use_count(); + ast_module_ref(ast_module_info->self); /* Reset the extension */ i->ext[0] = '\0'; /* Play the dialtone */ @@ -984,12 +967,8 @@ static void phone_check_exception(struct phone_pvt *i) ioctl(i->fd, PHONE_DIALTONE); } } else { - if (i->dialtone) { - ast_mutex_lock(&usecnt_lock); - usecnt--; - ast_mutex_unlock(&usecnt_lock); - ast_update_use_count(); - } + if (i->dialtone) + ast_module_unref(ast_module_info->self); memset(i->ext, 0, sizeof(i->ext)); if (i->cpt) { |