aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--channels/chan_alsa.c11
-rw-r--r--channels/chan_features.c8
-rw-r--r--channels/chan_gtalk.c11
-rw-r--r--channels/chan_iax2.c8
-rw-r--r--channels/chan_oss.c13
-rw-r--r--channels/chan_phone.c33
-rw-r--r--channels/chan_sip.c8
-rw-r--r--channels/chan_skinny.c9
-rw-r--r--channels/chan_zap.c8
9 files changed, 20 insertions, 89 deletions
diff --git a/channels/chan_alsa.c b/channels/chan_alsa.c
index e74df21cb..83900a3de 100644
--- a/channels/chan_alsa.c
+++ b/channels/chan_alsa.c
@@ -113,11 +113,9 @@ static char outdevname[50] = ALSA_OUTDEV;
static struct timeval lasttime;
#endif
-static int usecnt;
static int silencesuppression = 0;
static int silencethreshold = 1000;
-AST_MUTEX_DEFINE_STATIC(usecnt_lock);
AST_MUTEX_DEFINE_STATIC(alsalock);
static const char tdesc[] = "ALSA Console Channel Driver";
@@ -573,9 +571,7 @@ static int alsa_hangup(struct ast_channel *c)
c->tech_pvt = NULL;
alsa.owner = NULL;
ast_verbose(" << Hangup on console >> \n");
- ast_mutex_lock(&usecnt_lock);
- usecnt--;
- ast_mutex_unlock(&usecnt_lock);
+ ast_module_unref(ast_module_info->self);
if (hookstate) {
hookstate = 0;
if (!autoanswer) {
@@ -800,10 +796,7 @@ static struct ast_channel *alsa_new(struct chan_alsa_pvt *p, int state)
if (!ast_strlen_zero(language))
ast_string_field_set(tmp, language, language);
p->owner = tmp;
- ast_mutex_lock(&usecnt_lock);
- usecnt++;
- ast_mutex_unlock(&usecnt_lock);
- ast_update_use_count();
+ ast_module_ref(ast_module_info->self);
ast_jb_configure(tmp, &global_jbconf);
if (state != AST_STATE_DOWN) {
if (ast_pbx_start(tmp)) {
diff --git a/channels/chan_features.c b/channels/chan_features.c
index 89fe1f903..295b5a0f8 100644
--- a/channels/chan_features.c
+++ b/channels/chan_features.c
@@ -65,9 +65,6 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
static const char tdesc[] = "Feature Proxy Channel Driver";
-static int usecnt =0;
-AST_MUTEX_DEFINE_STATIC(usecnt_lock);
-
#define IS_OUTBOUND(a,b) (a == b->chan ? 1 : 0)
struct feature_sub {
@@ -492,10 +489,7 @@ static struct ast_channel *features_new(struct feature_pvt *p, int state, int in
p->subs[index].owner = tmp;
if (!p->owner)
p->owner = tmp;
- ast_mutex_lock(&usecnt_lock);
- usecnt++;
- ast_mutex_unlock(&usecnt_lock);
- ast_update_use_count();
+ ast_module_ref(ast_module_info->self);
return tmp;
}
diff --git a/channels/chan_gtalk.c b/channels/chan_gtalk.c
index 44ef9364b..41358eaaf 100644
--- a/channels/chan_gtalk.c
+++ b/channels/chan_gtalk.c
@@ -164,9 +164,6 @@ struct gtalk_container {
static const char desc[] = "Gtalk Channel";
-static int usecnt = 0;
-AST_MUTEX_DEFINE_STATIC(usecnt_lock);
-
static int global_capability = AST_FORMAT_ULAW | AST_FORMAT_ALAW | AST_FORMAT_GSM | AST_FORMAT_H263;
AST_MUTEX_DEFINE_STATIC(gtalklock); /*!< Protect the interface list (of gtalk_pvt's) */
@@ -953,9 +950,7 @@ static struct ast_channel *gtalk_new(struct gtalk *client, struct gtalk_pvt *i,
if (!ast_strlen_zero(client->musicclass))
ast_string_field_set(tmp, musicclass, client->musicclass);
i->owner = tmp;
- ast_mutex_lock(&usecnt_lock);
- usecnt++;
- ast_mutex_unlock(&usecnt_lock);
+ ast_module_ref(ast_module_info->self);
ast_copy_string(tmp->context, client->context, sizeof(tmp->context));
ast_copy_string(tmp->exten, i->exten, sizeof(tmp->exten));
/* Don't use ast_set_callerid() here because it will
@@ -1467,9 +1462,7 @@ static int gtalk_hangup(struct ast_channel *ast)
ast_mutex_unlock(&p->lock);
gtalk_free_pvt(client, p);
- ast_mutex_lock(&usecnt_lock);
- usecnt--;
- ast_mutex_unlock(&usecnt_lock);
+ ast_module_unref(ast_module_info->self);
return 0;
}
diff --git a/channels/chan_iax2.c b/channels/chan_iax2.c
index 6204dcc23..040048c50 100644
--- a/channels/chan_iax2.c
+++ b/channels/chan_iax2.c
@@ -173,8 +173,6 @@ static int timingfd = -1; /* Timing file descriptor */
static struct ast_netsock_list *netsock;
static int defaultsockfd = -1;
-static int usecnt = 0;
-
int (*iax2_regfunk)(const char *username, int onoff) = NULL;
/* Ethernet, etc */
@@ -1716,8 +1714,7 @@ static int iax2_predestroy(int callno)
c->tech_pvt = NULL;
ast_queue_hangup(c);
pvt->owner = NULL;
- ast_atomic_fetchadd_int(&usecnt, -1);
- ast_update_use_count();
+ ast_module_unref(ast_module_info->self);
}
return 0;
}
@@ -3302,8 +3299,7 @@ static struct ast_channel *ast_iax2_new(int callno, int state, int capability)
for (v = i->vars ; v ; v = v->next)
pbx_builtin_setvar_helper(tmp, v->name, v->value);
- ast_atomic_fetchadd_int(&usecnt, 1);
- ast_update_use_count();
+ ast_module_ref(ast_module_info->self);
return tmp;
}
diff --git a/channels/chan_oss.c b/channels/chan_oss.c
index 06a287957..3e23e8172 100644
--- a/channels/chan_oss.c
+++ b/channels/chan_oss.c
@@ -281,10 +281,6 @@ END_CONFIG
#define MAX(a,b) ((a) > (b) ? (a) : (b))
#endif
-
-static int usecnt;
-AST_MUTEX_DEFINE_STATIC(usecnt_lock);
-
static char *config = "oss.conf"; /* default config file */
static int oss_debug;
@@ -842,9 +838,7 @@ static int oss_hangup(struct ast_channel *c)
c->tech_pvt = NULL;
o->owner = NULL;
ast_verbose(" << Hangup on console >> \n");
- ast_mutex_lock(&usecnt_lock); /* XXX not sure why */
- usecnt--;
- ast_mutex_unlock(&usecnt_lock);
+ ast_module_unref(ast_module_info->self);
if (o->hookstate) {
if (o->autoanswer || o->autohangup) {
/* Assume auto-hangup too */
@@ -1025,10 +1019,7 @@ static struct ast_channel *oss_new(struct chan_oss_pvt *o, char *ext, char *ctx,
c->cid.cid_dnid = ast_strdup(ext);
o->owner = c;
- ast_mutex_lock(&usecnt_lock);
- usecnt++;
- ast_mutex_unlock(&usecnt_lock);
- ast_update_use_count();
+ ast_module_ref(ast_module_info->self);
ast_jb_configure(c, &global_jbconf);
if (state != AST_STATE_DOWN) {
if (ast_pbx_start(c)) {
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)
{
diff --git a/channels/chan_sip.c b/channels/chan_sip.c
index 5c99a2084..2d7b435c6 100644
--- a/channels/chan_sip.c
+++ b/channels/chan_sip.c
@@ -221,8 +221,6 @@ static struct ast_jb_conf global_jbconf;
static const char config[] = "sip.conf";
static const char notify_config[] = "sip_notify.conf";
-static int usecnt = 0;
-
#define RTP 1
#define NO_RTP 0
@@ -3324,8 +3322,7 @@ static int sip_hangup(struct ast_channel *ast)
p->owner = NULL;
ast->tech_pvt = NULL;
- ast_atomic_fetchadd_int(&usecnt, -1);
- ast_update_use_count();
+ ast_module_unref(ast_module_info->self);
/* Do not destroy this pvt until we have timeout or
get an answer to the BYE or INVITE/CANCEL
@@ -3852,8 +3849,7 @@ static struct ast_channel *sip_new(struct sip_pvt *i, int state, const char *tit
if (!ast_strlen_zero(i->language))
ast_string_field_set(tmp, language, i->language);
i->owner = tmp;
- ast_atomic_fetchadd_int(&usecnt, 1);
- ast_update_use_count();
+ ast_module_ref(ast_module_info->self);
ast_copy_string(tmp->context, i->context, sizeof(tmp->context));
ast_copy_string(tmp->exten, i->exten, sizeof(tmp->exten));
diff --git a/channels/chan_skinny.c b/channels/chan_skinny.c
index 9b8faf55e..de321b885 100644
--- a/channels/chan_skinny.c
+++ b/channels/chan_skinny.c
@@ -868,10 +868,6 @@ static char *skinny_cxmodes[] = {
static struct sched_context *sched;
static struct io_context *io;
-/* usage count and locking */
-static int usecnt = 0;
-AST_MUTEX_DEFINE_STATIC(usecnt_lock);
-
/* Protect the monitoring thread, so only one process can kill or start it, and not
when it's doing something critical. */
AST_MUTEX_DEFINE_STATIC(monlock);
@@ -2754,10 +2750,7 @@ static struct ast_channel *skinny_new(struct skinny_line *l, int state)
if (l->amaflags)
tmp->amaflags = l->amaflags;
- ast_mutex_lock(&usecnt_lock);
- usecnt++;
- ast_mutex_unlock(&usecnt_lock);
- ast_update_use_count();
+ ast_module_ref(ast_module_info->self);
tmp->callgroup = l->callgroup;
tmp->pickupgroup = l->pickupgroup;
ast_string_field_set(tmp, call_forward, l->call_forward);
diff --git a/channels/chan_zap.c b/channels/chan_zap.c
index bbec9c182..1420b6037 100644
--- a/channels/chan_zap.c
+++ b/channels/chan_zap.c
@@ -229,8 +229,6 @@ static int gendigittimeout = 8000;
/*! \brief How long to wait for an extra digit, if there is an ambiguous match */
static int matchdigittimeout = 3000;
-static int usecnt = 0;
-
/*! \brief Protect the interface list (of zt_pvt's) */
AST_MUTEX_DEFINE_STATIC(iflock);
@@ -2703,8 +2701,7 @@ static int zt_hangup(struct ast_channel *ast)
p->oprmode = 0;
ast->tech_pvt = NULL;
ast_mutex_unlock(&p->lock);
- ast_atomic_fetchadd_int(&usecnt, -1);
- 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);
@@ -5324,8 +5321,7 @@ static struct ast_channel *zt_new(struct zt_pvt *i, int state, int startpbx, int
}
}
- ast_atomic_fetchadd_int(&usecnt, 1);
- ast_update_use_count();
+ ast_module_ref(ast_module_info->self);
return tmp;
}