More ast_channel_lock fixes
authorOlle Johansson <oej@edvina.net>
Sat, 15 Apr 2006 15:07:39 +0000 (15:07 +0000)
committerOlle Johansson <oej@edvina.net>
Sat, 15 Apr 2006 15:07:39 +0000 (15:07 +0000)
- Update lock.h with definitions of ast_channel_lock, ast_channel_unlock and ast_channel_trylock
- Convert some functions (but not all) in channel.c
- Fix some bugs in chan_sip.c
- Convert rest of chan_sip.c

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

channel.c
channels/chan_sip.c
include/asterisk/lock.h

index 303cc32..b6236d4 100644 (file)
--- a/channel.c
+++ b/channel.c
@@ -1408,7 +1408,7 @@ int ast_hangup(struct ast_channel *chan)
 
        /* Don't actually hang up a channel that will masquerade as someone else, or
           if someone is going to masquerade as us */
-       ast_mutex_lock(&chan->lock);
+       ast_channel_lock(chan);
 
        detach_spies(chan);             /* get rid of spies */
 
@@ -1419,14 +1419,14 @@ int ast_hangup(struct ast_channel *chan)
 
        if (chan->masq) {
                ast_log(LOG_WARNING, "%s getting hung up, but someone is trying to masq into us?!?\n", chan->name);
-               ast_mutex_unlock(&chan->lock);
+               ast_channel_unlock(chan);
                return 0;
        }
        /* If this channel is one which will be masqueraded into something,
           mark it as a zombie already, so we know to free it later */
        if (chan->masqr) {
                ast_set_flag(chan, AST_FLAG_ZOMBIE);
-               ast_mutex_unlock(&chan->lock);
+               ast_channel_unlock(chan);
                return 0;
        }
        free_translation(chan);
@@ -1464,7 +1464,7 @@ int ast_hangup(struct ast_channel *chan)
                        ast_log(LOG_DEBUG, "Hanging up zombie '%s'\n", chan->name);
        }
                        
