[asterisk-commits] kpfleming: branch 1.4 r45408 - in /branches/1.4: channels/ include/asterisk/ ...

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Tue Oct 17 15:24:11 MST 2006


Author: kpfleming
Date: Tue Oct 17 17:24:10 2006
New Revision: 45408

URL: http://svn.digium.com/view/asterisk?rev=45408&view=rev
Log:
optimize the 'quick response' code a bit more... no more malloc() or memset() for each response
expand stringfields API a bit to allow reusing the stringfield pool on a structure when needed, and remove some unnecessary code when the structure was being freed

Modified:
    branches/1.4/channels/chan_iax2.c
    branches/1.4/channels/chan_sip.c
    branches/1.4/include/asterisk/stringfields.h
    branches/1.4/main/ast_expr2.c
    branches/1.4/main/channel.c

Modified: branches/1.4/channels/chan_iax2.c
URL: http://svn.digium.com/view/asterisk/branches/1.4/channels/chan_iax2.c?rev=45408&r1=45407&r2=45408&view=diff
==============================================================================
--- branches/1.4/channels/chan_iax2.c (original)
+++ branches/1.4/channels/chan_iax2.c Tue Oct 17 17:24:10 2006
@@ -1763,7 +1763,7 @@
 				iax2_frame_free(frame.data);
 			jb_destroy(pvt->jb);
 			/* gotta free up the stringfields */
-			ast_string_field_free_all(pvt);
+			ast_string_field_free_pools(pvt);
 			free(pvt);
 		}
 	}
@@ -8346,7 +8346,7 @@
 					peer->expire = -1;
 					ast_clear_flag(peer, IAX_DYNAMIC);
 					if (ast_dnsmgr_lookup(v->value, &peer->addr.sin_addr, &peer->dnsmgr)) {
-						ast_string_field_free_all(peer);
+						ast_string_field_free_pools(peer);
 						free(peer);
 						return NULL;
 					}
@@ -8357,7 +8357,7 @@
 					inet_aton("255.255.255.255", &peer->mask);
 			} else if (!strcasecmp(v->name, "defaultip")) {
 				if (ast_get_ip(&peer->defaddr, v->value)) {
-					ast_string_field_free_all(peer);
+					ast_string_field_free_pools(peer);
 					free(peer);
 					return NULL;
 				}
@@ -8493,7 +8493,7 @@
 	
 	if (user) {
 		if (firstpass) {
-			ast_string_field_free_all(user);
+			ast_string_field_free_pools(user);
 			memset(user, 0, sizeof(struct iax2_user));
 			if (ast_string_field_init(user, 32)) {
 				free(user);
@@ -8695,7 +8695,7 @@
 		ast_variables_destroy(user->vars);
 		user->vars = NULL;
 	}
-	ast_string_field_free_all(user);
+	ast_string_field_free_pools(user);
 	free(user);
 }
 
@@ -8736,7 +8736,7 @@
 	register_peer_exten(peer, 0);
 	if (peer->dnsmgr)
 		ast_dnsmgr_release(peer->dnsmgr);
-	ast_string_field_free_all(peer);
+	ast_string_field_free_pools(peer);
 	free(peer);
 }
 

Modified: branches/1.4/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/branches/1.4/channels/chan_sip.c?rev=45408&r1=45407&r2=45408&view=diff
==============================================================================
--- branches/1.4/channels/chan_sip.c (original)
+++ branches/1.4/channels/chan_sip.c Tue Oct 17 17:24:10 2006
@@ -722,7 +722,7 @@
 #define SIP_PROG_INBAND_NEVER	(0 << 25)
 #define SIP_PROG_INBAND_NO	(1 << 25)
 #define SIP_PROG_INBAND_YES	(2 << 25)
-#define SIP_FREE_BIT		(1 << 27)	/*!< Undefined bit - not in use */
+#define SIP_NO_HISTORY		(1 << 27)	/*!< Suppress recording request/response history */
 #define SIP_CALL_LIMIT		(1 << 28)	/*!< Call limit enforced for this call */
 #define SIP_SENDRPID		(1 << 29)	/*!< Remote Party-ID Support */
 #define SIP_INC_COUNT		(1 << 30)	/*!< Did this connection increment the counter of in-use calls? */
@@ -1792,7 +1792,7 @@
 {
 	va_list ap;
 
-	if (!recordhistory || !p)
+	if (!p)
 		return;
 	va_start(ap, fmt);
 	append_history_va(p, fmt, ap);
@@ -1979,7 +1979,7 @@
 	}
 	if (sip_debug_test_pvt(p))
 		ast_verbose("Scheduling destruction of SIP dialog '%s' in %d ms (Method: %s)\n", p->callid, ms, sip_methods[p->method].text);
-	if (recordhistory)
+	if (!ast_test_flag(&p->flags[0], SIP_NO_HISTORY))
 		append_history(p, "SchedDestroy", "%d ms", ms);
 
 	if (p->autokillid > -1)
@@ -2113,7 +2113,7 @@
 			ast_inet_ntoa(dst->sin_addr),
 			ntohs(dst->sin_port), req->data);
 	}
