[Asterisk-cvs] asterisk/pbx pbx_dundi.c, 1.38, 1.39 pbx_gtkconsole.c, 1.18, 1.19

kpfleming at lists.digium.com kpfleming at lists.digium.com
Fri Jul 15 18:52:59 CDT 2005


Update of /usr/cvsroot/asterisk/pbx
In directory mongoose.digium.com:/tmp/cvs-serv13236/pbx

Modified Files:
	pbx_dundi.c pbx_gtkconsole.c 
Log Message:
add a library of timeval manipulation functions, and change a large number of usses to use the new functions (bug #4504)


Index: pbx_dundi.c
===================================================================
RCS file: /usr/cvsroot/asterisk/pbx/pbx_dundi.c,v
retrieving revision 1.38
retrieving revision 1.39
diff -u -d -r1.38 -r1.39
--- pbx_dundi.c	21 Jun 2005 00:58:31 -0000	1.38
+++ pbx_dundi.c	15 Jul 2005 23:00:47 -0000	1.39
@@ -680,13 +680,6 @@
 	return NULL;	
 }
 
-static inline int calc_ms(struct timeval *start)
-{
-	struct timeval tv;
-	gettimeofday(&tv, NULL);
-	return ((tv.tv_sec - start->tv_sec) * 1000 + (tv.tv_usec - start->tv_usec) / 1000);
-}
-
 static int dundi_query_eid_internal(struct dundi_entity_info *dei, const char *dcontext, dundi_eid *eid, struct dundi_hint_metadata *hmd, int ttl, int blockempty, dundi_eid *avoid[]);
 
 static void *dundi_query_thread(void *data)
@@ -2302,7 +2295,7 @@
 		*context = '\0';
 		context++;
 	}
-	gettimeofday(&start, NULL);
+	start = ast_tvnow();
 	res = dundi_lookup(dr, MAX_RESULTS, NULL, context, tmp, bypass);
 	
 	if (res < 0) 
@@ -2315,7 +2308,7 @@
 		ast_cli(fd, "%3d. %5d %s/%s (%s)\n", x + 1, dr[x].weight, dr[x].tech, dr[x].dest, dundi_flags2str(fs, sizeof(fs), dr[x].flags));
 		ast_cli(fd, "     from %s, expires in %d s\n", dr[x].eid_str, dr[x].expiration);
 	}
-	ast_cli(fd, "DUNDi lookup completed in %d ms\n", calc_ms(&start));
+	ast_cli(fd, "DUNDi lookup completed in %d ms\n", ast_tvdiff_ms(ast_tvnow(), start));
 	return RESULT_SUCCESS;
 }
 
@@ -2333,14 +2326,14 @@
 		*context = '\0';
 		context++;
 	}
-	gettimeofday(&start, NULL);
+	start = ast_tvnow();
 	res = dundi_precache(context, tmp);
 	
 	if (res < 0) 
 		ast_cli(fd, "DUNDi precache returned error.\n");
 	else if (!res) 
 		ast_cli(fd, "DUNDi precache returned no error.\n");
-	ast_cli(fd, "DUNDi lookup completed in %d ms\n", calc_ms(&start));
+	ast_cli(fd, "DUNDi lookup completed in %d ms\n", ast_tvdiff_ms(ast_tvnow(), start));
 	return RESULT_SUCCESS;
 }
 