-       ast_mutex_unlock(&chan->lock);
+       ast_channel_unlock(chan);
        manager_event(EVENT_FLAG_CALL, "Hangup",
                        "Channel: %s\r\n"
                        "Uniqueid: %s\r\n"
@@ -1482,7 +1482,7 @@ int ast_hangup(struct ast_channel *chan)
 int ast_answer(struct ast_channel *chan)
 {
        int res = 0;
-       ast_mutex_lock(&chan->lock);
+       ast_channel_lock(chan);
        /* Stop if we're a zombie or need a soft hangup */
        if (ast_test_flag(chan, AST_FLAG_ZOMBIE) || ast_check_hangup(chan)) {
                ast_mutex_unlock(&chan->lock);
@@ -1496,7 +1496,7 @@ int ast_answer(struct ast_channel *chan)
                ast_setstate(chan, AST_STATE_UP);
                if (chan->cdr)
                        ast_cdr_answer(chan->cdr);
-               ast_mutex_unlock(&chan->lock);
+               ast_channel_unlock(chan);
                return res;
                break;
        case AST_STATE_UP:
@@ -1504,7 +1504,7 @@ int ast_answer(struct ast_channel *chan)
                        ast_cdr_answer(chan->cdr);
                break;
        }
-       ast_mutex_unlock(&chan->lock);
+       ast_channel_unlock(chan);
        return 0;
 }
 
@@ -1546,7 +1546,7 @@ int ast_activate_generator(struct ast_channel *chan, struct ast_generator *gen,
 {
        int res = 0;
 
-       ast_mutex_lock(&chan->lock);
+       ast_channel_lock(chan);
 
        if (chan->generatordata) {
                if (chan->generator && chan->generator->release)
@@ -1564,7 +1564,7 @@ int ast_activate_generator(struct ast_channel *chan, struct ast_generator *gen,
                chan->generator = gen;
        }
 
-       ast_mutex_unlock(&chan->lock);
+       ast_channel_unlock(chan);
 
        return res;
 }
@@ -1609,12 +1609,12 @@ struct ast_channel *ast_waitfor_nandfds(struct ast_channel **c, int n, int *fds,
        
        /* Perform any pending masquerades */
        for (x=0; x < n; x++) {
-               ast_mutex_lock(&c[x]->lock);
+               ast_channel_lock(c[x]);
                if (c[x]->masq) {
                        if (ast_do_masquerade(c[x])) {
                                ast_log(LOG_WARNING, "Masquerade failed\n");
                                *ms = -1;
-                               ast_mutex_unlock(&c[x]->lock);
+                               ast_channel_unlock(c[x]);
                                return NULL;
                        }
                }
@@ -1625,13 +1625,13 @@ struct ast_channel *ast_waitfor_nandfds(struct ast_channel **c, int n, int *fds,
                        if (diff < 1) {
                                /* Should already be hungup */
                                c[x]->_softhangup |= AST_SOFTHANGUP_TIMEOUT;
-                               ast_mutex_unlock(&c[x]->lock);
+                               ast_channel_unlock(c[x]);
                                return c[x];
                        }
                        if (!whentohangup || (diff < whentohangup))
                                whentohangup = diff;
                }
-               ast_mutex_unlock(&c[x]->lock);
+               ast_channel_unlock(c[x]);
        }
        /* Wait full interval */
        rms = *ms;
@@ -1858,14 +1858,14 @@ static struct ast_frame *__ast_read(struct ast_channel *chan, int dropaudio)
        void *data;
        int res;
 #endif
-       ast_mutex_lock(&chan->lock);
+       ast_channel_lock(chan);
        if (chan->masq) {
                if (ast_do_masquerade(chan)) {
                        ast_log(LOG_WARNING, "Failed to perform masquerade\n");
                        f = NULL;
                } else
                        f =  &ast_null_frame;
-               ast_mutex_unlock(&chan->lock);
+               ast_channel_unlock(chan);
                return f;
        }
 
@@ -1873,7 +1873,7 @@ static struct ast_frame *__ast_read(struct ast_channel *chan, int dropaudio)
        if (ast_test_flag(chan, AST_FLAG_ZOMBIE) || ast_check_hangup(chan)) {
                if (chan->generator)
                        ast_deactivate_generator(chan);
-               ast_mutex_unlock(&chan->lock);
+               ast_channel_unlock(chan);
                return NULL;
        }
        prestate = chan->_state;
@@ -1884,7 +1884,7 @@ static struct ast_frame *__ast_read(struct ast_channel *chan, int dropaudio)
                chan->dtmff.subclass = chan->dtmfq[0];
                /* Drop first digit */
                memmove(chan->dtmfq, chan->dtmfq + 1, sizeof(chan->dtmfq) - 1);
-               ast_mutex_unlock(&chan->lock);
+               ast_channel_unlock(chan);
                return &chan->dtmff;
        }
        
@@ -1912,7 +1912,7 @@ static struct ast_frame *__ast_read(struct ast_channel *chan, int dropaudio)
                        ioctl(chan->timingfd, ZT_TIMERACK, &blah);
                        func = chan->timingfunc;
                        data = chan->timingdata;
-                       ast_mutex_unlock(&chan->lock);
+                       ast_channel_unlock(chan);
                        if (func) {
 #if 0
                                ast_log(LOG_DEBUG, "Calling private function\n");
@@ -1920,10 +1920,10 @@ static struct ast_frame *__ast_read(struct ast_channel *chan, int dropaudio)
                                func(data);
                        } else {
                                blah = 0;
-                               ast_mutex_lock(&chan->lock);
+                               ast_channel_lock(chan);
                                ioctl(chan->timingfd, ZT_TIMERCONFIG, &blah);
                                chan->timingdata = NULL;
-                               ast_mutex_unlock(&chan->lock);
+                               ast_channel_unlock(chan);
                        }
                        return &ast_null_frame;
                } else
@@ -2313,28 +2313,28 @@ int ast_write(struct ast_channel *chan, struct ast_frame *fr)
        int res = -1;
        struct ast_frame *f = NULL;
        /* Stop if we're a zombie or need a soft hangup */
-       ast_mutex_lock(&chan->lock);
+       ast_channel_lock(chan);
        if (ast_test_flag(chan, AST_FLAG_ZOMBIE) || ast_check_hangup(chan))  {
-               ast_mutex_unlock(&chan->lock);
+               ast_channel_unlock(chan);
                return -1;
        }
        /* Handle any pending masquerades */
        if (chan->masq) {
                if (ast_do_masquerade(chan)) {
                        ast_log(LOG_WARNING, "Failed to perform masquerade\n");
-                       ast_mutex_unlock(&chan->lock);
+                       ast_channel_unlock(chan);
                        return -1;
                }
        }
        if (chan->masqr) {
-               ast_mutex_unlock(&chan->lock);
+               ast_channel_unlock(chan);
                return 0;
        }
        if (chan->generatordata) {
                if (ast_test_flag(chan, AST_FLAG_WRITE_INT))
                        ast_deactivate_generator(chan);
                else {
-                       ast_mutex_unlock(&chan->lock);
+                       ast_channel_unlock(chan);
                        return 0;
                }
        }
@@ -2361,9 +2361,9 @@ int ast_write(struct ast_channel *chan, struct ast_frame *fr)
                break;
        case AST_FRAME_DTMF:
                ast_clear_flag(chan, AST_FLAG_BLOCKING);
-               ast_mutex_unlock(&chan->lock);
+               ast_channel_unlock(chan);
                res = do_senddigit(chan,fr->subclass);
-               ast_mutex_lock(&chan->lock);
+               ast_channel_lock(chan);
                CHECK_BLOCKING(chan);
                break;
        case AST_FRAME_TEXT:
@@ -2439,7 +2439,7 @@ int ast_write(struct ast_channel *chan, struct ast_frame *fr)
                else
                        chan->fout++;
        }
-       ast_mutex_unlock(&chan->lock);
+       ast_channel_unlock(chan);
        return res;
 }
 