-	if (recordhistory) {
+	if (!ast_test_flag(&p->flags[0], SIP_NO_HISTORY)) {
 		struct sip_request tmp;
 		parse_copy(&tmp, req);
 		append_history(p, reliable ? "TxRespRel" : "TxResp", "%s / %s - %s", tmp.data, get_header(&tmp, "CSeq"), 
@@ -2139,7 +2139,7 @@
 		else
 			ast_verbose("%sTransmitting (no NAT) to %s:%d:\n%s\n---\n", reliable ? "Reliably " : "", ast_inet_ntoa(p->sa.sin_addr), ntohs(p->sa.sin_port), req->data);
 	}
-	if (recordhistory) {
+	if (!ast_test_flag(&p->flags[0], SIP_NO_HISTORY)) {
 		struct sip_request tmp;
 		parse_copy(&tmp, req);
 		append_history(p, reliable ? "TxReqRel" : "TxReq", "%s / %s - %s", tmp.data, get_header(&tmp, "CSeq"), sip_methods[tmp.method].text);
@@ -2810,7 +2810,7 @@
 		ast_sched_del(sched, reg->expire);
 	if (reg->timeout > -1)
 		ast_sched_del(sched, reg->timeout);
-	ast_string_field_free_all(reg);
+	ast_string_field_free_pools(reg);
 	regobjs--;
 	free(reg);
 	
@@ -2903,7 +2903,7 @@
 	}
 	ast_mutex_destroy(&p->lock);
 
-	ast_string_field_free_all(p);
+	ast_string_field_free_pools(p);
 
 	free(p);
 }
@@ -3318,7 +3318,7 @@
 				transmit_request_with_auth(p, SIP_BYE, 0, XMIT_RELIABLE, 1);
 
 				/* Get RTCP quality before end of call */
-				if (recordhistory) {
+				if (!ast_test_flag(&p->flags[0], SIP_NO_HISTORY)) {
 					if (p->rtp)
 						append_history(p, "RTCPaudio", "Quality:%s", audioqos);
 					if (p->vrtp)
@@ -3811,7 +3811,7 @@
 	for (v = i->chanvars ; v ; v = v->next)
 		pbx_builtin_setvar_helper(tmp,v->name,v->value);
 
-	if (recordhistory)
+	if (!ast_test_flag(&i->flags[0], SIP_NO_HISTORY))
 		append_history(i, "NewChan", "Channel %s - from %s", tmp->name, i->callid);
 
 	return tmp;
@@ -4118,6 +4118,8 @@
 	/* Copy global flags to this PVT at setup. */
 	ast_copy_flags(&p->flags[0], &global_flags[0], SIP_FLAGS_TO_COPY);
 	ast_copy_flags(&p->flags[1], &global_flags[1], SIP_PAGE2_FLAGS_TO_COPY);
+
+	ast_set2_flag(&p->flags[0], !recordhistory, SIP_NO_HISTORY);
 
 	p->branch = ast_random();	
 	make_our_tag(p->tag, sizeof(p->tag));
@@ -5574,12 +5576,14 @@
 		return -1;
 	}
 
-	memset(p, 0, sizeof(*p));
+	/* if the structure was just allocated, initialize it */
+	if (!ast_test_flag(&p->flags[0], SIP_NO_HISTORY)) {
+		ast_set_flag(&p->flags[0], SIP_NO_HISTORY);
+		if (ast_string_field_init(p, 512))
+			return -1;
+	}
 
 	/* Initialize the bare minimum */
-	if (ast_string_field_init(p, 512))
-		return -1;
-
 	p->method = intended_method;
 
 	if (sin) {
@@ -5606,7 +5610,7 @@
 	/* Use this temporary pvt structure to send the message */
 	__transmit_response(p, msg, req, XMIT_UNRELIABLE);
 
-	/* Now do a simple destruction */
+	/* Free the string fields, but not the pool space */
 	ast_string_field_free_all(p);
 
 	return 0;
@@ -6317,7 +6321,7 @@
 	add_header(&req, "Supported", SUPPORTED_EXTENSIONS);
 	if (sipdebug)
 		add_header(&req, "X-asterisk-Info", "SIP re-invite (External RTP bridge)");
-	if (recordhistory)
+	if (!ast_test_flag(&p->flags[0], SIP_NO_HISTORY))
 		append_history(p, "ReInv", "Re-invite sent");
 	add_sdp(&req, p);
 	/* Use this as the basis */
@@ -6942,7 +6946,7 @@
 	if (!r)
 		return 0;
 
-	if (r->call && recordhistory)
+	if (r->call && !ast_test_flag(&r->call->flags[0], SIP_NO_HISTORY))
 		append_history(r->call, "RegistryRenew", "Account: %s@%s", r->username, r->hostname);
 	/* Since registry's are only added/removed by the the monitor thread, this
 	   may be overkill to reference/dereference at all here */
@@ -7042,7 +7046,7 @@
 			ast_log(LOG_WARNING, "Unable to allocate registration transaction (memory or socket error)\n");
 			return 0;
 		}
-		if (recordhistory)
+		if (!ast_test_flag(&p->flags[0], SIP_NO_HISTORY))
 			append_history(p, "RegistryInit", "Account: %s@%s", r->username, r->hostname);
 		/* Find address to hostname */
 		if (create_addr(p, r->hostname)) {
@@ -10786,7 +10790,7 @@
  			/* No old challenge */
 		return -1;
 	}
-	if (recordhistory)
+	if (!ast_test_flag(&p->flags[0], SIP_NO_HISTORY))
 		append_history(p, "RegistryAuth", "Try: %d", p->authtries);
  	if (sip_debug_test_pvt(p) && p->registry)
  		ast_verbose("Responding to challenge, registration to domain/host name %s\n", p->registry->hostname);
@@ -12992,7 +12996,7 @@
 				if (option_debug)
 					ast_log(LOG_DEBUG, "Hm....  No sdp for the moment\n");
 			}
-			if (recordhistory) /* This is a response, note what it was for */
+			if (!ast_test_flag(&p->flags[0], SIP_NO_HISTORY)) /* This is a response, note what it was for */
 				append_history(p, "ReInv", "Re-invite received");
 		}
 	} else if (debug)
