aboutsummaryrefslogtreecommitdiff
path: root/src/timer.c
diff options
context:
space:
mode:
authorkaustubhprabhu <devnull@localhost>2009-06-29 19:30:39 +0000
committerkaustubhprabhu <devnull@localhost>2009-06-29 19:30:39 +0000
commit81a2df59df58ac53858d4537ebe5bbeb54fc2dee (patch)
tree30a27c0359e221ae4c9ccaa842c965e750e01c45 /src/timer.c
parente1634906f188295dcfd7aca07136f22d14f21c62 (diff)
downloadiperf3-81a2df59df58ac53858d4537ebe5bbeb54fc2dee.tar.gz
changed timer_expired function call
Diffstat (limited to 'src/timer.c')
-rw-r--r--src/timer.c65
1 files changed, 33 insertions, 32 deletions
diff --git a/src/timer.c b/src/timer.c
index 38166df..a5decb2 100644
--- a/src/timer.c
+++ b/src/timer.c
@@ -9,41 +9,62 @@
#include "timer.h"
+
+
+double timeval_to_double(struct timeval *tv)
+{
+ double d;
+
+ d = tv->tv_sec + tv->tv_usec /1000000;
+
+ return d;
+}
+
+
+double timeval_diff(struct timeval *tv0, struct timeval *tv1)
+{
+ return timeval_to_double(tv1) - timeval_to_double(tv0);
+}
+
+/*
int
timer_expired(struct timer *tp)
{
struct timeval now;
+ double d= 0;
if(gettimeofday(&now, NULL) < 0) {
perror("gettimeofday");
return -1;
}
-
- return tp->end.tv_sec <= now.tv_sec;
+
+ d = timeval_to_double(&tp->end) - timeval_to_double(&now);
+
+ return d <= 0;
}
+*/
int
-timer_expired_micro(struct timer *tp)
+timer_expired(struct timer *tp)
{
struct timeval now;
- int64_t diff= 0, current= 0;
+ int64_t end = 0, current= 0, diff= 0;
if(gettimeofday(&now, NULL) < 0) {
perror("gettimeofday");
return -1;
}
- diff+= tp->end.tv_sec * 1000000 ;
- diff+= tp->end.tv_usec;
+ end+= tp->end.tv_sec * 1000000 ;
+ end+= tp->end.tv_usec;
current+= now.tv_sec * 1000000 ;
current+= now.tv_usec;
- return diff <= current;
+ diff = end - current;
+ return diff <= 0;
- // currently using microsecond limit. Else we need to introduce timespec instread of timeval
-}
-
+ }
struct timer *
@@ -60,12 +81,9 @@ new_timer(time_t sec, suseconds_t usec)
memcpy(&tp->end, &tp->begin, sizeof(struct timer));
tp->end.tv_sec = tp->begin.tv_sec + (time_t) sec;
tp->end.tv_usec = tp->begin.tv_usec + (time_t) usec;
+
+ tp->expired = timer_expired;
- if( sec != 0)
- tp->expired = timer_expired;
- else
- tp->expired = timer_expired_micro;
-
return tp;
}
@@ -100,20 +118,3 @@ delay(int64_t ns)
}
-double timeval_to_double(struct timeval *tv)
-{
- double d;
-
- d = tv->tv_sec + tv->tv_usec /1000000;
-
- return d;
-}
-
-
-double timeval_diff(struct timeval *tv0, struct timeval *tv1)
-{
- return timeval_to_double(tv1) - timeval_to_double(tv0);
-}
-
-
-