@@ -2468,7 +2468,7 @@ static int set_format(struct ast_channel *chan, int fmt, int *rawformat, int *fo
        }
        
        /* Now we have a good choice for both. */
-       ast_mutex_lock(&chan->lock);
+       ast_channel_lock(chan);
        *rawformat = native;
        /* User perspective is fmt */
        *format = fmt;
@@ -2482,7 +2482,7 @@ static int set_format(struct ast_channel *chan, int fmt, int *rawformat, int *fo
        else
                /* writing */
                *trans = ast_translator_build_path(*rawformat, *format);
-       ast_mutex_unlock(&chan->lock);
+       ast_channel_unlock(chan);
        if (option_debug)
                ast_log(LOG_DEBUG, "Set channel %s to %s format %s\n", chan->name,
                        direction ? "write" : "read", ast_getformatname(fmt));
@@ -3015,9 +3015,10 @@ int ast_do_masquerade(struct ast_channel *original)
           while the features are nice, the cost is very high in terms of pure nastiness. XXX */
 
        /* We need the clone's lock, too */
-       ast_mutex_lock(&clone->lock);
+       ast_channel_lock(clone);
 
-       ast_log(LOG_DEBUG, "Got clone lock for masquerade on '%s' at %p\n", clone->name, &clone->lock);
+       if (option_debug > 1)
+               ast_log(LOG_DEBUG, "Got clone lock for masquerade on '%s' at %p\n", clone->name, &clone->lock);
 
        /* Having remembered the original read/write formats, we turn off any translation on either
           one */
@@ -3116,7 +3117,7 @@ int ast_do_masquerade(struct ast_channel *original)
                res = clone->tech->hangup(clone);
        if (res) {
                ast_log(LOG_WARNING, "Hangup failed!  Strange things may happen!\n");
-               ast_mutex_unlock(&clone->lock);
+               ast_channel_unlock(clone);
                return -1;
        }
        
@@ -3181,7 +3182,8 @@ int ast_do_masquerade(struct ast_channel *original)
        /* Copy the music class */
        ast_string_field_set(original, musicclass, clone->musicclass);
 
-       ast_log(LOG_DEBUG, "Putting channel %s in %d/%d formats\n", original->name, wformat, rformat);
+       if (option_debug)
+               ast_log(LOG_DEBUG, "Putting channel %s in %d/%d formats\n", original->name, wformat, rformat);
 
        /* Okay.  Last thing is to let the channel driver know about all this mess, so he
           can fix up everything as best as possible */
@@ -3190,7 +3192,7 @@ int ast_do_masquerade(struct ast_channel *original)
                if (res) {
                        ast_log(LOG_WARNING, "Channel for type '%s' could not fixup channel %s\n",
                                original->tech->type, original->name);
-                       ast_mutex_unlock(&clone->lock);
+                       ast_channel_unlock(clone);
                        return -1;
                }
        } else