@@ -13791,18 +13795,18 @@
 	ast_set_flag(&p->flags[0], SIP_ALREADYGONE);	
 
 	/* Get RTCP quality before end of call */
-	if (recordhistory || p->owner) {
+	if (!ast_test_flag(&p->flags[0], SIP_NO_HISTORY) || p->owner) {
 		char *audioqos, *videoqos;
 		if (p->rtp) {
 			audioqos = ast_rtp_get_quality(p->rtp);
-			if (recordhistory)
+			if (!ast_test_flag(&p->flags[0], SIP_NO_HISTORY))
 				append_history(p, "RTCPaudio", "Quality:%s", audioqos);
 			if (p->owner)
 				pbx_builtin_setvar_helper(p->owner, "RTPAUDIOQOS", audioqos);
 		}
 		if (p->vrtp) {
 			videoqos = ast_rtp_get_quality(p->vrtp);
-			if (recordhistory)
+			if (!ast_test_flag(&p->flags[0], SIP_NO_HISTORY))
 				append_history(p, "RTCPvideo", "Quality:%s", videoqos);
 			if (p->owner)
 				pbx_builtin_setvar_helper(p->owner, "RTPVIDEOQOS", videoqos);
@@ -14429,7 +14433,7 @@
 	}
 	p->recv = sin;
 
-	if (recordhistory) /* This is a request or response, note what it was for */
+	if (!ast_test_flag(&p->flags[0], SIP_NO_HISTORY)) /* This is a request or response, note what it was for */
 		append_history(p, "Rx", "%s / %s / %s", req.data, get_header(&req, "CSeq"), req.rlPart2);
 
 	if (!lockretry) {
@@ -16438,7 +16442,7 @@
 	}
 	if (changed && !ast_test_flag(&p->flags[0], SIP_GOTREFER)) {
 		if (chan->_state != AST_STATE_UP) {	/* We are in early state */
-			if (recordhistory)
+			if (!ast_test_flag(&p->flags[0], SIP_NO_HISTORY))
 				append_history(p, "ExtInv", "Initial invite sent with remote bridge proposal.");
 			if (option_debug)
 				ast_log(LOG_DEBUG, "Early remote bridge setting SIP '%s' - Sending media to %s\n", p->callid, ast_inet_ntoa(rtp ? p->redirip.sin_addr : p->ourip));

Modified: branches/1.4/include/asterisk/stringfields.h
URL: http://svn.digium.com/view/asterisk/branches/1.4/include/asterisk/stringfields.h?rev=45408&r1=45407&r2=45408&view=diff
==============================================================================
--- branches/1.4/include/asterisk/stringfields.h (original)
+++ branches/1.4/include/asterisk/stringfields.h Tue Oct 17 17:24:10 2006
@@ -248,6 +248,7 @@
 	} \
    } while (0)
 #endif
+
 /*!
   \brief Set a field to a simple string value
   \param x Pointer to a structure containing fields
@@ -262,6 +263,7 @@
 #define ast_string_field_logset(x, field, data, logstr) \
 	ast_string_field_index_logset(x, ast_string_field_index(x, field), data, logstr)
 #endif
+
 /*!
   \brief Set a field to a complex (built) value
   \param x Pointer to a structure containing fields
@@ -312,7 +314,7 @@
 	ast_string_field_index_free(x, ast_string_field_index(x, field))
 
 /*!
-  \brief Free all fields (and the storage pool) in a structure
+  \brief Free the stringfield storage pools attached to a structure
   \param x Pointer to a structure containing fields
   \return nothing
 
@@ -320,15 +322,29 @@
   structure; it should only be called immediately before freeing
   the structure itself.
 */
-#define ast_string_field_free_all(x) do { \
-	int index; \
+#define ast_string_field_free_pools(x) do { \
 	struct ast_string_field_pool *this, *prev; \
-	for (index = 0; index < ast_string_field_count(x); index ++) \
-		ast_string_field_index_free(x, index); \
 	for (this = (x)->__field_mgr.pool; this; this = prev) { \
 		prev = this->prev; \
 		free(this); \
 	} \
 	} while(0)
 
+/*!
+  \brief Free the stringfields in a structure
+  \param x Pointer to a structure containing fields
+  \return nothing
+
+  After calling this macro, the most recently allocated pool
+  attached to the structure will be available for use by
+  stringfields again.
+*/
+#define ast_string_field_free_all(x) do { \
+	int index; \
+	for (index = 0; index < ast_string_field_count(x); index++) \
+		ast_string_field_index_free(x, index); \
+	(x)->__field_mgr.used = 0; \
+	(x)->__field_mgr.space = (x)->__field_mgr.size; \
+	} while(0)
+
 #endif /* _ASTERISK_STRINGFIELDS_H */

