aboutsummaryrefslogtreecommitdiffstats
path: root/pbx
diff options
context:
space:
mode:
authorkpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b>2005-07-15 23:00:47 +0000
committerkpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b>2005-07-15 23:00:47 +0000
commitff15e0fa53156b9994da3f726bfe91232de6195a (patch)
tree896015cada90b49858e1bf6503d9583704a56179 /pbx
parentc05cf07847cb384ba66aa29d5eda580eda413ffb (diff)
add a library of timeval manipulation functions, and change a large number of usses to use the new functions (bug #4504)
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@6146 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'pbx')
-rwxr-xr-xpbx/pbx_dundi.c43
-rwxr-xr-xpbx/pbx_gtkconsole.c4
2 files changed, 19 insertions, 28 deletions
diff --git a/pbx/pbx_dundi.c b/pbx/pbx_dundi.c
index aa4c0dbf6..6122f42a3 100755
--- a/pbx/pbx_dundi.c
+++ b/pbx/pbx_dundi.c
@@ -680,13 +680,6 @@ static void *dundi_precache_thread(void *data)
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 @@ static int dundi_do_lookup(int fd, int argc, char *argv[])
*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 @@ static int dundi_do_lookup(int fd, int argc, char *argv[])
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 @@ static int dundi_do_precache(int fd, int argc, char *argv[])
*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 @@ static struct dundi_transaction *create_transaction(struct dundi_peer *p)
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 @@ static void destroy_trans(struct dundi_transaction *trans, int fromtimeout)
{
struct dundi_transaction *cur, *prev;
struct dundi_peer *peer;
- struct timeval tv;
int ms;
int x;
int cnt;
@@ -2863,9 +2855,7 @@ static void destroy_trans(struct dundi_transaction *trans, int fromtimeout)
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 @@ static void destroy_trans(struct dundi_transaction *trans, int fromtimeout)
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 @@ static int dundi_lookup_internal(struct dundi_result *result, int maxret, struct
/* 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 @@ static int dundi_lookup_internal(struct dundi_result *result, int maxret, struct
/* 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 @@ static int dundi_precache_internal(const char *context, const char *number, int
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 @@ static int dundi_query_eid_internal(struct dundi_entity_info *dei, const char *d
/* 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 @@ static void qualify_peer(struct dundi_peer *peer, int schedonly)
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);
}
diff --git a/pbx/pbx_gtkconsole.c b/pbx/pbx_gtkconsole.c
index f17667707..eb9844fcf 100755
--- a/pbx/pbx_gtkconsole.c
+++ b/pbx/pbx_gtkconsole.c
@@ -107,12 +107,12 @@ static void __verboser(const char *stuff, int opos, int replacelast, int complet
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 */