use ast_atomic_fetchadd_int in chan_zap, sip, and iax2 for usecount handling
authorRussell Bryant <russell@russellbryant.com>
Sat, 22 Jul 2006 00:33:56 +0000 (00:33 +0000)
committerRussell Bryant <russell@russellbryant.com>
Sat, 22 Jul 2006 00:33:56 +0000 (00:33 +0000)
and fix a couple little things in passing
 - usecnt was not initialized in chan_iax2
 - ast_update_use_count() was not called after incrementing the count in chan_sip

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@38077 65c4cc65-6c06-0410-ace0-fbb531ad65f3

channels/chan_iax2.c
channels/chan_sip.c
channels/chan_zap.c

index 77c611f..d1062a5 100644 (file)
@@ -173,8 +173,7 @@ static int timingfd = -1;                           /* Timing file descriptor */
 static struct ast_netsock_list *netsock;
 static int defaultsockfd = -1;
 
-static int usecnt;
-AST_MUTEX_DEFINE_STATIC(usecnt_lock);
+static int usecnt = 0;
 
 int (*iax2_regfunk)(char *username, int onoff) = NULL;
 
@@ -1688,14 +1687,10 @@ static int iax2_predestroy(int callno)
                c->tech_pvt = NULL;
                ast_queue_hangup(c);
                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_atomic_fetchadd_int(&usecnt, -1);
+               ast_update_use_count();
        }
        ast_mutex_unlock(&iaxsl[callno]);
-       ast_update_use_count();
        return 0;
 }
 
@@ -3293,9 +3288,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_mutex_lock(&usecnt_lock);
-       usecnt++;
-       ast_mutex_unlock(&usecnt_lock);
+       ast_atomic_fetchadd_int(&usecnt, 1);
        ast_update_use_count();
        
        return tmp;
index 751fd41..07ce40d 100644 (file)
@@ -538,8 +538,6 @@ static int regobjs = 0;                     /*!< Registry objects */
 
 static struct ast_flags global_flags[2] = {{0}};       /*!< global SIP_ flags */
 
-AST_MUTEX_DEFINE_STATIC(usecnt_lock);
-
 /*! \brief Protect the SIP dialog list (of sip_pvt's) */
 AST_MUTEX_DEFINE_STATIC(iflock);
 
@@ -3201,9 +3199,7 @@ static int sip_hangup(struct ast_channel *ast)
        p->owner = NULL;
        ast->tech_pvt = NULL;
 
-       ast_mutex_lock(&usecnt_lock);
-       usecnt--;
-       ast_mutex_unlock(&usecnt_lock);
+       ast_atomic_fetchadd_int(&usecnt, -1);
        ast_update_use_count();
 
        ast_set_flag(&locflags, SIP_NEEDDESTROY);       
@@ -3672,9 +3668,8 @@ 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_mutex_lock(&usecnt_lock);
-       usecnt++;
-       ast_mutex_unlock(&usecnt_lock);
+       ast_atomic_fetchadd_int(&usecnt, 1);
+       ast_update_use_count();
        ast_copy_string(tmp->context, i->context, sizeof(tmp->context));
        ast_copy_string(tmp->exten, i->exten, sizeof(tmp->exten));
        ast_set_callerid(tmp, i->cid_num, i->cid_name, i->cid_num);
index 1e005b0..3aa84d0 100644 (file)
@@ -327,7 +327,6 @@ static int gendigittimeout = 8000;
 static int matchdigittimeout = 3000;
 
 static int usecnt = 0;
-AST_MUTEX_DEFINE_STATIC(usecnt_lock);
 
 /*! \brief Protect the interface list (of zt_pvt's) */
 AST_MUTEX_DEFINE_STATIC(iflock);
@@ -2636,11 +2635,7 @@ static int zt_hangup(struct ast_channel *ast)
        p->oprmode = 0;
        ast->tech_pvt = NULL;
        ast_mutex_unlock(&p->lock);
-       ast_mutex_lock(&usecnt_lock);
-       usecnt--;
-       if (usecnt < 0) 
-               ast_log(LOG_WARNING, "Usecnt < 0???\n");
-       ast_mutex_unlock(&usecnt_lock);
+       ast_atomic_fetchadd_int(&usecnt, -1);
        ast_update_use_count();
        if (option_verbose > 2) 
                ast_verbose( VERBOSE_PREFIX_3 "Hungup '%s'\n", ast->name);
@@ -5247,9 +5242,7 @@ static struct ast_channel *zt_new(struct zt_pvt *i, int state, int startpbx, int
                }
        }
 
-       ast_mutex_lock(&usecnt_lock);
-       usecnt++;
-       ast_mutex_unlock(&usecnt_lock);
+       ast_atomic_fetchadd_int(&usecnt, 1);
        ast_update_use_count();
        
        return tmp;