Modified: branches/1.4/main/ast_expr2.c
URL: http://svn.digium.com/view/asterisk/branches/1.4/main/ast_expr2.c?rev=45408&r1=45407&r2=45408&view=diff
==============================================================================
--- branches/1.4/main/ast_expr2.c (original)
+++ branches/1.4/main/ast_expr2.c Tue Oct 17 17:24:10 2006
@@ -142,7 +142,7 @@
 #include "asterisk.h"
 
 #ifndef STANDALONE
-ASTERISK_FILE_VERSION(__FILE__, "$Revision: 40546 $")
+ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 #endif
 
 #include <sys/types.h>

Modified: branches/1.4/main/channel.c
URL: http://svn.digium.com/view/asterisk/branches/1.4/main/channel.c?rev=45408&r1=45407&r2=45408&view=diff
==============================================================================
--- branches/1.4/main/channel.c (original)
+++ branches/1.4/main/channel.c Tue Oct 17 17:24:10 2006
@@ -664,7 +664,7 @@
 	if (needqueue) {
 		if (pipe(tmp->alertpipe)) {
 			ast_log(LOG_WARNING, "Channel allocation failed: Can't create alert pipe!\n");
-			ast_string_field_free_all(tmp);
+			ast_string_field_free_pools(tmp);
 			free(tmp);
 			return NULL;
 		} else {
@@ -1061,7 +1061,7 @@
 	/* Destroy the jitterbuffer */
 	ast_jb_destroy(chan);
 
-	ast_string_field_free_all(chan);
+	ast_string_field_free_pools(chan);
 	free(chan);
 	AST_LIST_UNLOCK(&channels);
 



More information about the asterisk-commits mailing list