]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
Update channel drivers to use module referencing so that unloading them while in...
authorJoshua Colp <jcolp@digium.com>
Tue, 23 Jan 2007 22:46:31 +0000 (22:46 +0000)
committerJoshua Colp <jcolp@digium.com>
Tue, 23 Jan 2007 22:46:31 +0000 (22:46 +0000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.4@51788 65c4cc65-6c06-0410-ace0-fbb531ad65f3

channels/chan_alsa.c
channels/chan_features.c
channels/chan_gtalk.c
channels/chan_iax2.c
channels/chan_oss.c
channels/chan_phone.c
channels/chan_sip.c
channels/chan_skinny.c
channels/chan_zap.c

index e74df21cb44aee08b1f6a50078406d82576f8229..83900a3deeb01b6baada720cbf44fe2d5e9546ed 100644 (file)
@@ -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)) {
index 89fe1f903abcfd1cdc9cc9d1d0d812546475052f..295b5a0f851d4ff99734f2e05c793cc6901ec560 100644 (file)
@@ -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;
 }
 
index 44ef9364bc4261474d2fdb7fe7b43562d66b9359..41358eaaf7a5394e075ec0e85ecd13a9722f28e4 100644 (file)
@@ -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;
 }
index 6204dcc2305c2009191e7f45a87afd0751d3b8b9..040048c50d649578636d03fb85b8fbdf3d60f77f 100644 (file)
@@ -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;
 }
index 06a2879577bdfd69cd8637f0190f1c6affdaced5..3e23e81729f4ce5a4a4608c2e0fb798de46f9b8d 100644 (file)
@@ -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)) {
index 44d79c25aefe9930eccdf58b2ef8a278c4220034..09a50bafe440d1adb32163120618f52751aac234 100644 (file)
@@ -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)
                        {
index 5c99a2084483794ea3806c06602c9b5a374f91ba..2d7b435c6704278becf9bbc873512a0c3238c51f 100644 (file)
@@ -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));
 
index 9b8faf55e2d0cde21e02f558ddaf893025eed9ed..de321b885653ff5338618a8d5316620c64275565 100644 (file)
@@ -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);
index bbec9c182c96971d53c278b847834160e5f6d297..1420b60370f22d8d9e25577c71027d22ccd260b7 100644 (file)
@@ -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;
 }