@@ -2779,7 +2772,7 @@
 	if (trans) {
 		memset(trans, 0, sizeof(struct dundi_transaction));
 		if (global_storehistory) {
-			gettimeofday(&trans->start, NULL);
+			trans->start = ast_tvnow();
 			ast_set_flag(trans, FLAG_STOREHIST);
 		}
 		trans->retranstimer = DUNDI_DEFAULT_RETRANS_TIMER;
@@ -2845,7 +2838,6 @@
 {
 	struct dundi_transaction *cur, *prev;
 	struct dundi_peer *peer;
-	struct timeval tv;
 	int ms;
 	int x;
 	int cnt;
@@ -2863,9 +2855,7 @@
 						ast_log(LOG_NOTICE, "Peer '%s' has become UNREACHABLE!\n", dundi_eid_to_str(eid_str, sizeof(eid_str), &peer->eid));
 					peer->lastms = -1;
 				} else {
-					gettimeofday(&tv, NULL);
-					ms = (tv.tv_sec - peer->qualtx.tv_sec) * 1000 + 
-							(tv.tv_usec - peer->qualtx.tv_usec) / 1000;
+					ms = ast_tvdiff_ms(ast_tvnow(), peer->qualtx);
 					if (ms < 1)
 						ms = 1;
 					if (ms < peer->maxms) {
@@ -2893,7 +2883,7 @@
 								cnt++;
 							}
 						}
-						peer->lookuptimes[0] = calc_ms(&trans->start);
+						peer->lookuptimes[0] = ast_tvdiff_ms(ast_tvnow(), trans->start);
 						peer->lookups[0] = malloc(strlen(trans->parent->number) + strlen(trans->parent->dcontext) + 2);
 						if (peer->lookups[0]) {
 							sprintf(peer->lookups[0], "%s@%s", trans->parent->number, trans->parent->dcontext);
@@ -3577,9 +3567,10 @@
 			/* Wait for the cache to populate */
 			ast_log(LOG_DEBUG, "Waiting for similar request for '%s@%s' for '%s'\n",
 				dr.number,dr.dcontext,dundi_eid_to_str(eid_str, sizeof(eid_str), &pending->root_eid));
-			gettimeofday(&start, NULL);
-			while(check_request(pending) && (calc_ms(&start) < ttlms) && (!chan || !chan->_softhangup)) {
+			start = ast_tvnow();
+			while(check_request(pending) && (ast_tvdiff_ms(ast_tvnow(), start) < ttlms) && (!chan || !chan->_softhangup)) {
 				/* XXX Would be nice to have a way to poll/select here XXX */
+				/* XXX this is a busy wait loop!!! */
 				usleep(1);
 			}
 			/* Continue on as normal, our cache should kick in */
@@ -3609,8 +3600,8 @@
 	/* Actually perform transactions */
 	discover_transactions(&dr);
 	/* Wait for transaction to come back */
-	gettimeofday(&start, NULL);
-	while(dr.trans && (calc_ms(&start) < ttlms) && (!chan || !chan->_softhangup)) {
+	start = ast_tvnow();
+	while(dr.trans && (ast_tvdiff_ms(ast_tvnow(), start) < ttlms) && (!chan || !chan->_softhangup)) {
 		ms = 100;
 		ast_waitfor_n_fd(dr.pfds, 1, &ms, NULL);
 	}
@@ -3767,8 +3758,8 @@
 		else
 			ast_log(LOG_NOTICE, "Weird, expiration = %d, but need to precache for %s@%s?!\n", dr.expiration, dr.number, dr.dcontext);
 	}
-	gettimeofday(&start, NULL);
-	while(dr.trans && (calc_ms(&start) < ttlms)) {
+	start = ast_tvnow();
+	while(dr.trans && (ast_tvdiff_ms(ast_tvnow(), start) < ttlms)) {
 		if (dr.pfds[0] > -1) {
 			ms = 100;
 			ast_waitfor_n_fd(dr.pfds, 1, &ms, NULL);
@@ -3829,8 +3820,8 @@
 	/* Actually perform transactions */
 	query_transactions(&dr);
 	/* Wait for transaction to come back */
-	gettimeofday(&start, NULL);
-	while(dr.trans && (calc_ms(&start) < ttlms))
+	start = ast_tvnow();
+	while(dr.trans && (ast_tvdiff_ms(ast_tvnow(), start) < ttlms))
 		usleep(1);
 	res = dr.respcount;
 	return res;
@@ -4150,7 +4141,7 @@
 		if (!schedonly)
 			peer->qualtrans = create_transaction(peer);
 		if (peer->qualtrans) {
-			gettimeofday(&peer->qualtx, NULL);
+			peer->qualtx = ast_tvnow();
 			ast_set_flag(peer->qualtrans, FLAG_ISQUAL);
 			dundi_send(peer->qualtrans, DUNDI_COMMAND_NULL, 0, 1, NULL);
 		}

Index: pbx_gtkconsole.c
===================================================================
RCS file: /usr/cvsroot/asterisk/pbx/pbx_gtkconsole.c,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- pbx_gtkconsole.c	24 Jun 2005 02:33:14 -0000	1.18
+++ pbx_gtkconsole.c	15 Jul 2005 23:00:47 -0000	1.19
@@ -107,12 +107,12 @@
 	if (replacelast) 
 		gtk_clist_remove(GTK_CLIST(verb), GTK_CLIST(verb)->rows - 1);
 	gtk_clist_append(GTK_CLIST(verb), s2);
-	if (last.tv_sec || last.tv_usec) {
+	if (!ast_tvzero(last)) {
 		gdk_threads_leave();
 		gettimeofday(&tv, NULL);
 		if (cleanupid > -1)
 			gtk_timeout_remove(cleanupid);
-		ms = (tv.tv_sec - last.tv_sec) * 1000 + (tv.tv_usec - last.tv_usec) / 1000;
+		ms = ast_tvdiff_ms(tv, last);
 		if (ms < 100) {
 			/* We just got a message within 100ms, so just schedule an update
 			   in the near future */




More information about the svn-commits mailing list