@@ -3201,8 +3203,9 @@ int ast_do_masquerade(struct ast_channel *original)
           a zombie so nothing tries to touch it.  If it's already been marked as a
           zombie, then free it now (since it already is considered invalid). */
        if (ast_test_flag(clone, AST_FLAG_ZOMBIE)) {
-               ast_log(LOG_DEBUG, "Destroying channel clone '%s'\n", clone->name);
-               ast_mutex_unlock(&clone->lock);
+               if (option_debug)
+                       ast_log(LOG_DEBUG, "Destroying channel clone '%s'\n", clone->name);
+               ast_channel_unlock(clone);
                manager_event(EVENT_FLAG_CALL, "Hangup",
                        "Channel: %s\r\n"
                        "Uniqueid: %s\r\n"
@@ -3218,13 +3221,14 @@ int ast_do_masquerade(struct ast_channel *original)
                ast_log(LOG_DEBUG, "Released clone lock on '%s'\n", clone->name);
                ast_set_flag(clone, AST_FLAG_ZOMBIE);
                ast_queue_frame(clone, &ast_null_frame);
-               ast_mutex_unlock(&clone->lock);
+               ast_channel_unlock(clone);
        }
        
        /* Signal any blocker */
        if (ast_test_flag(original, AST_FLAG_BLOCKING))
                pthread_kill(original->blocker, SIGURG);
-       ast_log(LOG_DEBUG, "Done Masquerading %s (%d)\n", original->name, original->_state);
+       if (option_debug)
+               ast_log(LOG_DEBUG, "Done Masquerading %s (%d)\n", original->name, original->_state);
        return 0;
 }
 
