[asterisk-commits] trunk r20295 - in /trunk: channel.c channels/chan_sip.c include/asterisk/lock.h

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Sat Apr 15 08:07:44 MST 2006


Author: oej
Date: Sat Apr 15 10:07:39 2006
New Revision: 20295

URL: http://svn.digium.com/view/asterisk?rev=20295&view=rev
Log:
More ast_channel_lock fixes
- 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

Modified:
    trunk/channel.c
    trunk/channels/chan_sip.c
    trunk/include/asterisk/lock.h

Modified: trunk/channel.c
URL: http://svn.digium.com/view/asterisk/trunk/channel.c?rev=20295&r1=20294&r2=20295&view=diff
==============================================================================
--- trunk/channel.c (original)
+++ trunk/channel.c Sat Apr 15 10:07:39 2006
@@ -1408,7 +1408,7 @@
 
 	/* 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 @@
 
 	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 @@
 			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_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 @@
 		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 @@
 			ast_cdr_answer(chan->cdr);
 		break;
 	}
-	ast_mutex_unlock(&chan->lock);
+	ast_channel_unlock(chan);
 	return 0;
 }
 
@@ -1546,7 +1546,7 @@
 {
 	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 @@
 		chan->generator = gen;
 	}
 
-	ast_mutex_unlock(&chan->lock);
+	ast_channel_unlock(chan);
 
 	return res;
 }
@@ -1609,12 +1609,12 @@
 	
 	/* 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 @@
 			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 @@
 	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 @@
 	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 @@
 		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 @@
 			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 @@
 				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 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 @@
 		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 @@
 		else
 			chan->fout++;
 	}
-	ast_mutex_unlock(&chan->lock);
+	ast_channel_unlock(chan);
 	return res;
 }
 
@@ -2468,7 +2468,7 @@
 	}
 	
 	/* 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 @@
 	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 @@
 	   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_log(LOG_DEBUG, "Got clone lock for masquerade on '%s' at %p\n", clone->name, &clone->lock);
+	ast_channel_lock(clone);
+
+	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 @@
 		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 @@
 	/* 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 @@
 		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 @@
 	   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 @@
 		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;
 }
 

Modified: trunk/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/trunk/channels/chan_sip.c?rev=20295&r1=20294&r2=20295&view=diff
==============================================================================
--- trunk/channels/chan_sip.c (original)
+++ trunk/channels/chan_sip.c Sat Apr 15 10:07:39 2006
@@ -1339,12 +1339,12 @@
 /*! \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 @@
 
 		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 @@
 			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 @@
 	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 @@
 	/* 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 @@
 			/* 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 @@
 		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 @@
 
 	/* 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 @@
 		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 @@
 
 	/* 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 @@
 	} 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 @@
 	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 @@
 	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 @@
 			build_route(p, req, 0);
 			if (c) {
 				/* Pre-lock the call */
-				ast_mutex_lock(&c->lock);
+				ast_channel_lock(c);
 			}
 		}
 		
@@ -10961,14 +10961,14 @@
 
 				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 @@
 				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 @@
 							/* 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 @@
 	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 @@
 		}
 		
 		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 @@
 							  (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 @@
 								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 @@
 		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 @@
 		}
 	}
 	ast_mutex_unlock(&p->lock);
-	ast_mutex_unlock(&chan->lock);
+	ast_channel_unlock(chan);
 	return 0;
 }
 
@@ -13474,7 +13474,7 @@
 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 @@
 		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 @@
 		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 @@
 	} else {
 		ast_log(LOG_WARNING, "Too many SIP headers added, max 50\n");
 	}
-	ast_mutex_unlock(&chan->lock);
+	ast_channel_unlock(chan);
 	return 0;
 }
 

Modified: trunk/include/asterisk/lock.h
URL: http://svn.digium.com/view/asterisk/trunk/include/asterisk/lock.h?rev=20295&r1=20294&r2=20295&view=diff
==============================================================================
--- trunk/include/asterisk/lock.h (original)
+++ trunk/include/asterisk/lock.h Sat Apr 15 10:07:39 2006
@@ -764,13 +764,27 @@
 #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 */



More information about the asterisk-commits mailing list