index 2624969..dac1d63 100644 (file)
@@ -1339,12 +1339,12 @@ static int append_history_full(struct sip_pvt *p, const char *fmt, ...)
 /*! \brief Retransmit SIP message if no answer */
 static int retrans_pkt(void *data)
 {
-       struct sip_pkt *pkt=data, *prev, *cur = NULL;
+       struct sip_pkt *pkt = data, *prev, *cur = NULL;
        char iabuf[INET_ADDRSTRLEN];
        int reschedule = DEFAULT_RETRANS;
 
-       /* Lock channel */
-       ast_channel_lock(&pkt->owner);
+       /* Lock channel PVT */
+       ast_mutex_lock(&pkt->owner->lock);
 
        if (pkt->retrans < MAX_RETRANS) {
                pkt->retrans++;
@@ -1381,7 +1381,7 @@ static int retrans_pkt(void *data)
 
                append_history(pkt->owner, "ReTx", "%d %s", reschedule, pkt->data);
                __sip_xmit(pkt->owner, pkt->data, pkt->packetlen);
-               ast_channel_unlock(&pkt->owner);
+               ast_mutex_unlock(&pkt->owner->lock);
                return  reschedule;
        } 
        /* Too many retries */
@@ -1406,7 +1406,7 @@ static int retrans_pkt(void *data)
                        ast_set_flag(&pkt->owner->flags[0], SIP_ALREADYGONE);
                        ast_log(LOG_WARNING, "Hanging up call %s - no reply to our critical packet.\n", pkt->owner->callid);
                        ast_queue_hangup(pkt->owner->owner);
-                       ast_mutex_unlock(&pkt->owner->owner->lock);
+                       ast_channel_unlock(pkt->owner->owner);
                } else {
                        /* If no channel owner, destroy now */
                        ast_set_flag(&pkt->owner->flags[0], SIP_NEEDDESTROY);   
@@ -2153,10 +2153,10 @@ static int auto_congest(void *nothing)
        p->initid = -1;
        if (p->owner) {
                /* XXX fails on possible deadlock */
-               if (!ast_mutex_trylock(&p->owner->lock)) {
+               if (!ast_channel_trylock(p->owner)) {
                        ast_log(LOG_NOTICE, "Auto-congesting %s\n", p->owner->name);
                        ast_queue_control(p->owner, AST_CONTROL_CONGESTION);
-                       ast_mutex_unlock(&p->owner->lock);
+                       ast_channel_unlock(p->owner);
                }
        }
        ast_mutex_unlock(&p->lock);
@@ -2284,12 +2284,12 @@ static void __sip_destroy(struct sip_pvt *p, int lockowner)
        /* Unlink us from the owner if we have one */
        if (p->owner) {
                if (lockowner)
-                       ast_mutex_lock(&p->owner->lock);
+                       ast_channel_lock(p->owner);
                if (option_debug)
                        ast_log(LOG_DEBUG, "Detaching from %s\n", p->owner->name);
                p->owner->tech_pvt = NULL;
                if (lockowner)
-                       ast_mutex_unlock(&p->owner->lock);
+                       ast_channel_unlock(p->owner);
        }
        /* Clear history */
        if (p->history) {
@@ -6819,7 +6819,7 @@ static struct sip_pvt *get_sip_pvt_byid_locked(char *callid)
                        /* Go ahead and lock it (and its owner) before returning */
                        ast_mutex_lock(&sip_pvt_ptr->lock);
                        if (sip_pvt_ptr->owner) {
-                               while(ast_mutex_trylock(&sip_pvt_ptr->owner->lock)) {
+                               while(ast_channel_trylock(sip_pvt_ptr->owner)) {
                                        ast_mutex_unlock(&sip_pvt_ptr->lock);
                                        usleep(1);
                                        ast_mutex_lock(&sip_pvt_ptr->lock);
@@ -9423,10 +9423,10 @@ int func_header_read(struct ast_channel *chan, char *function, char *data, char
                return -1;
        }
 
-       ast_mutex_lock(&chan->lock);
+       ast_channel_lock(chan);
        if (chan->tech != &sip_tech) {
                ast_log(LOG_WARNING, "This function can only be used on SIP channels.\n");
-               ast_mutex_unlock(&chan->lock);
+               ast_channel_unlock(chan);
                return -1;
        }
 
@@ -9434,19 +9434,19 @@ int func_header_read(struct ast_channel *chan, char *function, char *data, char
 
        /* If there is no private structure, this channel is no longer alive */
        if (!p) {
-               ast_mutex_unlock(&chan->lock);
+               ast_channel_unlock(chan);
                return -1;
        }
 
        content = get_header(&p->initreq, data);
 
        if (ast_strlen_zero(content)) {
-               ast_mutex_unlock(&chan->lock);
+               ast_channel_unlock(chan);
                return -1;
        }
 
        ast_copy_string(buf, content, len);
-       ast_mutex_unlock(&chan->lock);
+       ast_channel_unlock(chan);
 
        return 0;
 }
@@ -9589,10 +9589,10 @@ int function_sipchaninfo_read(struct ast_channel *chan, char *cmd, char *data, c
                return -1;
        }
 
-       ast_mutex_lock(&chan->lock);
+       ast_channel_lock(chan);
        if (chan->tech != &sip_tech) {
                ast_log(LOG_WARNING, "This function can only be used on SIP channels.\n");
-               ast_mutex_unlock(&chan->lock);
+               ast_channel_unlock(chan);
                return -1;
        }
 
@@ -9600,7 +9600,7 @@ int function_sipchaninfo_read(struct ast_channel *chan, char *cmd, char *data, c
 
        /* If there is no private structure, this channel is no longer alive */
        if (!p) {
-               ast_mutex_unlock(&chan->lock);
+               ast_channel_unlock(chan);
                return -1;
        }
 
@@ -9617,10 +9617,10 @@ int function_sipchaninfo_read(struct ast_channel *chan, char *cmd, char *data, c
        } else  if (!strcasecmp(data, "peername")) {
                ast_copy_string(buf, p->peername, len);
        } else {
-               ast_mutex_unlock(&chan->lock);
+               ast_channel_unlock(chan);
                return -1;
        }
-       ast_mutex_unlock(&chan->lock);
+       ast_channel_unlock(chan);
 
        return 0;
 }
@@ -10421,9 +10421,9 @@ static void *sip_park_thread(void *stuff)
        chan2 = d->chan2;
        copy_request(&req, &d->req);
        free(d);
-       ast_mutex_lock(&chan1->lock);
+       ast_channel_lock(chan1);
        ast_do_masquerade(chan1);
-       ast_mutex_unlock(&chan1->lock);
+       ast_channel_unlock(chan1);
        res = ast_park_call(chan1, chan2, 0, &ext);
        /* Then hangup */
        ast_hangup(chan2);
@@ -10472,15 +10472,15 @@ static int sip_park(struct ast_channel *chan1, struct ast_channel *chan2, struct
        ast_copy_string(chan2m->context, chan2->context, sizeof(chan2m->context));
        ast_copy_string(chan2m->exten, chan2->exten, sizeof(chan2m->exten));
        chan2m->priority = chan2->priority;
-       ast_mutex_lock(&chan2m->lock);
+       ast_channel_lock(chan2m);
        if (ast_do_masquerade(chan2m)) {
                ast_log(LOG_WARNING, "Masquerade failed :(\n");
-               ast_mutex_unlock(&chan2m->lock);
+               ast_channel_unlock(chan2m);
                chan2m->hangupcause = AST_CAUSE_SWITCH_CONGESTION;
                ast_hangup(chan2m);
                return -1;
        }
-       ast_mutex_unlock(&chan2m->lock);
+       ast_channel_unlock(chan2m);
        if ((d = ast_calloc(1, sizeof(*d)))) {
                /* Save original request for followup */
                copy_request(&d->req, req);
@@ -10914,7 +10914,7 @@ static int handle_request_invite(struct sip_pvt *p, struct sip_request *req, int
                        build_route(p, req, 0);
                        if (c) {
                                /* Pre-lock the call */
-                               ast_mutex_lock(&c->lock);
+                               ast_channel_lock(c);
                        }
                }
                
@@ -10961,14 +10961,14 @@ static int handle_request_invite(struct sip_pvt *p, struct sip_request *req, int
 
                                if (res) {
                                        /* Unlock locks so ast_hangup can do its magic */
-                                       ast_mutex_unlock(&c->lock);
-                                       ast_mutex_unlock(&p->lock);
+                                       ast_channel_unlock(c);
+                                       ast_channel_unlock(p);
                                        ast_hangup(c);
                                        ast_mutex_lock(&p->lock);
                                        c = NULL;
                                }
                        } else {        /* Pickup call in call group */
-                               ast_mutex_unlock(&c->lock);
+                               ast_channel_unlock(c);
                                if (ast_pickup_call(c)) {
                                        ast_log(LOG_NOTICE, "Nothing to pick up for %s\n", p->callid);
                                        if (ast_test_flag(req, SIP_PKT_IGNORE))
@@ -11073,7 +11073,7 @@ static int handle_request_refer(struct sip_pvt *p, struct sip_request *req, int
                                ast_log(LOG_DEBUG,"202 Accepted (supervised)\n");
                                attempt_transfer(p, p->refer_call);
                                if (p->refer_call->owner)
-                                       ast_mutex_unlock(&p->refer_call->owner->lock);
+                                       ast_channel_unlock(p->refer_call->owner);
                                ast_mutex_unlock(&p->refer_call->lock);
                                p->refer_call = NULL;
                                ast_set_flag(&p->flags[0], SIP_GOTREFER);       
@@ -11089,14 +11089,14 @@ static int handle_request_refer(struct sip_pvt *p, struct sip_request *req, int
                                                        /* Must release c's lock now, because it will not longer
                                                            be accessible after the transfer! */
                                                        *nounlock = 1;
-                                                       ast_mutex_unlock(&c->lock);
+                                                       ast_channel_unlock(c);
                                                        sip_park(transfer_to, c, req);
                                                        nobye = 1;
                                                } else {
                                                        /* Must release c's lock now, because it will not longer
                                                            be accessible after the transfer! */
                                                        *nounlock = 1;
-                                                       ast_mutex_unlock(&c->lock);
+                                                       ast_channel_unlock(c);
                                                        ast_async_goto(transfer_to,p->context, p->refer_to,1);
                                                }
                                        } else {
@@ -11725,7 +11725,7 @@ retrylock:
        if (p) {
                /* Go ahead and lock the owner if it has one -- we may need it */
                /* becaues this is deadlock-prone, we need to try and unlock if failed */
-               if (p->owner && ast_mutex_trylock(&p->owner->lock)) {
+               if (p->owner && ast_channel_trylock(p->owner)) {
                        ast_log(LOG_DEBUG, "Failed to grab lock, trying again...\n");
                        ast_mutex_unlock(&p->lock);
                        ast_mutex_unlock(&netlock);
@@ -11743,7 +11743,7 @@ retrylock:
                }
                
                if (p->owner && !nounlock)
-                       ast_mutex_unlock(&p->owner->lock);
+                       ast_channel_unlock(p->owner);
                ast_mutex_unlock(&p->lock);
        }
        ast_mutex_unlock(&netlock);
@@ -11872,7 +11872,7 @@ restartsearch:
                                                          (t > sip->lastrtprx + sip->rtpholdtimeout))) {
                                                /* Needs a hangup */
                                                if (sip->rtptimeout) {
-                                                       while(sip->owner && ast_mutex_trylock(&sip->owner->lock)) {
+                                                       while(sip->owner && ast_channel_trylock(sip->owner)) {
                                                                ast_mutex_unlock(&sip->lock);
                                                                usleep(1);
                                                                ast_mutex_lock(&sip->lock);
@@ -11881,7 +11881,7 @@ restartsearch:
                                                                ast_log(LOG_NOTICE, "Disconnecting call '%s' for lack of RTP activity in %ld seconds\n", sip->owner->name, (long)(t - sip->lastrtprx));
                                                                /* Issue a softhangup */
                                                                ast_softhangup(sip->owner, AST_SOFTHANGUP_DEV);
-                                                               ast_mutex_unlock(&sip->owner->lock);
+                                                               ast_channel_unlock(sip->owner);
                                                        }
                                                }
                                        }
@@ -13431,15 +13431,15 @@ static int sip_dtmfmode(struct ast_channel *chan, void *data)
                ast_log(LOG_WARNING, "This application requires the argument: info, inband, rfc2833\n");
                return 0;
        }
-       ast_mutex_lock(&chan->lock);
+       ast_channel_lock(chan);
        if (chan->tech != &sip_tech) {
                ast_log(LOG_WARNING, "Call this application only on SIP incoming calls\n");
-               ast_mutex_unlock(&chan->lock);
+               ast_channel_unlock(chan);
                return 0;
        }
        p = chan->tech_pvt;
        if (!p) {
-               ast_mutex_unlock(&chan->lock);
+               ast_channel_unlock(chan);
                return 0;
        }
        ast_mutex_lock(&p->lock);
@@ -13466,7 +13466,7 @@ static int sip_dtmfmode(struct ast_channel *chan, void *data)
                }
        }
        ast_mutex_unlock(&p->lock);
-       ast_mutex_unlock(&chan->lock);
+       ast_channel_unlock(chan);
        return 0;
 }
 
@@ -13474,7 +13474,7 @@ static int sip_dtmfmode(struct ast_channel *chan, void *data)
 static int sip_addheader(struct ast_channel *chan, void *data)
 {
        int no = 0;
-       int ok = 0;
+       int ok = FALSE;
        char varbuf[30];
        char *inbuf = (char *) data;
        
@@ -13482,7 +13482,7 @@ static int sip_addheader(struct ast_channel *chan, void *data)
                ast_log(LOG_WARNING, "This application requires the argument: Header\n");
                return 0;
        }
-       ast_mutex_lock(&chan->lock);
+       ast_channel_lock(chan);
 
        /* Check for headers */
        while (!ok && no <= 50) {
@@ -13490,7 +13490,7 @@ static int sip_addheader(struct ast_channel *chan, void *data)
                snprintf(varbuf, sizeof(varbuf), "_SIPADDHEADER%.2d", no);
 
                if( (pbx_builtin_getvar_helper(chan, (const char *) varbuf) == (const char *) NULL) )
-                       ok = 1;
+                       ok = TRUE;
        }
        if (ok) {
                pbx_builtin_setvar_helper (chan, varbuf, inbuf);
@@ -13499,7 +13499,7 @@ static int sip_addheader(struct ast_channel *chan, void *data)
        } else {
                ast_log(LOG_WARNING, "Too many SIP headers added, max 50\n");
        }
-       ast_mutex_unlock(&chan->lock);
+       ast_channel_unlock(chan);
        return 0;
 }
 
index ab6dde3..9ff56e0 100644 (file)
@@ -764,13 +764,27 @@ AST_INLINE_API(int ast_atomic_dec_and_test(volatile int *p),
 #ifndef DEBUG_CHANNEL_LOCKS
 /*! \brief Lock a channel. If DEBUG_CHANNEL_LOCKS is defined 
        in the Makefile, print relevant output for debugging */
-#define ast_channel_lock(x)            ast_mutex_lock(x->lock);
+#define ast_channel_lock(x)            ast_mutex_lock(&x->lock)
 /*! \brief Unlock a channel. If DEBUG_CHANNEL_LOCKS is defined 
        in the Makefile, print relevant output for debugging */
-#define ast_channel_unlock(x)          ast_mutex_unlock(x->lock);
+#define ast_channel_unlock(x)          ast_mutex_unlock(&x->lock)
 /*! \brief Try locking a channel. If DEBUG_CHANNEL_LOCKS is defined 
        in the Makefile, print relevant output for debugging */
-#define ast_channel_trylock(x)         ast_mutex_trylock(x->lock);
+#define ast_channel_trylock(x)         ast_mutex_trylock(&x->lock)
+#else
+
+/*! \brief Lock AST channel (and print debugging output)
+\note You need to enable DEBUG_CHANNEL_LOCKS for this function */
+int ast_channel_lock(struct ast_channel *chan);
+
+/*! \brief Unlock AST channel (and print debugging output)
+\note You need to enable DEBUG_CHANNEL_LOCKS for this function
+*/
+int ast_channel_unlock(struct ast_channel *chan);
+
+/*! \brief Lock AST channel (and print debugging output)
+\note   You need to enable DEBUG_CHANNEL_LOCKS for this function */
+int __ast_channel_trylock(struct ast_channel *chan);
 #endif
 
 #endif /* _ASTERISK_LOCK_H */